Skip to content

marhoily/ChessKitFs

Repository files navigation

Chess Kit (F#)

Build status ChessKit.ChessLogic ChessKit.ChessLogic

Disclaimers

  1. API is very unstable at the moment! Wait for the version 1.0 before you depend on the library
  2. Zobrist is not in the code yet. I'm playing with the API at the moment.

What it is

Chess Kit includes:

  • Immutable Board representation
  • Parsing moves in algebraic notation (SAN)
  • Detect position properties: check, mate, stalemate, draw by repetition, 50 moves rule, insufficient material.
// Fool's Mate
var position = Board.StartingPosition
    .MakeMove("f3")
    .MakeMove("e5")
    .MakeMove("g4")
    .MakeMove("Qh4#");
Console.WriteLine(position.Dump());
Console.WriteLine(position.Properties);
prints out:
 ╔═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╗
8║ r │ n │ b │   │ k │ b │ n │ r ║
 ╟───┼───┼───┼───┼───┼───┼───┼───╢
7║ p │ p │ p │ p │   │ p │ p │ p ║
 ╟───┼───┼───┼───┼───┼───┼───┼───╢
6║   │   │   │   │   │   │   │   ║
 ╟───┼───┼───┼───┼───┼───┼───┼───╢
5║   │   │   │   │ p │   │   │   ║
 ╟───┼───┼───┼───┼───┼───┼───┼───╢
4║   │   │   │   │   │   │ P │ q ║
 ╟───┼───┼───┼───┼───┼───┼───┼───╢
3║   │   │   │   │   │ P │   │   ║
 ╟───┼───┼───┼───┼───┼───┼───┼───╢
2║ P │ P │ P │ P │ P │   │   │ P ║
 ╟───┼───┼───┼───┼───┼───┼───┼───╢
1║ R │ N │ B │ Q │ K │ B │ N │ R ║
 ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝
   A   B   C   D   E   F   G   H

Mate
var move = Move.Parse("b7-b8=Q");
var legalMove = Fen
    .Parse("8/1P6/8/8/8/8/8/8 w - - 0 1")
    .ValidateLegalMove(move);
var nextPosition = legalMove.ToPosition();
Console.WriteLine(Fen.Print(nextPosition));
prints out:
1Q6/8/8/8/8/8/8/8 b - - 0 1
  • Apply the moves to the board and not only get a new board, but also all possible info about that move, like why it is illegal
  • Get all legal moves for a piece. This is not based on trying to apply moves from all squares to all squaresn, but a dedicated algorithm
  • Print the board nicely as text ;)

What it is not

  • it is not a chess engine
  • it's not nearly optimal enough to enable you to write a chess engine on top of it
  • it is not chess games database

What it might also be

Versions after 1 can include:

Known issues

  • you have to set up in your app.config manually

About

Chess related algorithms and data structures

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published