The goal is to capture every opposing piece, or to leave the opponent with no legal move.
Click one of your pieces, then a glowing square. Red moves first.
To watch two agents play each other, choose AI vs AI in MODE.
The checkers agents search the game tree: the current position is the root, each legal move is a branch, and each reply branches again. A search scores the positions at the bottom of the tree with a hand-written heuristic evaluation, a fast estimate of how good a position is for the side to move. Five agents choose moves from the game tree or at random (alpha-beta search, plain minimax, Monte Carlo tree search, greedy and random). A sixth, chance, samples a move from fixed weights with no search. Each agent can be played against, or watched in a match against another agent.
The rules are American checkers on three board sizes: 8×8 with 12 men per side, 10×10 with 20 and 12×12 with 30. Each side starts with three, four or five rows of men (three on 8×8, four on 10×10, five on 12×12), and Red starts at the bottom and moves first. The board is stored as its dark squares only, numbered row by row from the top1. Men move and capture forward only. Kings move and capture one step in any direction, with no flying kings. A man that reaches the far row is crowned, and crowning ends its move. A side with no legal move loses2.
Forced or optional captures. With forced captures (the default, standard rules) a capture must be played whenever one exists. With optional captures a simple move is legal even when a capture exists. In both cases a capture chain is played to its end: once a piece starts jumping, it must keep jumping while a jump is available. A captured piece stays on the board until the move ends, so it cannot be jumped twice. Where a player declines to capture, which only optional captures allow, the search scores the position as it stands rather than in the middle of a capture.
Draws. A game is drawn after 80 plies (one move by either side) with no capture and no man moving. A king's move does not reset the count.
Minimax is a decision rule for two-player, zero-sum games, where one player's gain is exactly the other's loss. Each side is assumed to choose the reply that is worst for the other. The code uses negamax, a compact form of minimax in which every score is from the point of view of the side to move, so a child's score is negated for its parent.
Here s is the position, \sigma \in \{+1, -1\} is the side to move (+1 for Red, −1 for White), d is the remaining depth in plies, M(s,\sigma) is the set of legal moves, and s_m is the position after move m. The maximum is over the legal moves, and each is scored by the negated value of the reply position. The starting value \text{stand} is the score for declining to capture, described under quiescence below. When declining is not allowed, the starting value is -2\,\text{WIN}, lower than any real score.
A side with no legal move has lost, and it is scored -\text{WIN} + p, where p is the ply at which that position is reached. The ply term makes a sooner loss score lower than a later one, so the search avoids the losses that come sooner and prefers the wins that come sooner. \text{WIN} is far larger than any heuristic score, so a forced result is always separated from an estimate.
The heuristic evaluation scores a position from the side to move's point of view, without searching further. It counts material: a man is worth 100 points and a king, a crowned man, 165 points. A man is also worth 3 points for each row it has advanced toward the crowning row, and 8 more points while it stays on its own back row, where it stops the opponent from crowning there. A king gets no advancement term. A piece on one of the eight central squares, the middle 4×4 block of the board, gets 6 more points. The evaluation has no mobility term. The constants were set by hand, and no tuning run or results file is committed for them.
Here q is a square and p_q the piece on it (+1 red man, +2 red king, −1 white man, −2 white king). v(q) is the value of that piece on that square. The advancement term a(q) is the number of rows the man has moved from its home row: a(q) = (n-1) - r(q) for a red man and a(q) = r(q) for a white man, where r(q) is the row of q counted from the top (row 0) and n is the board size. The home-row term h(q) is 1 when a red man stands on row n-1 or a white man on row 0, and 0 otherwise. C is the set of central squares, which has 8 squares on every board size. So the advancement bonus runs from 0 on a man's home row to 3(n-1) on the crowning row, which is 21 on 8×8.
The sum runs over all squares. Each red piece adds its value and each white piece subtracts its value, so the total is from Red's point of view. Multiplying by \sigma turns it into the side to move's point of view, which is what negamax needs. The same weights apply on every board size. The advancement and centre terms are measured on the board's own rows and columns.
Example. On 8×8, a red man on square 14 has advanced four rows from its home row (row 7 to row 3), so it is worth 100 + 3 \times 4 = 112. Square 14 is central, so the man is worth 118. A red king on the same square is worth 165 + 6 = 171. A white man on square 1 is on its home row, so it is worth 100 + 8 = 108, and it counts as -108 for Red.
Alpha-beta pruning is a refinement of negamax that keeps a window of two bounds. \alpha is the best score the side to move has already secured on the current line, and \beta is the bound that the opponent has already secured. When a reply shows that the opponent would never allow this line, the score reaches \beta, the remaining replies are skipped, and the search records a cutoff. The score returned is the same as minimax gives at the same depth, found with fewer positions.
The agent does not search one fixed depth. It uses iterative deepening: it searches depth 1 completely, then depth 2, and so on, and plays the best move from the deepest depth that finished. The time budget is 0.2 s, 0.8 s or 2.0 s at Fast, Normal and Strong, on every board size. A search that runs out of time in the middle of a depth discards that depth and keeps the answer of the previous one. A forced win or loss found at any depth ends the search early. Match runs use node budgets of 3,000, 12,000 and 40,000 nodes instead of time, so a match replays the same way on any machine.
Each depth also helps the next one. The best move found at one depth is tried first at the next, so cutoffs come early. The search keeps a transposition table, explained after the full version below.
function ALPHA-BETA(position, depth, α, β):
if depth = 0 or LEGAL-MOVES(position) is empty:
return EVALUATE(position) # score for the side to move
best ← −infinity
for each move m in LEGAL-MOVES(position):
score ← −ALPHA-BETA(RESULT(position, m), depth − 1, −β, −α)
best ← max(best, score)
α ← max(α, score)
if α ≥ β:
break # prune: the opponent will avoid this line
constants: WIN = 100000, MAX-DEPTH = 30, FORCED-DEPTH = 4, MATE-BOUND = WIN − 1000
function SEARCH(position, side, time-budget):
moves ← LEGAL-MOVES(position, side)
if moves is empty: raise error "no legal moves"
if moves has exactly one move: # no choice: play it
score ← −NEGAMAX(RESULT(position, moves[1]), −side, FORCED-DEPTH − 1, −2·WIN, 2·WIN, 1)
return moves[1], score # this search has no time limit
best ← moves[1] # kept if depth 1 does not finish
TABLE ← empty # transposition table, one per search
deadline ← now + time-budget
try:
for depth ← 1 to MAX-DEPTH: # iterative deepening
order ← moves with the previous best move first
results ← empty; α ← −2·WIN
for each m in order:
s ← −NEGAMAX(RESULT(position, m), −side, depth − 1, −2·WIN, −α, 1)
add (m, s) to results; α ← max(α, s)
best ← the move in results with the highest score
if |score(best)| > WIN − 100: break # forced win or loss found
on time-limit reached:
stop # keep the answer of the last full depth
return best
function NEGAMAX(position, side, depth, α, β, ply):
count one node
if the time limit is reached: # checked every 512 nodes
raise time-limit reached # unwinds to the try in SEARCH
moves ← LEGAL-MOVES(position, side)
if moves is empty:
return −WIN + ply # the side to move has lost
stand ← none
if depth ≤ 0: # quiescence at the depth limit
moves, stand ← QUIET-LEAF(position, side, moves)
if moves is empty: return stand
α0 ← α
entry ← TABLE[(position, side)]
best-path ← none
if entry exists:
(d, flag, value, best-path) ← entry
value ← FROM-TABLE(value, ply) # back to a score from the root
if d ≥ depth and (flag = EXACT or (flag = LOWER and value ≥ β) or (flag = UPPER and value ≤ α)):
return value
sort moves: best-path first, then the most pieces captured first # move ordering
best ← −2·WIN if stand is none, else stand # stand pat
α ← max(α, best)
if α ≥ β: return best
for each m in moves:
score ← −NEGAMAX(RESULT(position, m), −side, depth − 1, −β, −α, ply + 1)
if score > best: best ← score; best-path ← m.path
α ← max(α, best)
if α ≥ β: break # cut off the remaining replies
flag ← UPPER if best ≤ α0; LOWER if best ≥ β; EXACT otherwise
TABLE[(position, side)] ← (depth, flag, TO-TABLE(best, ply), best-path) # wins and losses stored relative to this node
return best
function QUIET-LEAF(position, side, moves):
captures ← the moves in moves that capture
if captures is empty:
return (empty list, EVALUATE(position, side)) # quiet: score it statically
stand ← none if captures are forced or every move captures, else EVALUATE(position, side)
return (captures, stand)
function TO-TABLE(score, ply): # a win or loss becomes its distance from this node
if score > MATE-BOUND: return score + ply
if score < −MATE-BOUND: return score − ply
return score # an ordinary evaluation is stored unchanged
function FROM-TABLE(score, ply): # the reverse, applied when an entry is read
if score > MATE-BOUND: return score − ply
if score < −MATE-BOUND: return score + ply
return score
Transposition table. Different move orders can reach the same position, so the search keeps a transposition table, a dictionary keyed by the position and the side to move. Each entry stores the depth searched, a score, the best move found and a flag. The flag is needed because a score found inside a window may be only a bound, not the exact value. The flag is EXACT when the score lies inside the window, LOWER when the true score is at least the stored value (a fail-high result, where the score reached \beta), and UPPER when the true score is at most the stored value (a fail-low result, where no move reached \alpha_0). The flag is set by the rule below.
Here \alpha_0 is the value of \alpha on entry to the node, before the stand pat step, and \beta is the upper bound of the window. An entry is reused only when it was searched at least as deep as the current depth and its flag fits the current window (the lookup in the full version). The table is cleared at the start of each search and kept across the depths of one search. Wins and losses are stored by their distance from the node, not by their score from the root, and are converted back on lookup, so an entry reached at another ply gives the right distance (see the next paragraph).
Mate distance in the table. A forced win or loss scores \text{WIN} minus or plus the ply where it happens, counted from the root. The table is shared by every node of one search, and the same position is reached at different plies. A win found at one ply is a shorter win from a shallower node and a longer win from a deeper one. So a win or loss must be stored relative to the node: the table keeps its distance from the node, and the current ply is added back on lookup. Without this, a stored win could be reported with the wrong number of moves.
Here v is a score from the root, p is the ply of the node, and \text{WIN} - 1000 (MATE-BOUND) is the threshold above which a score is a win or loss rather than an evaluation. An evaluation never reaches that size, so evaluations are stored unchanged. Example. A win scored \text{WIN} - 7 at a node reached at ply 3 is stored as \text{WIN} - 4, its distance from that node. Read back at ply 5, it gives \text{WIN} - 4 - 5 = \text{WIN} - 9: the same win is four plies below that node, so it happens at ply 9 from the root. The code names are to_table and from_table.
Move ordering. Good ordering makes cutoffs come early. Moves are sorted with the table's best move first, then captures by the number of pieces taken, largest first. The sort is stable, so equal moves keep their legal-move order.
Quiescence and stand pat. At the depth limit, a position with a capture pending is not scored in the middle of an exchange. Only the captures are kept and searched further, until a quiet position is reached. The side to move may also decline to capture and keep the static evaluation, which is the stand pat score. Stand pat is allowed only when captures are optional and some legal move is not a capture. With forced captures, or when every legal move is a capture, the side must capture, so the starting value is -2\,\text{WIN}.
Mate distance. A side with no legal move is scored -\text{WIN} + \text{ply}. The ply term means a forced loss found sooner scores lower, so the search avoids it, and a forced win found sooner is preferred. The page reports any score within 200 of WIN as a win or loss, with the number of moves to it.
Single-move shortcut. When only one legal move exists, there is nothing to choose. The agent plays that move without iterative deepening, and scores it with a fixed search of four plies that has no time limit, so the analysis still shows a score.
Example. On the seed 1 position in the results below, depth 4 minimax visits 2,962 positions and alpha-beta visits 618. Both choose the same move with the same score.
Plain minimax searches every legal move to a fixed depth, with no cutoffs and no transposition table. It has no time budget, so its depth depends only on the board size and the capture rule. At the same depth it returns the same score as alpha-beta search, which is why it is the reference that alpha-beta is measured against. Quiescence applies at the depth limit here too, so a pending capture is searched through.
Depth is fixed because, without pruning, each extra ply multiplies the work by the number of legal moves, and optional captures add more moves per position. The depths were chosen on the machine the code was written on, so that the slowest of three midgame positions takes about 3 s or less12. The depths for each strength are in the strength table below.
function MINIMAX(position, depth):
if depth = 0 or LEGAL-MOVES(position) is empty:
return EVALUATE(position) # score for the side to move
best ← −infinity
for each move m in LEGAL-MOVES(position): # every move is searched; none is pruned
best ← max(best, −MINIMAX(RESULT(position, m), depth − 1))
return best
function SEARCH(position, side, depth):
for each move m in LEGAL-MOVES(position, side):
score[m] ← −MINIMAX(RESULT(position, m), −side, depth − 1, 1)
return the move with the highest score
function MINIMAX(position, side, depth, ply):
count one node
moves ← LEGAL-MOVES(position, side)
if moves is empty:
return −WIN + ply # the side to move has lost
stand ← none
if depth ≤ 0: # quiescence, as in alpha-beta
moves, stand ← QUIET-LEAF(position, side, moves)
if moves is empty: return stand
best ← −2·WIN if stand is none, else stand # stand pat, when allowed
for each m in moves:
best ← max(best, −MINIMAX(RESULT(position, m), −side, depth − 1, ply + 1))
return best
The full version has no table, no ordering and no cutoff. Its node count is the number of calls to the search function, which is why the counts in the results below grow so quickly with depth. The leaf rule is the same QUIET-LEAF as in alpha-beta.
Monte Carlo tree search (MCTS) values a move by playing random games from the positions after it, instead of scoring a fixed-depth tree with the heuristic. The version here is UCT, upper confidence bounds applied to trees. Each iteration has four steps. Selection walks down the tree and, at each node, chooses the child with the highest upper confidence bound 1 (UCB1). Expansion adds one untried move as a new child. Simulation plays a rollout, a random game from that child, to a result. Backpropagation adds the result to every node on the path back to the root.
The UCB1 score of a child is its average result plus an exploration bonus that is large for children with few visits. Children that have been tried rarely keep being tried, and the best-looking children are tried most.
Here w_c is the number of wins credited to child c, n_c is its visit count, and N is the visit count of its parent. C is the standard UCB1 constant. Wins are credited to the side that moved into the child, so w_c / n_c is the win rate of that move for the mover. The \ln N term grows slowly as the parent is visited more.
A rollout stops after 40 plies. Random play is noisy, and long games are slow to finish, so the position reached at the cutoff is scored with the same evaluation the tree searches use. Rollouts prefer captures: when a capture exists one is chosen at random, otherwise any legal move is chosen at random. A rollout that reaches a position where the side to move has no legal move ends there. Its value is then 0 if the stuck side is the side the rollout started from, and 1 if it is the opponent, because every rollout value is the chance that the starting side wins.
Here V is the rollout value: the chance that the side that started the rollout wins. \sigma_0 is that side, and s_{\text{end}} is the position after 40 plies. The evaluation is taken from \sigma_0's point of view, so the value is always for the starting side, even when the other side is to move at the end. A side with no legal move ends the rollout early, and the value is then 0 or 1 as the first formula gives. \text{EVAL} is the evaluation above, and the divisor 300 is the scale in points (EVAL_SCALE). \tanh is the hyperbolic tangent, which maps any real number into the interval from −1 to 1, so the cut-off value lies strictly between 0 and 1. Example. One man of material, 100 points, gives \tfrac12 + \tfrac12\tanh(1/3) \approx 0.66, and 300 points gives about 0.88.
function ROLLOUT(board, side):
start ← side
repeat 40 times: # rollouts stop after 40 plies
if LEGAL-MOVES(board, side) is empty:
return 0 if side = start else 1 # the side to move has lost
board ← RESULT(board, a random move, a capture if one exists)
side ← −side
return 0.5 + 0.5 · tanh(EVALUATE(board, start) / 300) # from the starting side's view
constants: ROLLOUT-PLIES = 40, EVAL-SCALE = 300
function ROLLOUT(board, side):
start ← side # the side the value is for
repeat ROLLOUT-PLIES times:
moves ← LEGAL-MOVES(board, side)
if moves is empty:
return 0 if side = start else 1 # the side to move has lost
pool ← the captures in moves, or all of moves if there are none
m ← a uniform random element of pool
board ← RESULT(board, m); side ← −side
return 0.5 + 0.5 · tanh(EVALUATE(board, start) / EVAL-SCALE) # squashed into (0, 1)
Why the sign flips. A rollout is played from the child's position by alternating sides, so after an odd number of plies the side to move is the opponent. The code keeps the starting side in \sigma_0 and evaluates from its view, so the value can always be read as the starting side's chance of winning. The full version shows the same rule line by line.
Backpropagation adds 1 - V to each node's wins, because the wins at a node belong to the side that moved into it, which is the opponent of the side to move there. The value is then flipped for the parent, one level up. Each node's visit count goes up by 1 on the same walk.
The move played is the child with the most visits, ordered first by the visit count, with the higher win rate breaking ties. The page reports the win rate of each root move, not a score, and the same ordering decides which moves are shown as best.
The search runs a fixed number of iterations, not a time limit. The strength table below gives the counts. The random generator is seeded from the position (the code uses zlib.crc32 of the board and the side to move), so the same position always gets the same answer on any machine.
function MCTS(position, side, iterations):
root ← a node for position, with every legal move untried
repeat iterations times:
node ← root
while node has no untried moves and node has children: # selection
node ← the child with the highest UCB1 score
if node has untried moves: # expansion
node ← a child made by one random untried move
value ← ROLLOUT(node) # simulation
for each node from node up to the root: # backpropagation
add (1 − value) to the node's wins; value ← 1 − value
return the move of the most visited child of root
constants: C = √2, ROLLOUT-PLIES = 40, EVAL-SCALE = 300
function MCTS(position, side, iterations, seed):
rng ← SEEDED-GENERATOR(seed)
root ← NODE(position, side, move = none, parent = none) # every legal move untried
repeat iterations times:
node ← root
while node.untried is empty and node.children is not empty: # selection
node ← the child c with the highest c.wins / c.visits + C · √(ln node.visits / c.visits)
if node.untried is not empty: # expansion
k ← random index in node.untried
swap node.untried[k] with the last entry; m ← remove the last entry
child ← NODE(RESULT(node.board, m), −node.side, m, node)
add child to node.children; node ← child
value ← ROLLOUT(node.board, node.side) # simulation
while node is not none: # backpropagation
node.visits ← node.visits + 1
node.wins ← node.wins + (1 − value)
value ← 1 − value
node ← node.parent
return the child of root with the highest (visits, wins / visits)
Untried moves. Each node holds all its legal moves as untried. Expansion removes one at random by swapping it to the end of the list and popping it, so removal is cheap. A node with no legal moves at all is simulated, and its rollout returns 0 for its side, so the tree learns that the position is lost.
Win rate for the root. A child's win rate is its wins over its visits, counted for the side at the root, so the figures in the analysis panel compare the root's moves directly.
Greedy scores each legal move with the evaluation of the position that move leaves, one ply deep, and plays the best. It does not look at the reply. A move that leaves the opponent with no legal move is scored as a win, \text{WIN} - 1, so it is preferred to any evaluated move. Ties go to the earlier move in the legal-move order, so greedy is deterministic.
Here s_m is the position after move m, and \sigma is the side to move. \text{EVAL}(s_m, -\sigma) is the evaluation from the opponent's point of view, so the minus sign turns it into the mover's point of view. The agent plays the move with the highest score.
function GREEDY(position, side):
for each move m in LEGAL-MOVES(position, side):
if LEGAL-MOVES(RESULT(position, m), −side) is empty:
score[m] ← WIN − 1 # the opponent has no reply: a win
else:
score[m] ← −EVALUATE(RESULT(position, m), −side)
return the move with the highest score
Random chooses uniformly from the legal moves, from a generator seeded from the position, so the same position always gets the same move. Random and greedy are the baselines: a search agent should beat both.
Chance does no search and no reasoning about the position beyond the type of each move. It works like the 2048 tile spawner, which places a 2 with probability 90% and a 4 with 10%. Each legal move gets a fixed weight by its type, the weights are renormalised over the legal moves, and one move is sampled. It is seeded from the position, so the same position always gets the same move.
| Move type | Example | Weight |
|---|---|---|
| Capture | Any move that jumps a piece (a chain counts once). | 5 |
| Man into the centre | A man that moves onto one of the central 4×4 squares. | 3 |
| Other man move | Any other step by a man. | 2 |
| King move | A king stepping one square. | 1 |
Here m is a legal move, \kappa(m) is its type from the table, and W(\kappa) is that type's weight. The denominator is the total weight of the legal moves, which is the renormalisation. Example. At the start position Red has seven legal moves. Four move into the centre (weight 3 each) and three do not (weight 2 each), so the total is 18. Each centre move has probability 3/18 \approx 0.17, and each other move has 2/18 \approx 0.11.
function CHANCE(position, side):
moves ← LEGAL-MOVES(position, side)
for each move m in moves:
weight[m] ← CHANCE-WEIGHTS[KIND(position, m)] # capture 5, centre man 3, man 2, king 1
return a move sampled with probability weight[m] / sum of all weights
Strength sets each agent's budget. Alpha-beta search is limited by time, and the other searches by a fixed depth or iteration count, so their answers do not depend on the machine.
| Budget | Fast | Normal | Strong |
|---|---|---|---|
| Alpha-beta, time (every board size) | 0.2 s | 0.8 s | 2.0 s |
| MCTS iterations, 8×8 | 300 | 1,000 | 2,000 |
| MCTS iterations, 10×10 | 200 | 500 | 1,000 |
| MCTS iterations, 12×12 | 150 | 350 | 500 |
| Minimax depth, 8×8 forced / optional | 2 / 2 | 4 / 3 | 5 / 4 |
| Minimax depth, 10×10 forced / optional | 2 / 2 | 3 / 2 | 4 / 3 |
| Minimax depth, 12×12 forced / optional | 2 / 1 | 3 / 2 | 3 / 2 |
Minimax depths are in plies (half-moves). The match runner uses a node budget of 3,000, 12,000 and 40,000 nodes for alpha-beta at Fast, Normal and Strong, instead of time23.
Search cost. Ten positions were built by playing 8 random legal plies from the opening (seeds 1 to 10), with Red to move. Each was searched by minimax and by alpha-beta search to depths 4, 5 and 6. The alpha-beta counts are summed over the iterative-deepening passes 1 to d, as the agent runs it. The scores match at every depth on all eight non-forced positions, and the moves match on seven of them, with the mismatches being ties24.
| Depth (plies) | Minimax positions, median | Alpha-beta positions, median | Same score / same move |
|---|---|---|---|
| 4 | 3,373 | 498 | 8 of 8 / 7 of 8 |
| 5 | 15,541 | 1,287 | 8 of 8 / 7 of 8 |
| 6 | 90,072 | 2,676 | 8 of 8 / 7 of 8 |
Positions with a single legal move are left out of the agreement columns. The move generator matches the published perft counts from the opening (7, 49, 302, 1,469 and 7,361 positions at depths 1 to 5)24. Match play. In the 8×8 round robin at level 1 (10 games per pair, forced captures, games paired from seeded 4-ply openings), each agent played the other four, so each total covers 40 games. Over those games, alpha-beta won 32, drew 8 and lost none; MCTS won 22, drew 12 and lost 6; minimax won 21, drew 9 and lost 10; greedy won 7, drew 4 and lost 29; random won none, drew 3 and lost 3725. Head to head, alpha-beta won 7 of 10 against minimax (3 draws) and 5 of 10 against MCTS (5 draws), and won all 10 against greedy and random. MCTS won 3 of 10 against minimax (6 draws, 1 loss), 9 of 10 against greedy (1 draw), and all 10 against random. Minimax won all 10 against greedy and random. Against chance, alpha-beta won all 10 games26. Ten games per pair is a small sample, so read these as a rough ordering at this strength.