2Contains the GameSummaryPlotManager class.
5from pathlib
import Path
7import matplotlib.pyplot
as plt
9from matplotlib.gridspec
import GridSpec
10import xiangqi_bindings
as bindings
15 SearchResultsByTypePlotter,
23 Manages the layout and file output of a figure containing multiple
24 plots of data
from a GameSummary.
26 def __init__(self, game_summary: GameSummary, save_fig: bool =
False):
30 self.
fig = plt.figure(figsize=(12, 19), dpi=150)
44 height_ratios=[0.89, 1, 1, 0.7, 1, 1, 0.55, 1],
51 ).has_search_summaries
63 for gs_row
in range(1, 3):
67 self.
gs[gs_row, gs_col],
71 for gs_row
in range(4, 6):
75 self.
gs[gs_row, gs_col],
79 for gs_row
in range(7, 8):
83 self.
gs[gs_row, gs_col],
99 s=f
"Summary plots for Game ID # {self.game_summary.game_id}",
106 s=f
"RED player type: {self.game_summary.get_player_summary(bindings.PieceColor.kRed).player_type}\n"
107 f
"RED max search depth: {self.game_summary.get_player_summary(bindings.PieceColor.kRed).max_search_depth}\n"
108 f
"RED Zobrist key size: {self.game_summary.get_player_summary(bindings.PieceColor.kRed).zobrist_key_size} bits\n\n"
109 f
"BLACK player type: {self.game_summary.get_player_summary(bindings.PieceColor.kBlk).player_type}\n"
110 f
"BLACK max search depth: {self.game_summary.get_player_summary(bindings.PieceColor.kBlk).max_search_depth}\n"
111 f
"BLACK Zobrist key size: {self.game_summary.get_player_summary(bindings.PieceColor.kBlk).zobrist_key_size} bits\n\n"
112 f
"Result = {self.game_summary.game_state.name}",
120 transform=self.
fig.transFigure,
128 s=
"Minimax Node Counts by Search Result Type",
136 transform=self.
fig.transFigure,
144 s=
"Move Selection Time",
152 transform=self.
fig.transFigure,
160 s=
"Minimax Evaulation Scores",
166 raise FileExistsError(f
"{path} already exists")
167 path.parent.mkdir(parents=
True, exist_ok=
True)
168 plt.savefig(str(path), dpi=self.
fig.dpi)
169 print(f
"Plots of summary data saved to:\n{str(path.resolve())}")
173 show_plot: bool =
True
178 player=bindings.PieceColor.kRed
179 ).first_searches_by_type,
181 player=bindings.PieceColor.kBlk
182 ).first_searches_by_type,
184 search_results_by_type_plotter.plot()
189 player=bindings.PieceColor.kRed
190 ).first_search_stats,
192 player=bindings.PieceColor.kBlk
193 ).first_search_stats,
195 search_time_plotter.plot()
200 player=bindings.PieceColor.kRed
201 ).first_search_stats,
203 player=bindings.PieceColor.kBlk
204 ).first_search_stats,
205 add_plot_column_titles=
False,
207 eval_score_plotter.plot()
213if __name__ ==
"__main__":
215 my_game_summary_path = (
216 Path(__file__).parent.parent.parent
219 /
"20241108172951135840-test"
220 /
"20241108172951135840.json"
223 my_game_summary = import_game_summary(path=my_game_summary_path)
225 plot_manager.plot(show_plot=
True)
Manages the layout and file output of a figure containing multiple plots of data from a GameSummary.
bool has_minimax_data(self, bindings.PieceColor player)
int num_players_with_minimax_data(self)
def plot(self, bool show_plot=True)
def __init__(self, GameSummary game_summary, bool save_fig=False)
def save_figure(self, Path path)
Implements GameSummaryPlotter, and plots evaluated score of each move of each Player using a Minimax ...
Implements GameSummaryPlotter, and produces stacked plots of Minimax search result counts grouped by ...
Implements GameSummaryPlotter, and produces plots showing time spent by core MinimaxMoveEvaluator(s) ...
Contains functions for importing / exporting a GameSummary from / to .json file.
Contains the GameSummaryPlotter abstract base class, and multiple subclasses that implement it.
GameSummary class and its component classes.