Chapter 2 · Game

Chess (vs. AI)

← Chapter 2

How to play

  • You play White; the computer plays Black. Click one of your pieces (or focus it and press Enter), then a marked square. Dots show quiet moves, rings show captures.
  • All standard rules apply (castling, en passant, check, checkmate, stalemate, draws by threefold repetition and the fifty-move rule, insufficient material). Pawns always promote to a queen.
  • Undo takes back your last move and the AI's reply. New game starts over.
  • The last move is highlighted in yellow; a king in check is marked in red.

How the AI thinks

The computer uses minimax search with alpha-beta pruning. It looks ahead the chosen number of plies, assumes you will always pick the reply that is worst for it, and chooses the move with the best guaranteed outcome. Alpha-beta pruning skips branches that cannot change the decision, which speeds up the search a lot without changing the result.

At the end of the search, positions are scored by an evaluation function: material (pawn 100, knight 320, bishop 330, rook 500, queen 900) plus piece-square tables that reward good placement (knights in the centre, advanced pawns, a sheltered king). Checkmate is scored as a win or a loss, stalemate as a draw.

Connection to game theory

Chess is a finite, two-player, zero-sum, perfect-information game. By Zermelo's theorem it has a definite value found by backward induction (White wins, Black wins, or a draw); but the game tree is far too large to solve, so programs search to a limited depth and approximate the value with heuristics.