An open API service indexing awesome lists of open source software.

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.

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 |