From 778b6db1ccb6c8a433c2b36b303f6b64e3b779fa Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sat, 2 May 2020 15:42:39 +0200 Subject: [PATCH] order children --- core/game_node.py | 4 ++++ core/sgf_parser.py | 9 +++++++-- katrain.py | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/game_node.py b/core/game_node.py index 2a8fed5..9ee21b7 100644 --- a/core/game_node.py +++ b/core/game_node.py @@ -44,6 +44,10 @@ class GameNode(SGFNode): ] return properties + @staticmethod + def order_children(children): + return sorted(children, key=lambda c: 0.5 if c.auto_undo is None else int(c.auto_undo)) # analyzed/not undone main, non-teach second, undone last + # various analysis functions def analyze(self, engine, priority=0, visits=None, time_limit=True, refine_move=None, analyze_fast=False): engine.request_analysis( diff --git a/core/sgf_parser.py b/core/sgf_parser.py index a5cc965..7254e99 100644 --- a/core/sgf_parser.py +++ b/core/sgf_parser.py @@ -69,9 +69,14 @@ class SGFNode: self.set_property(move.player, move.sgf(self.board_size)) def sgf_properties(self, **xargs) -> Dict: - """For hooking into in a subclass and overriding/formatting any additional properties to be output""" + """For hooking into in a subclass and overriding/formatting any additional properties to be output.""" return copy.deepcopy(self.properties) + @staticmethod + def order_children(children): + """For hooking into in a subclass and overriding branch order.""" + return children + def sgf(self, **xargs) -> str: """Generates an SGF, calling sgf_properties on each node with the given xargs, so it can filter relevant properties if needed.""" import sys @@ -80,7 +85,7 @@ class SGFNode: sys.setrecursionlimit(max(sys.getrecursionlimit(), 3 * bszx * bszy)) # thanks to lightvector for causing stack overflows ;) sgf_str = "".join([prop + "".join(f"[{v}]" for v in values) for prop, values in self.sgf_properties(**xargs).items() if values]) if self.children: - children = [c.sgf(**xargs) for c in self.children] + children = [c.sgf(**xargs) for c in self.order_children(self.children)] if len(children) == 1: sgf_str += ";" + children[0] else: diff --git a/katrain.py b/katrain.py index 1599183..8d5f3a4 100644 --- a/katrain.py +++ b/katrain.py @@ -1,7 +1,8 @@ from kivy.config import Config # isort:skip + Config.set("input", "mouse", "mouse,multitouch_on_demand") # isort:skip # no red dots on right click ICON = "img/icon.png" -Config.set("kivy", "window_icon",ICON) # isort:skip # set icon before Window is imported +Config.set("kivy", "window_icon", ICON) # isort:skip # set icon before Window is imported import signal import os @@ -296,7 +297,7 @@ class KaTrainApp(App): gui = ObjectProperty(None) def build(self): - self.icon = ICON # how you're supposed to set an icon + self.icon = ICON # how you're supposed to set an icon self.gui = KaTrainGui() print(self.get_application_icon()) Window.bind(on_request_close=self.on_request_close)