A terminal-based chess application where AI engines and LLMs play against each other. Watch Stockfish battle LLMs on a Unicode chess board with real-time move updates.
- Multiple engine types: Stockfish, Ollama LLMs, or Random
- Live display: Unicode chess board centered in terminal
- Move highlighting: Last move shown in green
- Material score: Real-time advantage tracking (e.g., "+3 material")
- Captured pieces: Displayed next to each player
- Adjustable Stockfish skill levels (0-20)
- Tournament mode with statistics
- PGN export for game analysis
- Python 3.8+
- Stockfish (recommended) - for proper chess play
- Ollama (optional) - for LLM-based play
cd ai_chess# Create venv
python -m venv venv
# Activate (Linux/macOS)
source venv/bin/activate
# Activate (Windows)
venv\Scripts\activatepip install -r requirements.txt# Arch Linux
sudo pacman -S stockfish
# Ubuntu/Debian
sudo apt install stockfish
# macOS
brew install stockfish
# Windows - download from https://stockfishchess.org/download/# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
# Pull models
ollama pull llama3
ollama pull mistral
# Start Ollama
ollama serve# See all options
python -m src.main --help
# Default game: Stockfish (skill 10) vs Stockfish (skill 10)
python -m src.main
# Watch a mismatch: strong vs weak
python -m src.main --white-skill 15 --black-skill 3# Equal skill match
python -m src.main
# Different skill levels (skill 0-20, higher = stronger)
python -m src.main --white-skill 15 --black-skill 5# LLM plays white against weak Stockfish
python -m src.main --white-engine llm --white-model llama3 --black-engine stockfish --black-skill 3python -m src.main --white-engine llm --white-model llama3 --black-engine llm --black-model mistral# 5-game tournament between Stockfish levels
python -m src.main --tournament --games 5 --white-skill 10 --black-skill 5
# Save all games to PGN
python -m src.main --tournament --games 10 --save-pgnpython -m src.main --white-engine random --black-engine random --delay 0.3| Option | Default | Description |
|---|---|---|
--white-engine |
stockfish | Engine for white: stockfish, llm, or random |
--black-engine |
stockfish | Engine for black: stockfish, llm, or random |
| Option | Default | Description |
|---|---|---|
--white-skill |
10 | Stockfish skill for white (0-20) |
--black-skill |
10 | Stockfish skill for black (0-20) |
--engine-path |
auto | Path to Stockfish executable |
--engine-time |
1.0 | Time per move in seconds |
--engine-depth |
- | Search depth (overrides time) |
| Option | Default | Description |
|---|---|---|
--white-model |
llama3 | Ollama model for white |
--black-model |
llama3 | Ollama model for black |
--ollama-url |
http://localhost:11434 | Ollama API URL |
--temperature |
0.7 | LLM temperature (0.0-1.0) |
| Option | Default | Description |
|---|---|---|
--delay |
1.5 | Delay between moves (seconds) |
--games |
1 | Number of games to play |
--tournament |
false | Run tournament with stats |
--save-pgn |
false | Save games to PGN files |
--list-models |
false | List available Ollama models |
-h, --help |
- | Show help message and exit |
| Level | Approximate Rating | Description |
|---|---|---|
| 0-3 | 800-1200 | Beginner |
| 4-7 | 1200-1600 | Casual player |
| 8-11 | 1600-2000 | Club player |
| 12-15 | 2000-2400 | Advanced |
| 16-19 | 2400-2800 | Expert/Master |
| 20 | 3000+ | Full strength |
# Beginner vs intermediate Stockfish
python -m src.main --white-skill 3 --black-skill 8
# Fast game with minimal delay
python -m src.main --delay 0.5 --engine-time 0.5
# Deep analysis mode (slower but stronger)
python -m src.main --engine-depth 20
# LLM trying to beat weak Stockfish
python -m src.main --white-engine llm --white-model llama3 --black-skill 1
# 10-game match, save results
python -m src.main --tournament --games 10 --save-pgn --white-skill 10 --black-skill 15The game displays a centered chess board with:
╭───────────── AI Chess Battle ──────────────╮
│ │
│ ♚ Stockfish (Skill 5) (Black) │
│ │
│ a b c d e f g h │
│ 8 ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ │
│ 7 ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ │
│ ... │
│ 2 ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ │
│ 1 ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖ │
│ │
│ ♔ Stockfish (Skill 15) (White) │
│ Captured: ♟ ♟ ♞ │
│ │
│ Move 12 ♔ White to play │
│ ♔ Stockfish (Skill 15) leads by +4 │
│ │
╰──────────── Powered by Ollama ─────────────╯
- Board colors: Tan/brown squares with high contrast pieces
- Highlighting: Last move shown in bright green
- Material score: Shows who's winning and by how much
PGN files are saved to the games/ directory:
games/20240115_143022_Stockfish_(Skill_10)_vs_Stockfish_(Skill_5).pgn
ai_chess/
├── README.md
├── requirements.txt
├── src/
│ ├── __init__.py
│ ├── main.py # CLI entry point
│ ├── chess_game.py # Game orchestration
│ ├── board_display.py # Terminal rendering
│ ├── ai_player.py # Ollama LLM integration
│ ├── engine_player.py # Stockfish integration
│ ├── game_recorder.py # PGN save/replay
│ └── utils.py # Helper functions
├── games/ # Saved PGN files
└── tests/
└── __init__.py
Install Stockfish for your system (see Installation), or specify the path:
python -m src.main --engine-path /path/to/stockfishOnly needed if using --white-engine llm or --black-engine llm:
ollama serveThis is expected - LLMs are not chess engines. They pattern-match rather than calculate. Use Stockfish for proper chess, or pit LLMs against low-skill Stockfish for entertainment.
MIT


