Cody is an experimental chess engine where every line of code is generated by AI. The goal is to push LLM-assisted programming and answer one question: how strong of a chess engine can AI build from scratch?
Every code improvement Cody makes requires AI API calls, which cost real money. While you can run Cody locally with free models like Ollama, the best results come from premium models like GPT-4 or Claude. If you find this experiment interesting or valuable, please consider supporting development costs.
Your contributions help keep Cody improving and experimenting with cutting-edge AI models. Every donation directly funds API usage and compute resources.
Unlike traditional engines (like Stockfish) or NNUE-based engines tuned by humans, Cody is a "Zero-Human-Code" project.
- Architecture and logic: All search algorithms, evaluation functions, and bitboard manipulations are AI-generated.
- Debugging: Human intervention is limited to providing error logs back to the AI for self-correction.
- Goal: Achieve a competitive ELO rating with a codebase birthed from prompt engineering.
First time here? Start with these resources:
- README.md <- You are here (project overview)
- ROADMAP.md - Current priorities and completed milestones
- QUICKREF.md - Command cheatsheet while working
- cody-graph/PHASES.md - Details on each orchestration phase
- cody-graph/DIAGNOSTICS.md - Troubleshooting and logs
- cody-graph/ELO_GAIN_PHASE.md - ELO loop details
- architecture.md - Deep dive into design and implementation
For running the improvement orchestrator, see "Automated Improvement System" section below.
- Bitboard representation: High-performance board state management with
PieceBitboardsand occupancy maps. - UCI protocol support: Works with standard chess GUIs like Arena, Cute Chess, or Scid vs. PC.
- Search algorithms:
- Negamax with alpha-beta pruning.
- Iterative deepening with time management.
- Quiescence search to avoid the horizon effect.
- Transposition table for move ordering and cutoff reduction.
- Evaluation: AI-crafted heuristics, including piece-square tables (PST) and material imbalance weights.
- Move generation: Pseudo-legal move generation with legality verification via attack checking.
Cody uses an automated multi-phase improvement loop powered by LangGraph orchestration:
1. Run clippy --W clippy::pedantic β Detect warnings
2. LLM proposes fix (unified diff)
3. Apply patch to disk
4. Verify (build + tests)
5. Commit on success or rollback on failure
Additional phases can be enabled in cody-agent/config.json:
- Clippy phase: Eliminate pedantic clippy warnings
- Refactoring phase: Improve code quality and architecture
- UCIfeatures phase: Implement missing UCI commands for tournament-grade protocol support
- Performance phase: Optimize critical paths for speed (uses o3 model)
- ELOGain phase: Chess-specific improvements to increase playing strength (uses o3 model)
- Unit Tests/Docs phase: Test coverage and documentation updates
The codebase is organized as a Cargo workspace with two crates:
-
bitboard/β Pure bitboard logic, move generation, position manipulation- Exports:
Position,Move,MoveGen, bitboard utilities
- Exports:
-
engine/β Search engine, evaluation, UCI API, benchmarks- Depends on:
bitboard(path dependency inCargo.toml) - External dependencies:
criterion(benchmarking),once_cell,rayon,crossbeam - Exports: UCI API, search algorithms, benchmark harness
- Depends on:
Key constraints:
- Fixed-block allocator: Search nodes are preallocated in an arena, no heap allocations in hot path
- External dependencies: Allowed only when they are extremely high-performance and used in performance-critical paths
- Type safety: Semantic newtypes like
Ply,Depth,NodeIdto prevent type confusion - Separation of concerns: Bitboard crate focuses on board rules; engine crate handles search/UCI
See architecture.md for detailed design.
Install dependencies:
pip install -U langgraph openaiAuthenticate with OpenAI:
# Linux/macOS
export OPENAI_API_KEY="sk-..."
# Windows (PowerShell)
$env:OPENAI_API_KEY = "sk-..."
# Windows (cmd)
set OPENAI_API_KEY=sk-...Configure in cody-agent/config.json:
{
"model": "gpt-4-turbo",
"models": {
"clippy": "gpt-4-mini",
"refactoring": "gpt-4-turbo",
"features": "gpt-4-turbo",
"performance": "gpt-4-turbo",
"ELOGain": "gpt-4-turbo",
"unit_tests_docs": "gpt-4-mini"
},
"use_local": false
}Note on Model Names: The model names above are current defaults. Adjust them to match your OpenAI API availability. For complex optimization tasks (performance, ELOGain), use your most capable model. For simpler tasks (clippy), faster/cheaper models work well.
model: Default model (kept for future compatibility)models.<phase>: Per-phase model overrideclippy: Fastest/cheapest model (fixing obvious warnings)refactoring: General-purpose model (code quality improvements)features: General-purpose model (new capabilities)performance: Capable model (deep optimization analysis)ELOGain: Capable model (chess-specific improvements)unit_tests_docs: Faster/cheaper model (straightforward test generation)
use_local: Iftrue, use local Ollama instead of OpenAI API
From the repo root:
# Run all configured phases
python cody-graph/main.py all
# Run a single phase
python cody-graph/main.py clippy # Fix compiler warnings
python cody-graph/main.py refactor # Code quality improvements
python cody-graph/main.py features # New features/UCI commands
python cody-graph/main.py performance # Speed optimization
python cody-graph/main.py elogain # Chess ELO improvements
python cody-graph/main.py tests # Test coverage & docsThe orchestrator logs diagnostic information to .cody_logs/ with timestamped files:
*_clippy_output.txtβ Compiler warnings detected*_llm_response.txtβ LLM reasoning and proposed fixes*_diff_extracted.logβ Applied patches*_build_output.txtβ Build/test results
Check progress in real-time or review diagnostics afterward. See DIAGNOSTICS.md for detailed log reference.
This will:
- Load configured phases from
cody-agent/config.json - Execute phases sequentially (or run a single phase)
- Generate diagnostics in
.cody_logs/ - Save progress to
orchestrator_state.json
Optional environment variables:
# Linux/macOS
export CODY_REPO_PATH="/path/to/Cody"
export OPENAI_API_KEY="sk-..."
# Windows (PowerShell)
$env:CODY_REPO_PATH = "D:\Cody"
$env:OPENAI_API_KEY = "sk-..."- cody-graph/DIAGNOSTICS.md β Diagnostic output and troubleshooting
- cody-graph/PHASES.md β Multi-phase orchestration details
Build:
cargo build --releaseRun tests:
cargo test
cargo test -p bitboard
cargo test -p engineRun benchmarks:
cargo bench -p engineRun UCI engine:
cargo run -p engineValidate move generation:
cargo run --release -p engine -- perft 5Use cody-graph/tools/selfplay.py to decide whether a code change should be accepted as an ELO improvement.
cutechess-cliis installed atC:\Program Files (x86)\Cute Chess\cutechess-cli.exe.- Opening book exists at
cody-graph/tools/weak.epd. - Python env is available (
D:/Cody/.venv/Scripts/python.exein this repo).
Run from repo root (D:\Cody):
# Build current commit as candidate
cargo build --release
# Keep a baseline executable in the same folder as cody.exe.
# Example: create baseline once from a known-good commit/tag, then copy it here as cody-vX.Y.exe.
Copy-Item .\target\release\cody.exe .\target\release\cody-v1.0.exeselfplay.py expects:
- Candidate:
target/release/cody.exe - Baseline: highest versioned
target/release/cody-v*.exe
Push-Location .\target\release
D:/Cody/.venv/Scripts/python.exe ../../cody-graph/tools/selfplay.py --mode strict
Pop-LocationIf you are already in repo root (D:\Cody), use this equivalent command:
D:/Cody/.venv/Scripts/python.exe .\cody-graph\tools\selfplay.py --mode strict../../cody-graph/tools/selfplay.py is only valid when current directory is target\release.
Strict mode pins deterministic settings (seed, threads, hash, sequential openings) and writes:
target/release/temp_match.pgntarget/release/temp_match.meta.json
- Build and tests pass:
cargo build --releasecargo test -p bitboardcargo test -p engine
- Selfplay completes in
--mode strictwith no illegal move/disqualification. - Candidate score is better than baseline in the strict run (
Score of Candidate vs Champion: W - L - DwithW > L). - Keep
temp_match.meta.jsonwith the result so the comparison can be reproduced later.
If W <= L, treat the change as not yet proven and iterate.
- Full legal move generation with proper castling and en passant handling
- Quiescence search to evaluate quiet positions accurately
- Transposition table for move ordering and cutoff reduction
- Time management with absolute and remaining time budgets
- UCI protocol for integration with chess GUIs
Cody currently plays at about 2100, based on playing against weak engines: Simplex, Rebel and Minimal.
Version ELO increases
| Engine | Elo Gain |
|---|---|
| Simplex | 2373 |
| Cody-2.0.0.0 | 2106 |
| Rebel | 1992 |
| Minimal | 1978 |
| Cody-1.0.0.0 | 1865 |
Completed:
- β Complete bitboard infrastructure
- β Legal move generation (pseudo-legal + legality check)
- β UCI protocol handler
- β Negamax search with alpha-beta pruning
- β Quiescence search
- β Transposition table
- β Time management
- β Automated clippy warning fixes
In Progress / Recently Completed:
- π Improving move ordering heuristics
- π Optimizing search performance
- β Automated ELO improvement loop with SPRT testing and version management
- β Multi-phase orchestration system for diverse improvement strategies
- β Diagnostic logging with detailed LLM interaction tracking
Not Yet Implemented (Infrastructure Ready):
- β³ Refactoring phase (code quality β agent ready, decision criteria not finalized)
- β³ Additional UCI feature expansion (infrastructure ready, feature backlog pending)
Completed Phases:
- β Clippy fixes β Automated compiler warning elimination
- β ELO gain β Systematic chess engine strength improvements
- β Unit test generation β Position-specific regression test creation
MIT License. See LICENSE for details.