Playing A Game#

Note

The current version of chessengine has not yet implemented all rules of chess. A few move-related bugs are also known and under development.

  • King moves -
    • Moves generated by other pieces are not checked to make sure they do not place the king in check

    • The king generates moves that move it into check

    • The king isn’t required to move itself out of check

  • Pawn promotion -
    • Pawns are not promoted when they reach the last rank

  • Stalemate -
    • The engine still asks for a move if the user is stalemated

    • If the engine is stalemated, it crashes

  • Castling -
    • Castling is accepted if the king is in check or if the king moves into check

    • Castling is accepted if the square next to the castle is being attacked

The recommended way to play a game on the console is by using the command -

$ chessengine play

You can also invoke chessengine from python by running -

$ python -m chessengine.play

Use the -p flag to play against another player instead of the computer -

$ chessengine play -p

If playing against the computer, chessengine will prompt you to pick the side you want to play - black or white. Enter “w” for white and “b” for black. The computer will parse PGN files included in the package to search for opening moves, and the game will start.

Making Moves On The Board#

You can make moves by entering the Standard Algebraic Notation (SAN) of the move as the input. SAN is the standard method of recording moves in chess games. Note that the SAN you enter must be valid and unambiguous given the current state of the chessboard.

If you are not familiar with SAN, you can also make moves by describing the start square and the end square for the move in the following format -

"<start_square> to <end_square>"

Where <start_square> and <end_square> are given as coordinates on the chessboard. For example, b1 to c3. This will move the piece on square b1 to the square c3.