Download src/game_state.py from algorembrant/CheckerChesser: direct link, hf CLI and curl.
- Browser
- Download file 707 Bytes
-
https://huggingface.co/algorembrant/CheckerChesser/resolve/main/src/game_state.py
- Command line
-
hf download hf://algorembrant/CheckerChesser/src/game_state.py
-
curl -L -o game_state.py https://huggingface.co/algorembrant/CheckerChesser/resolve/main/src/game_state.py
707 Bytes
| import chess | |
| class GameState: | |
| def __init__(self): | |
| self.board = chess.Board() | |
| def reset(self): | |
| self.board.reset() | |
| def make_move(self, uci_move): | |
| try: | |
| move = chess.Move.from_uci(uci_move) | |
| if move in self.board.legal_moves: | |
| self.board.push(move) | |
| return True | |
| return False | |
| except: | |
| return False | |
| def set_piece(self, square, piece): | |
| """Set a piece on the board directly.""" | |
| self.board.set_piece_at(square, piece) | |
| def get_fen(self): | |
| return self.board.fen() | |
| def is_game_over(self): | |
| return self.board.is_game_over() | |