A two players chess game library.
- ✅ Board and pieces representation
- ✅ Game and players representation
- ✅ Default game set up
- ✅ Custom game position set up
- ✅ Piece moves, made with algebraic notation (almost)
- ✅ Piece capturing
- ✅ Castling
- ✅ En passant
- ✅ Pawn promotion
- ✅ King check event
- ✅ Game ending events (checkmate / stalemate)
Creating a board :
Board board = new Board();
Getting specific tile in a board :
Board board = new Board();
Tile a1Tile = board.GetTile("a1");
or : 1
Board board = new Board();
Tile a1Tile = board.grid[0, 0];
Creating a piece :
Board board = new Board();
King whiteKing = new King(board.GetTile("a1"), Color.WHITE);
King blackKing = new King(board.GetTile("h8"), Color.BLACK);
board.AddPiece(whiteKing);
board.AddPiece(blackKing);
Creating a game with default set up :
Game game = new Game();
game.Start();
Creating a game with custom board position :
Board board = new Board();
King whiteKing = new King(board.GetTile("a1"), Color.WHITE);
King blackKing = new King(board.GetTile("h8"), Color.BLACK);
board.AddPiece(whiteKing);
board.AddPiece(blackKing);
Game game = new Game(board, Color.WHITE);
game.Start();
Handling current player move :
Game game = new Game();
game.Start();
game.HandlePlayerMove("d2", "d4");
Handling pawn promotion :
Board board = new Board();
Game game = new Game(board, Color.WHITE);
board.AddPiece(new Pawn(board.GetTile("a7"), Color.WHITE));
game.HandlePlayerMove("a7", "a8");
game.PromoteMovedPawnTo(typeof(Queen));
Other useful fields / methods :
whitePawn.legalMoves // returns piece legal moves
board.whiteKing // reference for white king
board.blackPieces // reference for black pieces
board.RemovePiece(whitePawn) // removes piece from the board
board.SetUp() // sets up board with default starting position
board.Contains(whitePawn) // returns true if board contains given piece
game.currentPlayer.king.isChecked // self explanatory
game.isOver // returns true if current player king is checkmated or is in stalemate
game.board.lastMovedPiece // last moved piece reference
game.board.LastMovedPieceIsAPawnAvailableForPromotion()
// special condition method, useful for creating custom interface for pawn promotion piece type picker
For more usage examples see tests.
- Moves history
- Board builder
- Time system
- Point system
- Proper algebraic notation system
- AI with different difficulties
- Multiplayer support
- Dedicated API docs (this is not hapenning lol)
Footnotes
-
Grid indexes are flipped, so
board.grid[7, 0]
will return tile a8,board.grid[0, 7]
will return tile h1 etc. ↩