2Classes for terminal UI output including board representation and, messages
3requesting info, and status messages.
9from dataclasses
import dataclass
10from typing
import Dict
13from xiangqi_bindings
import (
29 Provides messages requesting input from a Player.
31 input_prompt: str = "Enter a move in the form 'from_space, to_space': "
32 invalid_input_msg: str =
"Invalid input"
33 illegal_move_msg: str =
"Illegal move. Please enter a different move."
44 Outputs a text-base game board with GamePiece locations
in algebraic
49 PieceColor.kRed: cr.Style.BRIGHT + cr.Fore.WHITE + cr.Back.RED,
50 PieceColor.kBlk: cr.Style.BRIGHT + cr.Fore.BLACK + cr.Back.WHITE,
51 PieceColor.kNul: cr.Fore.RESET + cr.Back.RESET,
54 _display_team_name = {PieceColor.kRed: "Red", PieceColor.kBlk:
"Black"}
75 _ = subprocess.call(
"clear" if os.name ==
"posix" else "cls")
79 f
"{self._disp_format[piece.piece_color]}"
80 f
"{self._type_to_code[piece.piece_type]}"
81 f
"{self._color_to_code[piece.piece_color]}"
82 f
"{cr.Style.RESET_ALL}"
87 f
" {chr(char_num)} " for char_num
in range(ord(
"a"), ord(
"j"))
89 file_labels.insert(0,
"\t")
90 file_labels.insert(len(file_labels),
"\n")
94 f
" {self.encode_piece(board.map()[row][col])} "
95 for col
in range(len(board.map()[0]))
97 for row
in range(len(board.map()))
99 for row_index
in range(len(board_list)):
100 board_list[row_index].insert(0, f
" {str(10 - row_index)}\t")
101 board_list.insert(0, file_labels)
102 board_list = [
"".join(row)
for row
in board_list]
104 return str(
"\n\n".join([str(rank)
for rank
in board_list]))
108 player_summary: PlayerSummary,
111 "Minimax": f
"Minimax, max search depth = "
112 f
"{player_summary.max_search_depth}, zobrist hash key size = "
113 f
"{player_summary.zobrist_key_size} bits",
117 return display_dispatch
121 player_type_string = f
"Player Type = {player_summary.player_type.name}"
122 move_evaluator_string = (
123 f
", Move Evaluator = {player_summary.move_evaluator_type.name}"
124 if player_summary.move_evaluator_type != EvaluatorType.NULL
127 search_depth_string = (
128 f
", Max Search Depth = {player_summary.max_search_depth}"
129 if player_summary.max_search_depth
133 zobrist_key_size_string = (
134 f
", Zobrist Key Size = {player_summary.zobrist_key_size}"
135 if player_summary.zobrist_key_size
140 f
"\n{self._display_team_name[player_summary.color]} Player:\n"
141 f
"{player_type_string}{move_evaluator_string}{search_depth_string}{zobrist_key_size_string}"
147 f
"Most recent move:\n"
148 f
"{mt.convert_move_to_input_str(prev_move)} "
149 f
"({self._display_team_name[color]})\n"
152 print(
"Most recent move:\n" "NA... No moves executed yet.\n")
155 print(f
"Whose turn:\n{self._display_team_name[color]}\n")
159 print(f
"{self._display_team_name[color]} is in check.")
164 f
"{mt.convert_move_to_input_str(final_move)} "
165 f
"({self._display_team_name[color]})\n"
170 if game_state == GameState.RED_WON:
171 print(
"Red won the game.")
172 if game_state == GameState.BLACK_WON:
173 print(
"Black won the game.")
174 if game_state == GameState.DRAW:
175 print(
"Game ended in a draw.")
179 red_player_summary: PlayerSummary,
180 black_player_summary: PlayerSummary,
181 game_state: GameState,
182 game_board: GameBoard,
183 whose_turn: PieceColor,
186 prev_move: Move =
None,
189 print(f
"{self.format_board_output(game_board)}\n")
192 print(f
"\nMove count: {move_count}\n")
194 if game_state == GameState.UNFINISHED:
196 color=opponent_of(whose_turn), prev_move=prev_move
200 color=whose_turn, is_in_check=is_in_check
205 color=opponent_of(whose_turn), final_move=prev_move
Reports details of a Game.
Outputs a text-base game board with GamePiece locations in algebraic notation.
def display_if_is_in_check(self, PieceColor color, bool is_in_check)
def format_board_output(self, GameBoard board)
def display_winner(GameState game_state)
def display_final_move(self, PieceColor color, Move final_move)
def display_whose_turn(self, PieceColor color)
def report_game_info(self, PlayerSummary red_player_summary, PlayerSummary black_player_summary, GameState game_state, GameBoard game_board, PieceColor whose_turn, bool is_in_check, int move_count, Move prev_move=None)
def encode_piece(self, GamePiece piece)
Dict[str, str] move_evaluator_translator(PlayerSummary player_summary)
def display_prev_move(self, PieceColor color, Move prev_move=None)
def display_player_info(self, PlayerSummary player_summary)
Enums that are only used on the Python side of the app.
Python abstract classes used by a Game.
Contains functions used to convert algebraic board notation into integer indices array notation.
Contains PlayerSummary class.