ChessInterface
In addition to the methods and attributes described in the overview, this object provides the methods below.
Methods
| Method | Description |
|---|---|
ChessInterface.check_move(move) |
move is a string formatted in SAN. Returns True if move is a valid move given the current game state, else False. |
ChessInterface.make_pseudo_move(state, move) |
state is a ChessGameState object and move is a string formatted in SAN. Returns the new ChessGameState that results if you played move on state. Returns None if the move is invalid. Note that on the returned state the values for ChessGameState.clocks will be -1. |
Examples
class Algo:
# ...
def take_turn(self, state: ChessGameState, interface: ChessInterface):
interface.log(state.board['a4':'h1'])
# > ------------------------
# 4 │ · · · · · · · · │
# 3 │ · · · · · · · · │
# 2 │ P P P P P P P P │
# 1 │ R N B Q K B N R │
# ------------------------
# a b c d e f g h
is_valid = interface.check_move('d4')
interface.log(is_valid)
# > True
new_state = interface.make_pseudo_move(state, 'd4')
interface.log(new_state.board['a4':'h1'])
# > ------------------------
# 4 │ · · · P · · · · │
# 3 │ · · · · · · · · │
# 2 │ P P P · P P P P │
# 1 │ R N B Q K B N R │
# ------------------------
# a b c d e f g h
# the returned state will be None if the move was invalid
new_state = interface.make_pseudo_move(state, 'a6')
interface.log(new_state)
# > None