ArticlesProjectsWeeklyCredentialsAbout

TMC #0016: Shannon Chess Engine

A pure-Python implementation of Shannon's 1950 chess engine design: full legal move generation for all piece types, the original material + mobility + pawn-structure evaluation function, and minimax search with alpha-beta pruning.

chessshannonminimaxalpha-betagame-aievaluation-functionpythonsearch

Shannon's 1950 paper described a complete chess engine design that was never implemented due to hardware constraints. This project builds exactly what Shannon specified.

What It Includes

Board & move generation: 8×8 board with full legal move generation for all six piece types, including pawn double-advance, diagonal captures, and promotion. Sliding pieces (bishop, rook, queen) use direction vectors; the board boundary is checked inline.

Shannon evaluation function: Material balance (Shannon's original centipawn values: P=1, N=B=3, R=5, Q=9, K=200) plus 0.1 × mobility differential and −0.5 penalty per doubled or isolated pawn. Symmetric; returns 0.00 on the starting position.

Minimax with alpha-beta: Recursive minimax search to configurable depth (default 3). Alpha-beta pruning reduces the node count from ~35d35^d to approximately 35d/235^{d/2}. The tree size demo measures this reduction empirically at depths 1–4.

Demo game: A 10-move engine vs engine game printing each move, its evaluation score, and node count. Shows the engine correctly preferring material gain, mobility, and pawn structure.

Running It

python shannon_chess.py              # all demos (depth 3)
python shannon_chess.py --demo eval  # evaluation function demo
python shannon_chess.py --demo tree  # game tree size comparison
python shannon_chess.py --demo game  # 10-move demo game
python shannon_chess.py --depth 2   # faster, shallower search

No external dependencies: pure Python 3.10+.

Source code
# TMC #0016 — Shannon Chess Engine

Companion code for [The Thinking Machine Chronicles #0016](/articles/tmc-0016-shannon-chess).

Implements Shannon's 1950 chess design: full legal move generation, the original material + mobility + pawn-structure evaluation function, and minimax search with alpha-beta pruning.

## Usage

```bash
python shannon_chess.py              # all demos (depth 3)
python shannon_chess.py --demo eval  # evaluation function on starting position
python shannon_chess.py --demo tree  # game tree size vs alpha-beta reduction
python shannon_chess.py --demo game  # 10-move engine demo game
python shannon_chess.py --depth 2   # adjust search depth
```

Pure Python 3.10+, no external dependencies.