diff --git a/core/common.py b/core/common.py index 7427759..b667dde 100644 --- a/core/common.py +++ b/core/common.py @@ -1,6 +1,7 @@ from typing import Any, List, Tuple OUTPUT_ERROR = -1 +OUTPUT_KATAGO_STDERR = -0.5 OUTPUT_INFO = 0 OUTPUT_DEBUG = 1 OUTPUT_EXTRA_DEBUG = 2 diff --git a/core/engine.py b/core/engine.py index 4579f77..28364e7 100644 --- a/core/engine.py +++ b/core/engine.py @@ -6,7 +6,7 @@ import threading import time from typing import Callable, Optional -from core.common import OUTPUT_DEBUG, OUTPUT_ERROR, OUTPUT_EXTRA_DEBUG +from core.common import OUTPUT_DEBUG, OUTPUT_ERROR, OUTPUT_EXTRA_DEBUG, OUTPUT_KATAGO_STDERR from core.game_node import GameNode @@ -38,11 +38,12 @@ class KataGoEngine: self._lock = threading.Lock() self.start() self.analysis_thread = threading.Thread(target=self._analysis_read_thread, daemon=True).start() + self.stderr_thread = threading.Thread(target=self._read_stderr_thread, daemon=True).start() def start(self): try: self.katrain.log(f"Starting KataGo with {self.command}", OUTPUT_DEBUG) - self.katago_process = subprocess.Popen(self.command, stdin=subprocess.PIPE, stdout=subprocess.PIPE) + self.katago_process = subprocess.Popen(self.command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except FileNotFoundError as e: self.katrain.log( f"Starting kata with command '{self.command}' failed with error {e}. Please make sure the 'katago' value under 'engine' in settings points to the correct KataGo executable.", @@ -70,6 +71,15 @@ class KataGoEngine: def is_idle(self): return not self.queries + def _read_stderr_thread(self): + while self.katago_process is not None: + try: + line = self.katago_process.stderr.readline() + if line: + self.katrain.log(line.decode(), OUTPUT_KATAGO_STDERR) + except: + return + def _analysis_read_thread(self): while self.katago_process is not None: try: diff --git a/core/sgf_parser.py b/core/sgf_parser.py index 9e1a994..66c54b8 100644 --- a/core/sgf_parser.py +++ b/core/sgf_parser.py @@ -28,7 +28,7 @@ class Move: """Initialize a move from SGF coordinates and player""" if sgf_coords == "" or Move.SGF_COORD.index(sgf_coords[0]) == board_size[0]: # some servers use [tt] for pass return cls(coords=None, player=player) - return cls(coords=(Move.SGF_COORD.index(sgf_coords[0]), board_size[1] - Move.SGF_COORD.index(sgf_coords[1]) - 1), player=player,) + return cls(coords=(Move.SGF_COORD.index(sgf_coords[0]), board_size[1] - Move.SGF_COORD.index(sgf_coords[1]) - 1), player=player) def __init__(self, coords: Optional[Tuple[int, int]] = None, player: str = "B"): """Initialize a move from zero-based coordinates and player""" diff --git a/gui/badukpan.py b/gui/badukpan.py index 7957e86..29021d4 100644 --- a/gui/badukpan.py +++ b/gui/badukpan.py @@ -85,7 +85,7 @@ class BadukPanWidget(Widget): if nodes_here and max(yd, xd) < self.grid_size / 2: # load old comment if touch.is_double_tap: # navigate to move katrain.game.set_current_node(nodes_here[-1]) - self.draw_board_contents() + katrain.update_state() else: # load comments katrain.log(f"\nAnalysis:\n{nodes_here[-1].analysis}", OUTPUT_DEBUG) katrain.log(f"\nParent Analysis:\n{nodes_here[-1].parent.analysis}", OUTPUT_DEBUG) diff --git a/katrain.py b/katrain.py index 3414af7..4ef54ae 100644 --- a/katrain.py +++ b/katrain.py @@ -17,7 +17,7 @@ from kivy.storage.jsonstore import JsonStore from kivy.uix.popup import Popup from core.ai import ai_move -from core.common import OUTPUT_INFO, OUTPUT_ERROR, OUTPUT_DEBUG, OUTPUT_EXTRA_DEBUG +from core.common import OUTPUT_INFO, OUTPUT_ERROR, OUTPUT_DEBUG, OUTPUT_EXTRA_DEBUG, OUTPUT_KATAGO_STDERR from core.engine import KataGoEngine from core.game import Game, IllegalMoveException, KaTrainSGF from core.sgf_parser import Move, ParseError @@ -47,7 +47,15 @@ class KaTrainGui(BoxLayout): self._keyboard.bind(on_key_down=self._on_keyboard_down) def log(self, message, level=OUTPUT_INFO): - if level == OUTPUT_ERROR: + if level == OUTPUT_KATAGO_STDERR: + if "starting" in message.lower(): + self.controls.set_status(f"KataGo engine starting...") + if message.startswith("Tuning"): + self.controls.set_status(f"KataGo is tuning settings for first startup, please wait." + message) + if "ready" in message.lower(): + self.controls.set_status(f"KataGo engine ready.") + print(f"[KG:STDERR]{message}") + elif level == OUTPUT_ERROR: self.controls.set_status(f"ERROR: {message}") print(f"ERROR: {message}") elif self.debug_level >= level: