Small chessboard widget for Android, which gives you callbacks on game turns,checks, checkmates and stalemates. Also allows to set board positions and undo game moves.
(My attempts to recreate this package for Flutter: https://pub.dev/packages/flutter_chess_board).
- Add the JitPack repository to your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency to your module builg.gradle:
dependencies {
implementation 'com.github.GMKornilov:chessboard:v1.0.1'
}
<com.github.gmkornilov.chessboard.view.ChessboardView
android:id="@+id/chessboardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:is_white="true"
app:allow_opponent_moves="true" />
is_white (default: true)
- is user playing as white or black.allow_moves (default: true)
- defines if user can do any moves.allow_opponent_moves (default: true)
- defines if user can do moves as the opposite player.
ChessboardView
- view itself.ChessboardView.BoardListener
- listener for main board events. Contains following methods:onMove(move: String): Unit
(move
is provided as Short Algebraic Notation(SAN))onFenChanged(newFen: String): Unit
onUndo(): Unit
onCheck(isWhiteChecked: Boolean): Unit
onCheckmate(whiteLost: Boolean): Unit
onStalemate(): Unit
fen: String?
- current board state in FEN. Getter returns current state of board. Setter sets board state and callsonFenChanged
method of current listener.lastMove: String?
- last move played in current position. Getter returns SAN of the last move or null, if no move was played. Setter take move in SAN as argument and tries to evaluate given move on board. After evaluationonFenChanged
andonMove
of corresponding listeners are called.isWhite: Boolean
- is board turned towards white or black player.allowOpponentMoves
- can player also play as his opponent.
addBoardListener(listener: ChessboardView.BoardListener)
- adds listener of board events.removeBoardListener(listener: ChessboardView.BoardListener)
- removes listener of board events.undo()
- reverts last played move, if there is any.