A C# chess engine built with bitboards and accessible via a REST API.
Try it: Chess Bot
- Bitboard Board Representation
- Magic Bitboards
- Legal Move Generation
- *Opening Book
- Repetition Detection
- Multi-threading
- Alpha-Beta Pruning
- Transposition Tables
- Move Ordering
- PVS
- Mate Search
- Asperation Windows
- Null Move Search
- Itterative deeping
- Quiescence Search
- Material Evaluation
- Piece-Square Tables
- Pawn Structure
- NNUE Neural Network - uses Orion 1.1's pretrained network (trained with the Cerebrum library by David Carteau, MIT license)
Based on current implementation, I estimate the bot to play at approximately 2000-2300 Elo. This is an informal estimate.
- .NET 10.0 SDK or later
-
Clone the repository:
git clone https://github.com/RJDonnison/ChessBot.git cd ChessBot -
Run the API server:
dotnet run --project ChessBot.Api
The API will start on
http://localhost:5000
The engine behavior is controlled via the Engine section in appsettings.json:
{
"Engine": {
"Threads": 4,
"HashMb": 128,
"TimeMs": 1000,
"Eval": "Nnue",
"EvalFile": "Networks/orion64-v1.1.nn"
}
}| Setting | Description | Default |
|---|---|---|
Threads |
Number of search threads (null = auto-detect, clamped 1–8) | null |
HashMb |
Transposition table size in MB | 128 |
TimeMs |
Default think time in milliseconds (per request if no remainingTimeMs provided) |
1000 |
Eval |
Evaluation mode: "Nnue" or "Classic" (case-insensitive) |
"Nnue" |
NnueFile |
Path to NNUE network file (relative to API content root or absolute) — only used if Eval=Nnue |
(required for Nnue) |
When Eval=Nnue, the engine loads the specified network file at startup. If loading fails, it falls back to Classic with a console warning.
To test without building a custom UI, you can use the provided Chess Bot Interface.
Returns the best move for a given position.
Parameters:
fen(required) - The board position in FEN notationtime(optional) - Remaining time in milliseconds for the player to move (affects think time calculation)
Example:
# Without time (uses default TimeMs setting)
curl "http://localhost:5000/bestmove?fen=rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR%20w%20KQkq%20-%200%201"
# With time (overrides default think time)
curl "http://localhost:5000/bestmove?fen=rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR%20w%20KQkq%20-%200%201&time=30000"Response:
{
"bestmove": "e2e4"
}// Import the ChessBot.Core library
using ChessBot.Core;
var bot = new Bot();
string fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
string bestMove = bot.GetBestMove(fen);
Console.WriteLine($"Best move: {bestMove}");- ChessBot.Core - Core engine logic
- ChessBot.Api - ASP.NET API wrapper
- ChessBot.Core.Tests - Unit tests for Perft move generation tests
- WebAssembly (WASM) - Browser-native engine compilation
- Multi-threading - Parallel search implementation
- ML evaluation - Neural network-based position evaluation (NNUE via Orion 1.1 / Cerebrum)
- History heuristic - Move ordering improvement using historical data
- King safety evaluation - Enhanced king attack detection and safety scoring
- Lazy evaluation - Deferred evaluation for performance
See LICENSE for details.
This project uses the following third-party assets:
-
Orion 1.1 Neural Network (
ChessBot.Api/Networks/orion64-v1.1.nn): The pretrained NNUE model from Orion v1.1 by David Carteau. The network file is redistributed unmodified as permitted by its license. For more details, see orionchess.com. -
Cerebrum Library (reference implementation): The NNUE inference code is ported from the Cerebrum library v2.0 by David Carteau, licensed under the MIT License. Copyright © 2025 David Carteau. For the original source, see github.com/david-carteau/cerebrum.