https://github.com/wtbates99/openboard
Computer vision tools for detecting a physical chess board, warping it top-down, and reporting occupied squares from webcam frames.
https://github.com/wtbates99/openboard
chess computer-vision opencv python webcam
Last synced: 17 days ago
JSON representation
Computer vision tools for detecting a physical chess board, warping it top-down, and reporting occupied squares from webcam frames.
- Host: GitHub
- URL: https://github.com/wtbates99/openboard
- Owner: wtbates99
- Created: 2026-04-26T22:40:05.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-02T18:00:29.000Z (about 2 months ago)
- Last Synced: 2026-06-14T08:34:03.185Z (17 days ago)
- Topics: chess, computer-vision, opencv, python, webcam
- Language: Python
- Size: 53.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OpenBoard
An open-source chess engine trained on GM games with AlphaZero-style self-play, built to run on Apple Silicon.
## How it works
- **Neural network** — 6-block ResNet with a policy head (4096 move logits) and value head (position evaluation), implemented in MLX
- **Training** — supervised pretraining on GM games fetched from Lichess, followed by a self-play loop where the engine generates its own training data
- **Search** — Monte Carlo Tree Search (MCTS) guided by the network's policy and value outputs
- **Hardware** — optimized for Apple Silicon via MLX; runs on CPU elsewhere
## Install
```bash
uv sync
```
## Fetch training games
```bash
uv run python main.py
```
Fetches 1000 blitz/rapid games from each of several GM Lichess accounts and saves them to `games.pgn`.
## Train
```bash
uv run python train.py
```
Supervised pretraining on the PGN data. Runs 20 epochs and saves weights to `model.safetensors`.
## Self-play loop
```bash
uv run python selfplay.py
```
Runs 10 iterations of: generate 50 self-play games → retrain on GM + self-play data → repeat. Each iteration the model improves its own training distribution.
## Play against the engine
```bash
uv run python play.py white 200
```
Second argument is your color (`white` or `black`), third is engine simulations per move (higher = stronger, slower).
Enter moves in standard notation (`e4`, `Nf3`, `O-O`) or from-to squares (`e2e4`, `g1f3`). Commands: `undo`, `flip`, `quit`.
```
8 r n b q k b n r
7 p p p p p p p p
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 P P P P P P P P
1 R N B Q K B N R
a b c d e f g h
```
## Files
| File | Purpose |
|------|---------|
| `main.py` | Fetch games from Lichess GM accounts |
| `data.py` | Parse PGN into training tensors |
| `model.py` | ResNet policy+value network |
| `train.py` | Supervised training loop |
| `mcts.py` | Monte Carlo Tree Search |
| `selfplay.py` | Self-play training loop |
| `play.py` | Terminal UI to play against the engine |