From 2664079d35eeb20dfe0d33df11f70a725796230e Mon Sep 17 00:00:00 2001 From: Sander Land Date: Fri, 1 May 2020 12:26:51 +0200 Subject: [PATCH] fix newgame --- bots/ai2gtp.py | 1 - bots/start_bot.py | 8 +++++--- game.py | 3 ++- gui/badukpan.py | 4 ++-- katrain.py | 14 ++++++++------ 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bots/ai2gtp.py b/bots/ai2gtp.py index a23c4fc..d39fb9c 100644 --- a/bots/ai2gtp.py +++ b/bots/ai2gtp.py @@ -120,4 +120,3 @@ while True: break print(f"= \n") sys.stdout.flush() - diff --git a/bots/start_bot.py b/bots/start_bot.py index fb546f8..47e33b5 100755 --- a/bots/start_bot.py +++ b/bots/start_bot.py @@ -1,7 +1,6 @@ import json import os import sys - from bots.settings import bot_strategy_names, greetings if len(sys.argv) < 2: @@ -9,7 +8,10 @@ if len(sys.argv) < 2: bot = sys.argv[1].strip() port = int(sys.argv[2]) if len(sys.argv) > 2 else 8587 + MAXGAMES = 10 +GTP2OGS = "node ../gtp2ogs" +# GTP2OGS = "gtp2ogs" BOT_SETTINGS = f" --maxconnectedgames {MAXGAMES} --noautohandicap --maxhandicap 0 --boardsizes 19" username = f"katrain-{bot}" @@ -32,11 +34,11 @@ settings_dump = ", ".join(f"{k}={v}" for k, v in ai_settings.items() if not k.st print(settings_dump) GREETING = f"Hello, welcome to an experimental version of KaTrain AIs - These are based on weakened policy nets of KataGo. Current mode is: {greetings[bot]}" if settings: - GREETING += f"Settings: {settings_dump}." + GREETING += f" Settings: {settings_dump}." BYEMSG = ( "Thank you for playing. If you have any feedback, please message my admin! Please note that score estimates in the malkovich log are based on low visits and likely inaccurate." ) -cmd = f'gtp2ogs --debug --apikey {APIKEY} --username {username} --greeting "{GREETING}" --farewell "{BYEMSG}" {BOT_SETTINGS} --aichat --noclock --nopause --speeds blitz,live --persist --minrank 25k --komis automatic,6.5,7.5 -- python bots/ai2gtp.py {bot} {port}' +cmd = f'{GTP2OGS} --debug --apikey {APIKEY} --username {username} --greeting "{GREETING}" --farewell "{BYEMSG}" {BOT_SETTINGS} --farewell_score --aichat --noclock --nopause --speeds blitz,live --persist --minrank 25k --komis automatic,6.5,7.5 -- python bots/ai2gtp.py {bot} {port}' print(f"starting bot {username} using server port {port} --> {cmd}") os.system(cmd) diff --git a/game.py b/game.py index 6b78633..dc58073 100644 --- a/game.py +++ b/game.py @@ -210,7 +210,8 @@ class Game: lo_threshold = 0.15 hi_threshold = 0.85 max_unknown = 10 - max_dame = 4*(board_size_x+board_size_y) + max_dame = 4 * (board_size_x + board_size_y) + def japanese_score_square(square, owner): player = stones.get(square, None) if (player == "B" and owner > hi_threshold) or (player == "W" and owner < -hi_threshold) or abs(owner) < lo_threshold: diff --git a/gui/badukpan.py b/gui/badukpan.py index 419930a..fd26644 100644 --- a/gui/badukpan.py +++ b/gui/badukpan.py @@ -275,11 +275,11 @@ class BadukPanWidget(Widget): passed = len(nodes) > 1 and current_node.is_pass if passed: if game_ended: - text = katrain.game.manual_score or 'game\nend' + text = katrain.game.manual_score or "game\nend" else: text = "pass" Color(0.45, 0.05, 0.45, 0.7) - center = (self.gridpos_x[int(board_size_x/2)], self.gridpos_y[int(board_size_y/2)]) + center = (self.gridpos_x[int(board_size_x / 2)], self.gridpos_y[int(board_size_y / 2)]) size = min(self.width, self.height) * 0.22 Ellipse(pos=(center[0] - size / 2, center[1] - size / 2), size=(size, size)) Color(0.85, 0.85, 0.85) diff --git a/katrain.py b/katrain.py index 8824da8..a7e9a21 100644 --- a/katrain.py +++ b/katrain.py @@ -33,6 +33,7 @@ class KaTrainGui(BoxLayout): self.debug_level = 0 self.engine = None # type: Optional[KataGoEngine] self.game = None + self.new_game_popup = None self.fileselect_popup = None self.config_popup = None self.logger = lambda message, level=OUTPUT_INFO: self.log(message, level) @@ -179,7 +180,7 @@ class KaTrainGui(BoxLayout): def _do_analyze_sgf_popup(self): if not self.fileselect_popup: - self.fileselect_popup = Popup(title="Double Click SGF file to analyze", size_hint=(0.8, 0.8)) + self.fileselect_popup = Popup(title="Double Click SGF file to analyze", size_hint=(0.8, 0.8)).__self__ popup_contents = LoadSGFPopup() self.fileselect_popup.add_widget(popup_contents) popup_contents.filesel.path = os.path.expanduser(self.config("sgf/sgf_load")) @@ -197,14 +198,15 @@ class KaTrainGui(BoxLayout): self.fileselect_popup.open() def _do_new_game_popup(self): - new_game_popup = Popup(title="New Game", size_hint=(0.5, 0.6)) - popup_contents = NewGamePopup(self, new_game_popup, {k: v[0] for k, v in self.game.root.properties.items() if len(v) == 1}) - new_game_popup.add_widget(popup_contents) - new_game_popup.open() + if not self.new_game_popup: + self.new_game_popup = Popup(title="New Game", size_hint=(0.5, 0.6)).__self__ + popup_contents = NewGamePopup(self, self.new_game_popup, {k: v[0] for k, v in self.game.root.properties.items() if len(v) == 1}) + self.new_game_popup.add_widget(popup_contents) + self.new_game_popup.open() def _do_config_popup(self): if not self.config_popup: - self.config_popup = Popup(title="Edit Settings", size_hint=(0.9, 0.9)) + self.config_popup = Popup(title="Edit Settings", size_hint=(0.9, 0.9)).__self__ popup_contents = ConfigPopup(self, self.config_popup, dict(self._config), ignore_cats=("trainer", "ai")) self.config_popup.add_widget(popup_contents) self.config_popup.open()