Play Against the AI
You play White. Type a move in SAN notation and press Enter or Move. The AI plays Black.
♜
♞
♝
♛
♚
♝
♞
♜
♟
♟
♟
♟
♟
♟
♟
♟
♙
♙
♙
♙
♙
♙
♙
♙
♖
♘
♗
♕
♔
♗
♘
♖
Your turn (White).
Move log
No moves yet.
Description
Neural layer: A ResNet-style policy/value network (ChessNet) trained in two stages. First, supervised pre-training on real human games from HuggingFace. Then MCTS self-play to improve beyond human patterns — the same architecture AlphaZero uses. The network outputs a policy over all 4096 possible moves and a value estimating win probability.
Why chess: Chess is the canonical benchmark for game AI — an engine that beats its own hand-tuned evaluation with a learned one is a concrete, measurable result.
Architecture
Chess AI — Two-Layer Pipeline
══════════════════════════════════════════════════
Layer 1: Classical Search
─────────────────────────
Board state
│
▼
┌────────────────────────────────────┐
│ Minimax + Alpha-Beta Pruning │
│ - explores game tree to depth N │
│ - alpha-beta cuts ~50–70% of tree │
└──────────────┬─────────────────────┘
│
▼
Best move returned
──────────────────────────────────────────────────
Layer 2: Neural Network (ChessNet)
──────────────────────────────────
Board → 13 input planes
(6 white piece types + 6 black + 1 turn plane)
│
▼
┌────────────────────────────────────┐
│ Entry Conv → 5× ResBlock (64 ch) │
│ Residual connections, BatchNorm │
└──────────┬───────────┬─────────────┘
│ │
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Policy Head │ │ Value Head │
│ 4096 logits │ │ tanh → ±1 │
│ (all moves) │ │ (win prob) │
└──────────────┘ └──────────────┘
Training:
1. Supervised pre-training on human games (HuggingFace dataset)
2. MCTS self-play — policy/value network guides tree search,
self-play results refine the networkArchitecture mirrors AlphaZero: a single ResNet with two heads replaces both the move selector and the evaluation function.Dev Notes
Tech Stack
Python, PyTorch for ChessNet, python-chess for move generation and board representation, torch.onnx for export.
From Connect 4 to Chess
Connect 4 Bot proved the minimax + tree search approach. Chess's branching factor is ~5× larger — alpha-beta pruning goes from useful to essential.
Why Not DQN
DQN outputs one Q-value per action from a single state — poorly suited to chess's 4096-move action space. The policy/value architecture handles the full move distribution directly, which is why AlphaZero uses it.
Download
chessnet.onnx
ChessNet exported to ONNX — portable and runtime-agnostic. Load with onnxruntime in Python or any ONNX-compatible engine.
ONNX~14 KB
↓ Download chessnet.onnx