224 lines
18 KiB
HTML
224 lines
18 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Counterfactual Regret Minimization (CFR) | Poker Sharingan</title>
|
|
<meta name="description" content="Counterfactual regret minimization (CFR) explained with a worked regret-matching example, MCCFR, Linear CFR, CFR+, pruning, and how Pluribus uses them.">
|
|
<link rel="canonical" href="https://sharingan.poker/learn/cfr/">
|
|
<meta property="og:type" content="article">
|
|
<meta property="og:site_name" content="Poker Sharingan">
|
|
<meta property="og:title" content="Counterfactual Regret Minimization (CFR)">
|
|
<meta property="og:description" content="Counterfactual regret minimization (CFR) explained with a worked regret-matching example, MCCFR, Linear CFR, CFR+, pruning, and how Pluribus uses them.">
|
|
<meta property="og:url" content="https://sharingan.poker/learn/cfr/">
|
|
<meta property="og:image" content="https://sharingan.poker/og.png">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:image" content="https://sharingan.poker/og.png">
|
|
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-12 -12 24 24'%3E%3Ccircle r='11' fill='%23111'/%3E%3Ccircle r='10' fill='%23d0141e'/%3E%3Cg fill='%23111'%3E%3Ccircle cy='-5.6' r='1.9'/%3E%3Ccircle cx='4.9' cy='2.8' r='1.9'/%3E%3Ccircle cx='-4.9' cy='2.8' r='1.9'/%3E%3C/g%3E%3Ccircle r='2.2' fill='%23111'/%3E%3C/svg%3E">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:wght@400&display=swap">
|
|
<link rel="stylesheet" href="../../shared.css">
|
|
<script type="application/ld+json">
|
|
[
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "TechArticle",
|
|
"headline": "Counterfactual Regret Minimization (CFR) Explained",
|
|
"description": "Counterfactual regret minimization (CFR) explained with a worked regret-matching example, MCCFR, Linear CFR, CFR+, pruning, and how Pluribus uses them.",
|
|
"datePublished": "2026-11-04",
|
|
"dateModified": "2026-11-04",
|
|
"author": {
|
|
"@type": "Person",
|
|
"name": "Marko Kraemer",
|
|
"url": "https://github.com/markokraemer"
|
|
},
|
|
"publisher": {
|
|
"@type": "Organization",
|
|
"name": "Poker Sharingan",
|
|
"url": "https://sharingan.poker/"
|
|
},
|
|
"mainEntityOfPage": "https://sharingan.poker/learn/cfr/",
|
|
"image": "https://sharingan.poker/og.png"
|
|
},
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "BreadcrumbList",
|
|
"itemListElement": [
|
|
{
|
|
"@type": "ListItem",
|
|
"position": 1,
|
|
"name": "Home",
|
|
"item": "https://sharingan.poker/"
|
|
},
|
|
{
|
|
"@type": "ListItem",
|
|
"position": 2,
|
|
"name": "Learn",
|
|
"item": "https://sharingan.poker/learn/"
|
|
},
|
|
{
|
|
"@type": "ListItem",
|
|
"position": 3,
|
|
"name": "Counterfactual Regret Minimization (CFR) Explained",
|
|
"item": "https://sharingan.poker/learn/cfr/"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"@context": "https://schema.org",
|
|
"@type": "FAQPage",
|
|
"mainEntity": [
|
|
{
|
|
"@type": "Question",
|
|
"name": "What is counterfactual regret minimization?",
|
|
"acceptedAnswer": {
|
|
"@type": "Answer",
|
|
"text": "An iterative self-play algorithm for imperfect-information games. It tracks, for every information set, how much better each action would have done than the one taken, and plays actions in proportion to positive regret. The average strategy approaches a Nash equilibrium in two-player zero-sum games."
|
|
}
|
|
},
|
|
{
|
|
"@type": "Question",
|
|
"name": "What is regret matching?",
|
|
"acceptedAnswer": {
|
|
"@type": "Answer",
|
|
"text": "The rule used at each decision point in CFR: keep cumulative regret per action, and choose each action with probability proportional to its positive regret. If no regret is positive, play uniformly."
|
|
}
|
|
},
|
|
{
|
|
"@type": "Question",
|
|
"name": "What is the difference between CFR and MCCFR?",
|
|
"acceptedAnswer": {
|
|
"@type": "Answer",
|
|
"text": "CFR visits the entire game tree each iteration. Monte Carlo CFR samples parts of the tree, such as chance events and opponent actions, which makes each iteration far cheaper while keeping regret estimates unbiased in expectation."
|
|
}
|
|
},
|
|
{
|
|
"@type": "Question",
|
|
"name": "What are Linear CFR and CFR+?",
|
|
"acceptedAnswer": {
|
|
"@type": "Answer",
|
|
"text": "Both speed up convergence. CFR+ floors negative cumulative regret at zero and was used to solve heads-up limit hold'em. Linear CFR weights iteration t by t so that later iterations count more; Pluribus used it early in training."
|
|
}
|
|
},
|
|
{
|
|
"@type": "Question",
|
|
"name": "Does CFR work for six-player poker?",
|
|
"acceptedAnswer": {
|
|
"@type": "Answer",
|
|
"text": "There is no convergence guarantee with three or more players. In practice, CFR-style self-play still produced a bot that beat elite professionals in Pluribus, so it works well empirically."
|
|
}
|
|
},
|
|
{
|
|
"@type": "Question",
|
|
"name": "Why do poker bots play the average strategy?",
|
|
"acceptedAnswer": {
|
|
"@type": "Answer",
|
|
"text": "The latest iterate can oscillate. The convergence guarantee applies to the strategy averaged across iterations, so that average is the one deployed."
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<main class="doc"><article class="sheet">
|
|
<div class="l"></div>
|
|
<div class="l"><a href="../../" style="text-decoration:none"><span class="chip">POKER SHARINGAN</span></a><nav class="nav"><a href="../">Learn</a><a href="/docs/">Run locally</a><a href="https://github.com/markokraemer/poker-sharingan">GitHub</a></nav></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h1 class="up">Counterfactual Regret Minimization (CFR) Explained</h1></div>
|
|
<div class="l muted"><span>Updated <time datetime="2026-11-04">November 4, 2026</time></span></div>
|
|
<div class="l"><span class="rule">========================================================================================================</span></div>
|
|
<div class="l"><p>Counterfactual regret minimization (CFR) is the algorithm family behind most strong poker AI. It plays a game against itself many times, tracks how much it regrets each choice, and shifts toward choices it regrets not having made. This page explains CFR poker training in plain terms: regret matching, information sets, the average strategy, and the variants (MCCFR, Linear CFR, CFR+) used in practice.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h2>The idea in one paragraph</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>Regret is simple. After you act, you ask: how much better would I have done with a different action? If an alternative would have won more, you have positive regret for it. CFR keeps a running total of that regret for every action at every decision point, and plays actions in proportion to their positive regret. Over many iterations, the players' <em>average</em> strategy approaches a Nash equilibrium in two-player zero-sum games. The original method is from Zinkevich, Johanson, Bowling and Piccione, <a href="https://papers.nips.cc/paper/2007/hash/08d98638c6fcd194a4b1e6992063e944-Abstract.html">"Regret Minimization in Games with Incomplete Information"</a> (NeurIPS 2007).</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>The word "counterfactual" matters. The regret at a decision is weighted by the probability that the <em>other</em> players and chance (the deck) would have led you there, while ignoring your own probability of reaching it. This lets every decision point learn on its own, which is what makes the method scale to a game as large as poker.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h2>Regret matching: a worked example</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>Regret matching is the rule CFR applies at each decision point. Rock-paper-scissors is the smallest honest example. Payoffs are +1 for a win, 0 for a tie, -1 for a loss. Track cumulative regret for (Rock, Paper, Scissors), all starting at zero. With no positive regret, you play uniformly: 1/3 each.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p><strong>Iteration 1.</strong> You play Rock, and the opponent plays Paper. You lose (-1). Had you played Paper, you would have tied (0). Had you played Scissors, you would have won (+1). Regret for an action is its payoff minus the payoff you got: Rock (-1) - (-1) = 0, Paper 0 - (-1) = +1, Scissors (+1) - (-1) = +2. Cumulative regret is (0, 1, 2).</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p><strong>Iteration 2.</strong> Normalize the positive regrets: total 3, so the strategy is (0, 1/3, 2/3). Say you sample Scissors, and the opponent plays Rock. You lose (-1). Paper would have won (+1) and Rock would have tied (0). Regrets this round: Rock 0 - (-1) = +1, Paper +1 - (-1) = +2, Scissors 0. Cumulative regret is now (1, 3, 2).</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p><strong>Iteration 3.</strong> Total positive regret is 6, so the strategy is (1/6, 3/6, 2/6), about (0.17, 0.50, 0.33). The strategy has moved toward Paper because the opponent has played Paper and Rock. The <em>average strategy</em> over iterations 1 and 2 is the mean of (1/3, 1/3, 1/3) and (0, 1/3, 2/3), which is (1/6, 1/3, 1/2). Against a fixed opponent the play chases a best response. In self-play, both sides do this at once, and it is the averages, not the latest strategies, that converge to equilibrium.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h2>Information sets and the average strategy</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>Poker is a game of hidden information, so a player cannot tell which exact game state they are in. An <strong>information set</strong> groups every state a player cannot distinguish: your own hole cards, the public board cards, and the betting history. CFR stores one regret table and one strategy per information set, and the action probabilities live there.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>Two details trip people up. First, the latest strategy can cycle and oscillate. Only the <strong>average strategy</strong>, weighted over iterations, carries the convergence guarantee. That is what a trained bot plays. Second, the guarantee holds for two-player zero-sum games. With three or more players there is no such guarantee, yet Pluribus showed that CFR-style self-play still produces strong six-player play. See the <a href="../poker-ai-history/">poker AI history</a> for how this fits into the wider field.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>The full poker tree is far too large to visit, so games are shrunk by abstraction. Card abstraction puts similar hands into the same bucket. Action abstraction limits bets to a short menu of sizes. The <a href="../pluribus/">Pluribus</a> paper used both, and so does <a href="../sharingan-2/">SHARINGAN-2</a>.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h2>Sampling variants: MCCFR</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>Vanilla CFR walks the whole game tree each iteration. That is impossible for no-limit hold'em. <strong>Monte Carlo CFR</strong> (MCCFR, Lanctot, Waugh, Zinkevich and Bowling, NeurIPS 2009) samples part of the tree instead and corrects for the sampling so regrets stay unbiased in expectation. Two common forms:</p></div>
|
|
<div class="l"><ul><li><strong>Outcome sampling</strong> follows a single path of play per iteration. Updates are cheap, but noisy.</li><li><strong>External sampling</strong> samples chance events and the opponents' actions, but tries every action for the player being updated. Updates cost more but are far less noisy. Pluribus used this form.</li></ul></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>Because each iteration touches only a sliver of the tree, a blueprint needs enormous numbers of iterations. SHARINGAN-2's blueprint was trained for 1.83e11 external-sampling iterations on CPU servers. Sampling is what turns an impossible computation into a rented-server job.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h2>Discounting and pruning: Linear CFR and CFR+</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>Early iterations are played with bad strategies, and plain CFR carries that early regret forever. Two fixes helped a great deal:</p></div>
|
|
<div class="l"><ul><li><strong>CFR+</strong> (Tammelin, 2014) resets negative cumulative regret to zero ("regret-matching+") and uses a weighted average. It powered Cepheus, which essentially solved heads-up limit hold'em.</li><li><strong>Linear CFR</strong> and Discounted CFR (Brown and Sandholm, <a href="https://doi.org/10.1609/aaai.v33i01.33011829">AAAI 2019</a>) weight iteration t in proportion to t, so later, better iterations count more. Pluribus applied Linear CFR discounting in the early part of training.</li></ul></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p><strong>Pruning</strong> skips actions whose cumulative regret is very negative, since they are unlikely to be worth playing. It saves time on most iterations. The usual rule is to revisit pruned actions every so often, and not to prune on the final betting round. SHARINGAN-2 prunes negative-regret actions on 95% of iterations and never on the river.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h2>A minimal sketch</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>The structure below is the core of external-sampling MCCFR for one player. It is a sketch for understanding, not the production Rust code.</p></div>
|
|
<div class="l"><pre class="code">def traverse(h, player):
|
|
if terminal(h): return payoff(h, player)
|
|
if chance(h): return traverse(sample_chance(h), player)
|
|
I = infoset(h)
|
|
sigma = regret_matching(regret[I]) # positive regrets, normalized
|
|
if actor(h) == player:
|
|
v = {a: traverse(h + a, player) for a in actions(h)}
|
|
ev = sum(sigma[a] * v[a] for a in actions(h))
|
|
for a in actions(h):
|
|
regret[I][a] += v[a] - ev # (+ discounting / pruning here)
|
|
return ev
|
|
a = sample(sigma) # opponent: sample one action
|
|
strategy_sum[I] += sigma # accumulate the average strategy
|
|
return traverse(h + a, player)</pre></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h2>How blueprints use it in Pluribus and SHARINGAN-2</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>CFR is used offline to compute a <strong>blueprint</strong>: a full strategy for the abstracted game. Pluribus computed its blueprint in 8 days on a 64-core server with MCCFR (external sampling), Linear CFR discounting early on, and negative-regret pruning. At play time it ran depth-limited real-time search on top of that blueprint, which the <a href="../pluribus/">Pluribus article</a> covers in detail.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><p>The open reproduction follows the same recipe. SHARINGAN-2 pairs an MCCFR blueprint (preflop in 169 lossless classes, 200 buckets per postflop street) with turn and river search. The training details are in the <a href="../sharingan-2/">SHARINGAN-2 write-up</a> and the <a href="../open-source-pluribus/">open-source Pluribus</a> page, and the code is on <a href="https://github.com/markokraemer/poker-sharingan">GitHub</a>. If you want to know how bots like these get scored fairly, read <a href="../measuring-poker-bots/">measuring poker bot skill</a>.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><span class="rule">========================================================================================================</span></div>
|
|
<div class="l"><h2>FAQ</h2></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h3>What is counterfactual regret minimization?</h3></div>
|
|
<div class="l"><p class="muted">An iterative self-play algorithm for imperfect-information games. It tracks, for every information set, how much better each action would have done than the one taken, and plays actions in proportion to positive regret. The average strategy approaches a Nash equilibrium in two-player zero-sum games.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h3>What is regret matching?</h3></div>
|
|
<div class="l"><p class="muted">The rule used at each decision point in CFR: keep cumulative regret per action, and choose each action with probability proportional to its positive regret. If no regret is positive, play uniformly.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h3>What is the difference between CFR and MCCFR?</h3></div>
|
|
<div class="l"><p class="muted">CFR visits the entire game tree each iteration. Monte Carlo CFR samples parts of the tree, such as chance events and opponent actions, which makes each iteration far cheaper while keeping regret estimates unbiased in expectation.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h3>What are Linear CFR and CFR+?</h3></div>
|
|
<div class="l"><p class="muted">Both speed up convergence. CFR+ floors negative cumulative regret at zero and was used to solve heads-up limit hold'em. Linear CFR weights iteration t by t so that later iterations count more; Pluribus used it early in training.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h3>Does CFR work for six-player poker?</h3></div>
|
|
<div class="l"><p class="muted">There is no convergence guarantee with three or more players. In practice, CFR-style self-play still produced a bot that beat elite professionals in Pluribus, so it works well empirically.</p></div>
|
|
<div class="l"></div>
|
|
<div class="l"><h3>Why do poker bots play the average strategy?</h3></div>
|
|
<div class="l"><p class="muted">The latest iterate can oscillate. The convergence guarantee applies to the strategy averaged across iterations, so that average is the one deployed.</p></div>
|
|
<div class="l"></div> <div class="l"><span class="rule">========================================================================================================</span></div>
|
|
<div class="l up muted">Related</div>
|
|
<div class="l"><nav class="nav"><a href="../pluribus/">Pluribus</a><a href="../poker-ai-history/">Poker AI history</a><a href="../measuring-poker-bots/">Measuring poker bots</a><a href="../sharingan-2/">SHARINGAN-2</a></nav></div>
|
|
<div class="l"></div>
|
|
<div class="l muted">Apache-2.0. For research and bot arenas; real-money sites ban bots.</div>
|
|
</article></main>
|
|
</body>
|
|
</html>
|