Othello / Reversi
Play Othello (Reversi) against a greedy computer.
Overview
Othello (also called Reversi) is a two-player abstract-strategy game played on an 8x8 board with two-sided black-and-white discs. Players take turns placing a disc on an empty square such that one or more of the opponent's discs are flanked between the new disc and another of the player's existing discs; every flanked disc flips to the placer's colour. When neither player can move, the game ends and whoever has more discs of their colour wins.
This implementation pits you against a greedy computer that picks the move maximising immediate disc count. A greedy AI is straightforward to beat with a corner-and-mobility strategy, but it's a fine teaching opponent and demonstrates why human experts focus on board control, not flip counts, in the opening and midgame.
How it works
The starting position has four central discs in a standard arrangement: two black on the descending diagonal and two white on the ascending diagonal. Each move must flip at least one opposing disc — otherwise it's illegal. Move generation scans all empty cells, then for each cell checks the eight directions outward for at least one opposing disc terminated by a same-colour disc.
If a player has no legal move, they pass and the opponent moves again; if both players pass consecutively, the game ends. The greedy AI evaluates every legal move by simulating it, counting the resulting disc total, and picking the largest. Stronger AIs add corner priority, edge stability, mobility, and shallow lookahead, but the greedy version is enough to make a satisfying first-game opponent.
Examples
- Opening move: black can play C4, D3, E6, or F5. Each flips one white disc and is symmetric under board rotation.
- The X-squares (B2, B7, G2, G7) are usually traps — playing one gives the opponent access to the adjacent corner.
- A common beginner mistake is to chase flips: every flip creates more frontier discs the opponent can flip back later.
- A perfect-game final score is 64-0; in practice tight games end in the 33-31 range.
FAQ
Why is the AI called greedy?
It picks the move that maximises immediate disc count without considering future positions.
Is more discs in the midgame good?
Counter-intuitively no — more discs in the midgame usually means more frontier squares for the opponent to flip later.
What's the best opening square?
By symmetry, all four opening moves for black are equivalent. White's response shapes the game more.
Can I pass when I have a legal move?
No. You must move if a legal move exists.
What's the perfect-play result?
With perfect play from both sides, computer analysis indicates a draw on the 8x8 board.