From 3abba26c9d74b421f12ea56021b21b57f383446b Mon Sep 17 00:00:00 2001 From: Yuki Kobayashi Date: Fri, 26 May 2023 21:15:53 +0900 Subject: [PATCH] fix #41 --- mcts/constant.py | 2 +- mcts/time_manager.py | 17 +++++++++++++++-- mcts/tree.py | 1 + program.py | 3 ++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mcts/constant.py b/mcts/constant.py index 2e30336..dae65e0 100644 --- a/mcts/constant.py +++ b/mcts/constant.py @@ -32,7 +32,7 @@ REMAINING_TIME = 60.0 # 探索速度のデフォルト値 -VISITS_PER_SEC = 200 +VISITS_PER_SEC = 20 # 投了の閾値 RESIGN_THRESHOLD = 0.05 diff --git a/mcts/time_manager.py b/mcts/time_manager.py index c876d01..c0b7604 100644 --- a/mcts/time_manager.py +++ b/mcts/time_manager.py @@ -32,7 +32,7 @@ def __init__(self, mode: TimeControl, constant_visits: int=CONST_VISITS, constan self.constant_visits = constant_visits self.constant_time = constant_time self.default_time = remaining_time - self.search_speed = 200 + self.search_speed = VISITS_PER_SEC self.remaining_time = [remaining_time] * 2 @@ -68,7 +68,7 @@ def get_num_visits_threshold(self, color: Stone) -> int: if self.mode == TimeControl.TIME_CONTROL: remaining_time = self.remaining_time[0] \ if color is Stone.BLACK else self.remaining_time[1] - return int(self.search_speed * remaining_time / 8.0) + return int(self.search_speed * remaining_time / 10.0) return int(self.constant_visits) @@ -85,6 +85,19 @@ def set_remaining_time(self, color: Stone, time: float) -> NoReturn: self.remaining_time[1] = time + def substract_consumption_time(self, color: Stone, time: float): + """消費した時間を持ち時間から引く。 + + Args: + color (Stone): 思考した手番の色。 + time (float): 消費した時間。 + """ + if color is Stone.BLACK: + self.remaining_time[0] -= time + if color is Stone.WHITE: + self.remaining_time[1] -= time + + def set_mode(self, mode:TimeControl) -> NoReturn: """思考時間管理の設定を変更する。 diff --git a/mcts/tree.py b/mcts/tree.py index 009bbce..cbabb98 100644 --- a/mcts/tree.py +++ b/mcts/tree.py @@ -83,6 +83,7 @@ def search_best_move(self, board: GoBoard, color: Stone, time_manager: TimeManag po_per_sec = root.node_visits / search_time time_manager.set_search_speed(root.node_visits, search_time) + time_manager.substract_consumption_time(color, search_time) print_err(f"{search_time:.2f} seconds, {po_per_sec:.2f} visits/sec") diff --git a/program.py b/program.py index b80a3a9..a0fcf97 100644 --- a/program.py +++ b/program.py @@ -18,4 +18,5 @@ # Version 0.6.1 : --batch-sizeオプションの追加。 # Version 0.6.2 : 2回連続パスした時にノードを展開しないように変更。 # Version 0.6.3 : 探索回数を増やした時に強くならないバグの修正。time_leftコマンドのバグ修正。 -VERSION="0.6.3" +# Version 0.6.4 : time_leftコマンドが来ないと持ち時間を正しく消費しないバグの修正。 +VERSION="0.6.4"