5from datetime
import datetime
6from typing
import Dict, List
8import xiangqi_bindings
as bindings
20 Runs a game between two Players.
22 Tracks Game state, collects proposed moves, alternates Player turns,
23 maintains on gong GameSummary, and sends info to terminal.
27 players: Dict[bindings.PieceColor, Player],
28 game_board: bindings.GameBoard,
29 status_reporter: MoveReporter = msg.TerminalStatusReporter(),
30 move_log: List[bindings.Move] =
None,
41 char
for char
in str(datetime.now())
if char.isdigit()
51 cdm.ExecutedMove.from_core_executed_move(
52 core_executed_move=item
57 kRed=self.
_players[bindings.PieceColor.kRed].summary,
58 kBlk=self.
_players[bindings.PieceColor.kBlk].summary,
70 def is_valid_move(proposed_move: bindings.Move, avail_moves: List[bindings.Move]):
71 return proposed_move
in avail_moves
77 self.
_board, cur_moves=avail_moves
79 if avail_moves.ContainsMove(proposed_move):
80 valid_move = proposed_move
83 illegal_move=proposed_move,
85 cur_moves=avail_moves,
91 Selects and executes a move.
93 @param avail_moves: a bindings.MoveCollection of legal moves
98 handle_interactive_eof()
99 executed_move = self.
_board.ExecuteMove(valid_move)
106 if color == bindings.PieceColor.kRed:
117 red_player_summary=self.
_players[bindings.PieceColor.kRed].summary,
118 black_player_summary=self.
_players[bindings.PieceColor.kBlk].summary,
131 if avail_moves.size() == 0:
Runs a game between two Players.
def set_game_state(self, GameState game_state)
def send_game_info_to_status_reporter(self)
def __init__(self, Dict[bindings.PieceColor, Player] players, bindings.GameBoard game_board, MoveReporter status_reporter=msg.TerminalStatusReporter(), List[bindings.Move] move_log=None)
def is_valid_move(bindings.Move proposed_move, List[bindings.Move] avail_moves)
def get_valid_move(self, bindings.MoveCollection avail_moves)
GameSummary summary(self)
def player_turn(self, bindings.MoveCollection avail_moves)
Selects and executes a move.
def set_winner(self, int color)
def change_whose_turn(self)
Holds summary info of a xiangqipy.game.Game; implements msgspec.Struct for json IO.
A data container for holding one PlayerSummary for each player in a Game.
Contains classes that mirror the structure of some core C++ classes, primarily to facilitate easy IO ...
Enums that are only used on the Python side of the app.
Python abstract classes used by a Game.
GameSummary class and its component classes.
Handles case where ScriptedPlayer has no moves remaining in list but Game is not finished.
Classes for terminal UI output including board representation and, messages requesting info,...