A chess engine library written in C# (.NET 9.0) that implements the Universal Chess Interface (UCI) protocol. Included are several example chess engines, including the engine I develop called Longsword.
dotnet build SharpKnight.slndotnet build SharpKnight.sln -c ReleaseTo compile the Longsword engine into a standalone executable:
dotnet publish SharpKnight.Longsword -c ReleaseThe compiled engine will be available in SharpKnight.Longsword/bin/Release/net9.0/publish/ and can be used with any UCI-compatible chess GUI.
dotnet test SharpKnight.Tests- SharpKnight - Core chess engine framework and library
- SharpKnight.Longsword - UCI-compatible chess engine executable
- SharpKnight.Material - Material evaluation engine
- SharpKnight.Random - Random move engine
- SharpKnight.Tests - Unit tests
The SharpKnight library provides core classes for building chess engines:
ChessBoard- Bitboard-based chess board representation with move generation, FEN parsing, and position evaluationChessEngineBase- Abstract base class for implementing chess engines with search, time management, and UCI option handlingIChessEngine- Interface defining the UCI protocol requirements for chess enginesUciHandler- UCI protocol handler for communication with chess GUIsEnginePlayer- Wrapper that connects a chess engine to the UCI handlerChessClock- Time control management for chess gamesMoves- Move generation and validation utilitiesZobrist- Zobrist hashing for position identification and transposition tables
To create a custom chess engine using the SharpKnight library:
- Create a class that inherits from
ChessEngineBase - Implement the required abstract methods:
FindBestMove()- Your search algorithmEvaluatePosition()- Your position evaluation function
- Wrap your engine in an
EnginePlayerand connect it toUciHandler.UciLoop()
For detailed instructions and examples, see HOWTO.md.