From 76c38e8368295b89626176609b172862c1f4c402 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Mon, 14 Dec 2020 16:31:03 +0100 Subject: [PATCH] sgf save --- katrain/core/constants.py | 1 + katrain/core/game.py | 9 +++++---- katrain/core/game_node.py | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/katrain/core/constants.py b/katrain/core/constants.py index 500f050..a7d2a99 100644 --- a/katrain/core/constants.py +++ b/katrain/core/constants.py @@ -240,6 +240,7 @@ TOP_MOVE_OPTIONS = [ TOP_MOVE_VISITS, TOP_MOVE_NOTHING, ] +REPORT_DT = 0.25 SGF_INTERNAL_COMMENTS_MARKER = "\u3164\u200b" SGF_SEPARATOR_MARKER = "\u3164\u3164" diff --git a/katrain/core/game.py b/katrain/core/game.py index 3f2c788..94a79ee 100644 --- a/katrain/core/game.py +++ b/katrain/core/game.py @@ -62,8 +62,9 @@ class Game: self.insert_after = None self.region_of_interest = None - + self.external_game = False # not generated by katrain at some point if move_tree: + self.external_game = PROGRAM_NAME not in self.root.get_property("AP", "") self.root = move_tree self.komi = self.root.komi handicap = int(self.root.get_property("HA", 0)) @@ -405,8 +406,8 @@ class Game: root_properties = self.root.properties x_properties = {} - if PROGRAM_NAME in self.root.get_property("AP", ""): - for bw in "BW": + for bw in "BW": + if not self.external_game: x_properties["P" + bw] = player_name(self.katrain.players_info[bw]) + SGF_INTERNAL_COMMENTS_MARKER player_info = self.katrain.players_info[bw] if player_info.player_type == PLAYER_AI: @@ -533,7 +534,7 @@ class Game: for move in analyze_moves: if cn.analysis["moves"].get(move.gtp(), {"visits": 0})["visits"] < visits: cn.analyze( - engine, priority=priority, visits=visits, refine_move=move, time_limit=False, report_every=None + engine, priority=priority, visits=visits, refine_move=move, time_limit=False ) # explicitly requested so take as long as you need def play_to_end(self): diff --git a/katrain/core/game_node.py b/katrain/core/game_node.py index a2db1b7..148b337 100644 --- a/katrain/core/game_node.py +++ b/katrain/core/game_node.py @@ -11,6 +11,7 @@ from katrain.core.constants import ( SGF_INTERNAL_COMMENTS_MARKER, SGF_SEPARATOR_MARKER, VERSION, + REPORT_DT, ) from katrain.core.lang import i18n from katrain.core.sgf_parser import Move, SGFNode @@ -173,7 +174,7 @@ class GameNode(SGFNode): analyze_fast=False, find_alternatives=False, region_of_interest=None, - report_every=0.25, + report_every=REPORT_DT, ): additional_moves = bool(find_alternatives or region_of_interest) engine.request_analysis(