Skip to content

GMKornilov/chessboard

Repository files navigation

Android ChessBoard

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).

Installation

  1. Add the JitPack repository to your root build.gradle at the end of repositories:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency to your module builg.gradle:
dependencies {
    implementation 'com.github.GMKornilov:chessboard:v1.0.1'
}

Usage

<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" />

XML parameters

  1. is_white (default: true) - is user playing as white or black.
  2. allow_moves (default: true) - defines if user can do any moves.
  3. allow_opponent_moves (default: true) - defines if user can do moves as the opposite player.

Provided types

  1. ChessboardView - view itself.
  2. 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

Public properties

  1. fen: String? - current board state in FEN. Getter returns current state of board. Setter sets board state and calls onFenChanged method of current listener.
  2. 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 evaluation onFenChanged and onMove of corresponding listeners are called.
  3. isWhite: Boolean - is board turned towards white or black player.
  4. allowOpponentMoves - can player also play as his opponent.

Public methods

  1. addBoardListener(listener: ChessboardView.BoardListener) - adds listener of board events.
  2. removeBoardListener(listener: ChessboardView.BoardListener) - removes listener of board events.
  3. undo() - reverts last played move, if there is any.

Some screenshots

white najdorf screenshot

black caro kann advance variation screenshot

white scholar's mate screenshot