Kotlin multiplatform chess backend
implementation("com.krossovochkin.chesskt:chesskt:x.x.x")Main class that holds all the game state is Game.
Create it with Game#create method providing optional FEN of the starting position.
If no FEN is provided then initial position will be used.
val game = Game.create()To make a move one should call Game#move with instance of the Move class.
For easier usage one can use extension String#asMove that parses usual PGN notation move and generates corresponding instance of Move class.
Calling Game#move will return true if move was successful or false otherwise.
val isSuccess = game.move("Nbxd2".asMove())To get piece on the particular square of the board one should call Game#getPiece providing square to check.
For easier usage one can use extension String#asSquare that generates corresponding instance of Square from file-rank string.
Calling Game#getPiece will return piece if it is on the given square or null otherwise.
val piece = game.getPiece("e4".asSquare())To get available moves call Game#availableMoves providing optional starting square.
List of available moves will be returned. If there are no moves empty list will be returned.
val availableMoves = game.availableMoves("d4".asSquare())To get notified on game end set up callback via Game#setGameResultCallback.
When game ends callback will be triggered with type of ending.
game.setGameResultCallback { result ->
if (result is GameResult.Draw) {
// do sth
}
}Repository contains test compose multiplatform app for demo and testing purposes.
There is no any chess moves engine there.
The test app is simple, is not intended for production use and is not designed to have a lot of features.
Web version can be found here
Copyright © Vasya Drobushkov
License Apache 2.0

