Skip to content

Latest commit

 

History

64 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess Bot

A C# chess engine built with bitboards and accessible via a REST API.

Try it: Chess Bot


Current Features

Core Engine

  • Bitboard Board Representation
  • Magic Bitboards
  • Legal Move Generation
  • *Opening Book
  • Repetition Detection
  • Multi-threading

Search

  • Alpha-Beta Pruning
  • Transposition Tables
  • Move Ordering
  • PVS
  • Mate Search
  • Asperation Windows
  • Null Move Search
  • Itterative deeping
  • Quiescence Search

Evaluation

  • 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)

Elo Speculation

Based on current implementation, I estimate the bot to play at approximately 2000-2300 Elo. This is an informal estimate.


Usage

Prerequisites

  • .NET 10.0 SDK or later

Building & Running

  1. Clone the repository:

    git clone https://github.com/RJDonnison/ChessBot.git
    cd ChessBot
  2. Run the API server:

    dotnet run --project ChessBot.Api

    The API will start on http://localhost:5000

Configuration

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.

Testing with a UI

To test without building a custom UI, you can use the provided Chess Bot Interface.

API Endpoints

GET /bestmove

Returns the best move for a given position.

Parameters:

  • fen (required) - The board position in FEN notation
  • time (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"
}

Integration Example

// 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}");

Project Structure

  • ChessBot.Core - Core engine logic
  • ChessBot.Api - ASP.NET API wrapper
  • ChessBot.Core.Tests - Unit tests for Perft move generation tests

Future Features (Roadmap)

  • 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

License

See LICENSE for details.

Third-Party Attribution

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.

About

A C# chess engine

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages