Board Game Solver

Solves Four in a Row and Kalah positions exactly: win, loss or draw and the value of every move.

Four in a Row: moves as column digits 1–7 from the first move on, or 6 lines of 7 cells (X = first player, O = second, . = empty), top row first. Kalah: “south: 0 0 0 2 1 1 | 20”, “north: …” (pits from each player’s left, store after |) and “to move: south”.

More options

The solver stops after this many positions and reports “not solved”.

Try an example: · · · · ·

More about this tool

Part of Playcards

How it works

Enter a Four in a Row position as the moves played so far (column digits 1–7, e.g. 4453) or as a 6-line grid, and the solver searches it to the end of the game: does the player to move win, lose or draw with perfect play, how fast, and what is every column worth. Positions with many empty cells take too long to solve exactly — the solver then stops at the node limit and says so instead of guessing. The Playcards computer player uses the same solver near the end of a game. Kalah endgames work the same way: enter both rows of pits with their stores and who is to move, and the solver plays every line to the end and gives the final store difference for each pit.

  • Exact game-tree search (negamax with alpha-beta pruning, centre columns first, a transposition table of upper bounds and an immediate-win check) from the given position to the end of the game; no heuristics decide the answer.
  • Score convention used by published Four in a Row test sets: 0 for a draw; for a win (43 − stones on the board before the winning stone) ÷ 2, rounded down — that is 22 minus the number of stones the winner has dropped. A loss is the negative. Column scores are the scores after dropping in that column, from the point of view of the player who drops.
  • The search stops at the node limit. Early positions (more than about 20 empty cells) usually need far more nodes than the limit allows; the answer is then “not solved” rather than an estimate. The empty board is a first-player win (Allis 1988, Allen 1988), which this tool cannot verify within its limit.
  • Kalah (6 pits, any number of seeds): exhaustive minimax over every line of play to the end of the game with a table of positions already solved; the value is the final store difference for the player to move with best play by both sides (an extra turn keeps the same player on move). The default rules capture only when the opposite pit holds seeds; the line “empty capture: on” switches to the house rule that also captures the last seed alone.

Sources

Part of Playcards

  • Playcards Card and board games table

    47 card games from Skat and Jass to Scopa and Daifugō, vs the computer, at home or online.

    Open Playcards

Related tools

  • Draughts PDN Checker – Checks every move of a draughts or checkers game in PDN, with compulsory and majority captures.

How to use the board game solver

Solve a Four in a Row position exactly — win, loss or draw for the player to move, how fast, and the value of every column — or a small Kalah endgame.

What it is for

In Four in a Row the decisive mistake often happens several moves before anyone notices. This solver takes a position and searches every line to the end of the game, so it can tell you who wins with perfect play from both sides, how quickly, and which columns keep that result. It is an exact search, not an estimate: if it cannot finish within the search limit, it says “not solved” instead of guessing.

You enter the position either as the moves played so far — the column digits 1 to 7 from the first move on, such as 4453 — or as a grid of six lines with seven cells each (X for the first player, O for the second, a dot for an empty cell, top row first). With a grid, the player to move follows from the number of stones.

Worked example

The default position is 52753311433677442422121, a middle game after 23 moves. The answer: The second player (to move) wins with perfect play, completing four with their 14th stone. Winning column: 5. The Value of each column table explains the choice: column 5 has the score 8, columns 3, 4 and 6 also win but more slowly (score 7), and columns 1, 2 and 7 still win but much later (scores 2 and 3). The search needed about 15,000 positions.

A grid example: a board with X on columns 2, 3 and 4 of the bottom row and O on columns 4 and 6 above and beside them. O is to move and every column loses: X has open ends on both sides, so the answer is a loss with the score −18 — X completes four with their 4th stone.

Very early positions are too big. The position 4444 (four stones) stops at the limit of 2,000,000 positions: Not solved within 2,000,000 positions (38 empty cells).

How to read the result

  • Outcome for the player to move: win, loss or draw with perfect play by both sides.
  • Score: 0 is a draw. A positive score is a win for the player to move: 22 minus the number of stones the winner has dropped when the four is complete, so a higher score is a faster win. Negative scores mirror this for a loss.
  • Value of each column: the score after dropping there. The best columns have the same score as the position; for a lost position they resist longest.
  • Positions searched: how much work the answer took.

Tips and common mistakes

  • Count your digits: every digit is one stone, alternating between the players, starting with the first player.
  • The solver rejects impossible input — a column with more than six stones, a move after the game was won, floating stones in a grid, or X having fewer stones than O.
  • From about 20 empty cells on, raise the search limit (up to 5,000,000) or enter a later position.
  • Several columns can share the best score; any of them is equally good.
  • A position that is already decided (four in a row on the board, or a full board) is reported as finished.

FAQ

Can it solve the empty board?

Not within its limit. The empty board is a known first-player win when the first stone goes into the middle column, but proving it takes far more positions than this tool searches.

Where do the score numbers come from?

They follow the convention of published Four in a Row test sets, so you can compare results directly. The tool's own tests check it against such published positions.

Does the Playcards computer player use this?

Yes. The strongest Four in a Row player in Playcards switches to this exact solver once 16 or fewer cells are empty.

Can it solve other games?

Small Kalah endgames, too: choose Kalah, enter both rows of pits with their stores and who is to move, and the solver gives the final store difference for every pit.

Guide last updated:

For scripts and AI agents

  • JSON API: POST https://playcardsboardsolver.usefulweb.app/api/v1/calculate (same calculation as this page)
  • Interface description: OpenAPI 3.1 · AI guide: llms.txt
  • MCP server (Streamable HTTP): https://playcardsboardsolver.usefulweb.app/mcp · tool name playcards_board_solver
Example request
curl -s -X POST https://playcardsboardsolver.usefulweb.app/api/v1/calculate \
  -H 'content-type: application/json' \
  -d '{"game":"fourinrow","position":"44444433333322"}'
Feedback · ideas & bug reports welcome