Skip to content

Commit

Permalink
added comments for can_claim_threefold_repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
QueensGambit committed Dec 3, 2018
1 parent a33c53e commit d0bca60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
14 changes: 14 additions & 0 deletions DeepCrazyhouse/src/domain/agent/player/MCTSAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,18 +665,32 @@ 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
node = node.child_nodes[node_idx]
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):
Expand Down
16 changes: 3 additions & 13 deletions DeepCrazyhouse/src/preprocessing/analyze_train_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
]
},
{
Expand All @@ -303,7 +303,7 @@
"metadata": {},
"outputs": [],
"source": [
"df['White'].value_counts()[:10][::-1].plot('barh')"
"df_full = pd.concat([df['White'], df['Black']])"
]
},
{
Expand All @@ -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)"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit d0bca60

Please sign in to comment.