From d0bca6091e747ba0677e8303180bfdc6f8d55d5a Mon Sep 17 00:00:00 2001 From: QueensGambit Date: Mon, 3 Dec 2018 18:53:51 +0100 Subject: [PATCH] added comments for can_claim_threefold_repetition --- .../src/domain/agent/player/MCTSAgent.py | 14 ++++++++++++++ .../src/preprocessing/analyze_train_data.ipynb | 16 +++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/DeepCrazyhouse/src/domain/agent/player/MCTSAgent.py b/DeepCrazyhouse/src/domain/agent/player/MCTSAgent.py index a0e698b1..63bc52da 100644 --- a/DeepCrazyhouse/src/domain/agent/player/MCTSAgent.py +++ b/DeepCrazyhouse/src/domain/agent/player/MCTSAgent.py @@ -665,11 +665,24 @@ def _run_single_playout(self, state: GameState, parent_node: Node, pipe_id=0, de return -value, depth, chosen_nodes def can_claim_threefold_repetition(self, transposition_key, chosen_nodes): + """ + Checks if a three fold repetition event can be claimed in the current search path. + This method makes use of the class transposition table and checks for board occurrences in the local search path + of the current thread as well. + + :param transposition_key: Transposition key which defines the board state by all it's pieces and pocket state. + The move counter is disregarded. + :param chosen_nodes: List of integer indices which correspond to the child node indices chosen from the + root node downwards. + :return: True, if threefold repetition can be claimed, else False + """ + # set the number of occurrences by default to 0 search_occurrence_counter = 0 node = self.root_node.child_nodes[chosen_nodes[0]] + # iterate over all accessed nodes during the current search of the thread and check for same transposition key for node_idx in chosen_nodes[1:-1]: if node.transposition_key == transposition_key: search_occurrence_counter += 1 @@ -677,6 +690,7 @@ def can_claim_threefold_repetition(self, transposition_key, chosen_nodes): if node is None: break + # use all occurrences in the class transposition table as well as the locally found equalities return self.transposition_table[transposition_key] + search_occurrence_counter >= 2 def _select_node(self, parent_node: Node): diff --git a/DeepCrazyhouse/src/preprocessing/analyze_train_data.ipynb b/DeepCrazyhouse/src/preprocessing/analyze_train_data.ipynb index a5550261..76ad8e2d 100644 --- a/DeepCrazyhouse/src/preprocessing/analyze_train_data.ipynb +++ b/DeepCrazyhouse/src/preprocessing/analyze_train_data.ipynb @@ -294,7 +294,7 @@ "metadata": {}, "outputs": [], "source": [ - "df = pd.DataFrame.from_csv('crazyara_lichess_dataset_stats.csv')" + "df = pd.DataFrame.from_csv('data/crazyara_lichess_dataset_stats.csv')" ] }, { @@ -303,7 +303,7 @@ "metadata": {}, "outputs": [], "source": [ - "df['White'].value_counts()[:10][::-1].plot('barh')" + "df_full = pd.concat([df['White'], df['Black']])" ] }, { @@ -312,16 +312,7 @@ "metadata": {}, "outputs": [], "source": [ - "df_white = df['White'].value_counts().reset_index().rename(columns={'index': 'Name', 0: 'White'})" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "df_black = df['Black'].value_counts().reset_index().rename(columns={'index': 'Name', 0: 'Black'})" + "((df_full.value_counts()[:10] / len(df)) * 100).round(2)" ] }, { @@ -378,7 +369,6 @@ "plt.suptitle(\"CrazyAra's Traing Data\\n569,537 Games total (%.2f\" % cum_perc + \"% \" + \"by %d players)\" % top_x, y=1.05, size=20)\n", "\n", "#ax = (df_full.value_counts()[:20][::-1] / len(df) * 100).plot('barh', title=\"CrazyAra's Traing Data\")\n", - "df_full = pd.concat([df['White'], df['Black']])\n", "ax = (df_full.value_counts()[:top_x][::-1]).plot('barh', title=\"\\nTop %d Active Crazyhouse-Players with Matches >= 2,000 elo for both Players\\nfrom January 2016 to June 2018 (database.lichess.org/)\" % top_x, ax=ax1)\n", "ax.set_xlabel(\"Number of Games\")\n", "#ax.set_ylabel(\"Crazyhouse Players on lichess.org\")\n",