Skip to content

cameron-cunningham-ix/SharpKnight

Repository files navigation

SharpKnight

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.

Prerequisites

Building

Build the entire solution

dotnet build SharpKnight.sln

Build in Release mode

dotnet build SharpKnight.sln -c Release

Build the Longsword engine executable

To compile the Longsword engine into a standalone executable:

dotnet publish SharpKnight.Longsword -c Release

The compiled engine will be available in SharpKnight.Longsword/bin/Release/net9.0/publish/ and can be used with any UCI-compatible chess GUI.

Run tests

dotnet test SharpKnight.Tests

Projects

  • 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

Using the Library

The SharpKnight library provides core classes for building chess engines:

Core Classes

  • ChessBoard - Bitboard-based chess board representation with move generation, FEN parsing, and position evaluation
  • ChessEngineBase - Abstract base class for implementing chess engines with search, time management, and UCI option handling
  • IChessEngine - Interface defining the UCI protocol requirements for chess engines
  • UciHandler - UCI protocol handler for communication with chess GUIs
  • EnginePlayer - Wrapper that connects a chess engine to the UCI handler
  • ChessClock - Time control management for chess games
  • Moves - Move generation and validation utilities
  • Zobrist - Zobrist hashing for position identification and transposition tables

Developing Your Own Engine

To create a custom chess engine using the SharpKnight library:

  1. Create a class that inherits from ChessEngineBase
  2. Implement the required abstract methods:
    • FindBestMove() - Your search algorithm
    • EvaluatePosition() - Your position evaluation function
  3. Wrap your engine in an EnginePlayer and connect it to UciHandler.UciLoop()

For detailed instructions and examples, see HOWTO.md.

About

C# Chess engine library w/ minimal external dependencies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages