From 460494c72c9c4efd9413d9bae6e26fff1e5ddf47 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Fri, 15 May 2020 19:12:12 +0200 Subject: [PATCH] update parent move, readme, analysis tab select --- INSTALL.md | 5 +++-- README.md | 2 +- katrain/__main__.py | 17 ++++++++++++----- katrain/core/game_node.py | 2 ++ katrain/gui/badukpan.py | 2 +- katrain/gui/controls.py | 8 +++++++- katrain/gui/kivyutils.py | 3 +-- 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 19b81c8..2e3b309 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -33,8 +33,9 @@ Kivy currently does not have a release for Python 3.8. * Open a terminal. * Run the command `git clone https://github.com/sanderland/katrain.git` to download the repository. - * Changing directory using `cd katrain`. - * Run the command `python3 setup.py install`. + * Changing directory using `cd katrain` + * Run the command `python3 setup.py install` + * If you get an error about permissions, try `python3 setup.py install --user` * A binary for KataGo is included, but if you have compiled your own, point the 'engine/katago' setting to the relevant KataGo v1.4+ binary. * Run the program by typing `katrain` in the terminal. diff --git a/README.md b/README.md index 786049d..2a9151d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# KaTrain v1.0.5 +# KaTrain v1.0.6 KaTrain is a tool for analyzing and playing go with AI feedback from KataGo. diff --git a/katrain/__main__.py b/katrain/__main__.py index eeb3edc..26801a4 100644 --- a/katrain/__main__.py +++ b/katrain/__main__.py @@ -106,11 +106,18 @@ class KaTrainGui(BoxLayout): def update_state(self, redraw_board=False): # is called after every message and on receiving analyses and config changes # AI and Trainer/auto-undo handlers cn = self.game.current_node - auto_undo = cn.player and "undo" in self.controls.player_mode(cn.player) - if auto_undo and cn.analysis_ready and cn.parent and cn.parent.analysis_ready and not cn.children and not self.game.ended: - self.game.analyze_undo(cn, self.config("trainer")) # not via message loop - if cn.analysis_ready and "ai" in self.controls.player_mode(cn.next_player).lower() and not cn.children and not self.game.ended and not (auto_undo and cn.auto_undo is None): - self._do_ai_move(cn) # cn mismatch stops this if undo fired. avoid message loop here or fires repeatedly. + if self.controls.play_analyze_mode == "play": + auto_undo = cn.player and "undo" in self.controls.player_mode(cn.player) + if auto_undo and cn.analysis_ready and cn.parent and cn.parent.analysis_ready and not cn.children and not self.game.ended: + self.game.analyze_undo(cn, self.config("trainer")) # not via message loop + if ( + cn.analysis_ready + and "ai" in self.controls.player_mode(cn.next_player).lower() + and not cn.children + and not self.game.ended + and not (auto_undo and cn.auto_undo is None) + ): + self._do_ai_move(cn) # cn mismatch stops this if undo fired. avoid message loop here or fires repeatedly. # Handle prisoners and next player display prisoners = self.game.prisoner_count diff --git a/katrain/core/game_node.py b/katrain/core/game_node.py index c046134..991c0da 100644 --- a/katrain/core/game_node.py +++ b/katrain/core/game_node.py @@ -82,6 +82,8 @@ class GameNode(SGFNode): self.ownership = analysis_json.get("ownership") self.policy = analysis_json.get("policy") self.analysis["root"] = analysis_json["rootInfo"] + if self.parent and self.move: + self.parent.update_move_analysis(analysis_json["rootInfo"], self.move.gtp()) # update analysis in parent for consistency @property def analysis_ready(self): diff --git a/katrain/gui/badukpan.py b/katrain/gui/badukpan.py index b4e81b7..244b37b 100644 --- a/katrain/gui/badukpan.py +++ b/katrain/gui/badukpan.py @@ -311,7 +311,7 @@ class BadukPanWidget(Widget): else: evalcol = copy.copy(self.eval_color(points_lost)) evalcol[3] = alpha - if teaching and child_node.auto_undo and child_node.analysis_ready: + if ((teaching and child_node.auto_undo) or katrain.controls.play_analyze_mode == "analyze") and child_node.analysis_ready: self.active_pv_moves.append((move.coords, child_node.candidate_moves[0]["pv"], child_node)) scale = self.ui_config["child_scale"] self.draw_stone(move.coords[0], move.coords[1], (*stone_color[move.player][:3], alpha), None, None, evalcol, evalscale=scale, scale=scale) diff --git a/katrain/gui/controls.py b/katrain/gui/controls.py index 25e2711..4151617 100644 --- a/katrain/gui/controls.py +++ b/katrain/gui/controls.py @@ -25,8 +25,14 @@ class Controls(BoxLayout): else: self.play_tab_button.trigger_action(duration=0) - def switch_mode(self): + @property + def play_analyze_mode(self): if self.play_tab_button.state == "down": + return "play" + return "analyze" + + def switch_mode(self): + if self.play_analyze_mode == "play": self.select_mode("analyze") else: self.select_mode("play") diff --git a/katrain/gui/kivyutils.py b/katrain/gui/kivyutils.py index 6df9686..85286d8 100644 --- a/katrain/gui/kivyutils.py +++ b/katrain/gui/kivyutils.py @@ -111,7 +111,7 @@ class StyledSpinner(Spinner): def __init__(self, **kwargs): super().__init__(**kwargs) - self.fbind("size", lambda s,dt: Clock.schedule_once(self._update_dropdown_size_frac,0) ) + self.fbind("size", lambda s, dt: Clock.schedule_once(self._update_dropdown_size_frac, 0)) def _update_dropdown_size_frac(self, *largs): if not self.sync_height_frac: @@ -129,7 +129,6 @@ class StyledSpinner(Spinner): item.font_size = fsz - class ToggleButtonContainer(GridLayout): __events__ = ("on_selection",)