ChessInterface
In addition to the methods and attributes described in the overview, this object provides the methods below.
Methods
| Method | Returns | Description |
|---|---|---|
ChessInterface.make_move(move) |
None |
Call this to make your move and progress the game. move is a string written in UCI, like 'e2e4'. Calling this with an invalid move or when it is not your turn will lose you the game. |
ChessInterface.make_pseudo_move(state, move) |
ChessGameState |
Call this to make a move and see the result without progressing the game. The function returns the resulting position when the given UCI move is played on the given state. |
Examples
Rendered State
{
"fen": "r1bqkbnr/pppp1ppp/2n5/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3",
"clocks": [299.9995828, 299.9995727]
}Values in Code
def on_my_turn(state):
ChessInterface.log(state.board['a4':'h1'])
# > ------------------------
# 4 │ · · · · P · · · │
# 3 │ · · · · · N · · │
# 2 │ P P P P · P P P │
# 1 │ R N B Q K B · R │
# ------------------------
# a b c d e f g h
new_state = ChessInterface.make_pseudo_move(state, 'd2d4')
ChessInterface.log(new_state.board['a4':'h1'])
# > ------------------------
# 4 │ · · · P P · · · │
# 3 │ · · · · · N · · │
# 2 │ P P P · · P P P │
# 1 │ R N B Q K B · R │
# ------------------------
# a b c d e f g h
# an invalid move raises instead of answering
try:
ChessInterface.make_pseudo_move(state, 'a2a5')
except ValueError as problem:
ChessInterface.log(problem)
# > White cannot play the move "a2a5" on "r1bqkbnr/pppp1ppp/2n5/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3": that piece cannot make it
ChessInterface.make_move('d2d4')