Skip to content

Commit

Permalink
ノードを再利用する
Browse files Browse the repository at this point in the history
  • Loading branch information
TadaoYamaoka committed Apr 13, 2019
1 parent b7f3787 commit 2f1d2a6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions dlshogi_zero/agent/selfplay_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def __init__(self, grp, id):
self.grp = grp
self.id = id

self.current_root_node = None
self.playouts = 0
self.board = Board()
self.moves = []
Expand Down Expand Up @@ -269,7 +270,8 @@ def playout(self, trajectories):
# 手番開始
if self.playouts == 0:
# ルートノード展開
self.current_root_node = self.expand_node()
if self.current_root_node is None:
self.current_root_node = self.expand_node()

current_node = self.current_root_node

Expand Down Expand Up @@ -300,9 +302,9 @@ def playout(self, trajectories):
continue

# ルート局面をキューに追加
self.grp.queuing_node(self.board, self.moves, self.repetitions, current_node)

return
if not self.current_root_node.evaled:
self.grp.queuing_node(self.board, self.moves, self.repetitions, current_node)
return

# プレイアウト
result = self.uct_search(self.current_root_node, 0, trajectories)
Expand Down Expand Up @@ -375,6 +377,11 @@ def next_step(self):
self.next_game(game_result)
return

# ノードを再利用する
self.current_root_node = current_root_node.child_nodes[select_index]
self.current_root_node.child_move_count.fill(0)
self.current_root_node.child_win.fill(0)

# 次の手番
self.playouts = 0

Expand Down Expand Up @@ -402,6 +409,7 @@ def next_game(self, game_result):
stopflg = True

# 新しいゲーム
self.current_root_node = None
self.playouts = 0
self.board.reset()
self.chunk.clear()
Expand Down

0 comments on commit 2f1d2a6

Please sign in to comment.