Skip to content

Commit

Permalink
Merge pull request #43 from kobanium/develop
Browse files Browse the repository at this point in the history
fix #41
  • Loading branch information
kobanium authored May 26, 2023
2 parents 0af929d + adebf09 commit 40a2016
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mcts/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
REMAINING_TIME = 60.0

# 探索速度のデフォルト値
VISITS_PER_SEC = 200
VISITS_PER_SEC = 20

# 投了の閾値
RESIGN_THRESHOLD = 0.05
17 changes: 15 additions & 2 deletions mcts/time_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)


Expand All @@ -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:
"""思考時間管理の設定を変更する。
Expand Down
1 change: 1 addition & 0 deletions mcts/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 40a2016

Please sign in to comment.