From a3815cb47a8e26688b395aa7260f9a24de7ef3f8 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sun, 6 Dec 2020 14:20:23 +0100 Subject: [PATCH] new game fix --- README.md | 7 +++- katrain/__main__.py | 1 + katrain/core/game.py | 9 ++++- katrain/gui.kv | 10 +++--- katrain/gui/popups.py | 33 ++++++++++++++---- katrain/gui/widgets/movetree.py | 2 +- .../i18n/locales/de/LC_MESSAGES/katrain.mo | Bin 16373 -> 16377 bytes .../i18n/locales/de/LC_MESSAGES/katrain.po | 4 +-- .../i18n/locales/en/LC_MESSAGES/katrain.mo | Bin 15635 -> 15652 bytes .../i18n/locales/en/LC_MESSAGES/katrain.po | 6 ++-- .../i18n/locales/es/LC_MESSAGES/katrain.mo | Bin 15769 -> 15773 bytes .../i18n/locales/es/LC_MESSAGES/katrain.po | 4 +-- .../i18n/locales/fr/LC_MESSAGES/katrain.mo | Bin 17476 -> 17480 bytes .../i18n/locales/fr/LC_MESSAGES/katrain.po | 4 +-- .../i18n/locales/jp/LC_MESSAGES/katrain.mo | Bin 17877 -> 17881 bytes .../i18n/locales/jp/LC_MESSAGES/katrain.po | 4 +-- .../i18n/locales/ko/LC_MESSAGES/katrain.mo | Bin 17409 -> 17413 bytes .../i18n/locales/ko/LC_MESSAGES/katrain.po | 4 +-- .../i18n/locales/ru/LC_MESSAGES/katrain.mo | Bin 22199 -> 22203 bytes .../i18n/locales/ru/LC_MESSAGES/katrain.po | 4 +-- katrain/popups.kv | 1 + 21 files changed, 63 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 260810c..1ec51f6 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,9 @@ Keyboard shortcuts are shown with **[key]**. * **[s]**: Equalize visits: Re-evaluate all currently shown next moves with the same visits as the current top move. Useful to increase confidence in the suggestions with high uncertainty. * **[d]**: Analyze all moves: Evaluate all possible next moves. This can take a bit of time even though 'fast_visits' is used, but can be useful to see how many reasonable next moves are available. * **[f]**: Find alternatives: Increases analysis of current candidate moves to at least the 'fast visits' level, and request a new query that excludes all current candidate moves. - * **[g]**: Find local responses: Searches within 5 spaces of the last move only. + * **[g]**: Select area of interest: set an area and search only for moves in this box, including variations. Good for solving tsumegos. + * **[i]**: Start insertion mode. Allows you to insert moves, to improve analysis when both players ignore an important exchange or life and death situation. Press again to stop inserting and copy the rest of the branch. + * **[l]**: Play out the game until the end and add as a collapsed branch, to visualize the potential effect of mistakes. This is done in the background, and can be started at several nodes at once when comparing the results at different starting positions. * **[spacebar]**: Turn continuous analysis on/off. This will continuously improve analysis of the current position, similar to Lizzie's 'pondering', but only when there are no other queries going on. * **[enter]** AI move. Makes the AI move for the current player regardless of current player selection. @@ -182,6 +184,9 @@ In addition to shortcuts mentioned above and those shown in the main menu: * **[arrow right]** or **[x]**: Redo move. Hold alt for 10 moves at a time, or ctrl to skip to the end. * **[arrow up/down]** Switch branch, as would be expected from the move tree. * **[home/end]** Go to the beginning/end of the game. +* **[pageup]** Make the currently selected node the main branch +* **[ctrl-delete]** Delete current node. +* **[c]** Collapse/Uncollapse the branch from the current node to the previous branching point. * **[b]** Go back to the previous branching point. * **[n]** As in clicking the red arrow, go to one move before the next mistake (orange or worse) by a human player. * **[scroll up]**: Undo move. Only works when hovering the cursor over the board. diff --git a/katrain/__main__.py b/katrain/__main__.py index 01b1493..a504100 100644 --- a/katrain/__main__.py +++ b/katrain/__main__.py @@ -339,6 +339,7 @@ class KaTrainGui(Screen, KaTrainBase): ).__self__ self.new_game_popup.content.popup = self.new_game_popup self.new_game_popup.open() + self.new_game_popup.content.update_from_current_game() def _do_timer_popup(self): self.controls.timer.paused = True diff --git a/katrain/core/game.py b/katrain/core/game.py index ea886bb..23e9695 100644 --- a/katrain/core/game.py +++ b/katrain/core/game.py @@ -535,18 +535,25 @@ class Game: def analyze_and_play_policy(node): nonlocal count, cn cand = node.candidate_moves + if self.katrain.game is not self: + return # a new game happened if cand: move = Move.from_gtp(cand[0]["move"], player=node.next_player) else: polmoves = node.policy_ranking move = polmoves[0][1] if polmoves else Move(None) + if move.is_pass: - cn.add_shortcut(node) self.set_current_node(node) self.katrain.controls.set_status("", STATUS_INFO) return count += 1 new_node = GameNode(parent=node, move=move) + if node != cn: + node.remove_shortcut() + cn.add_shortcut(new_node) + self.katrain.controls.move_tree.redraw_tree_trigger() + self.katrain.controls.set_status(i18n._("playtoend:status").format(num_moves=count), STATUS_INFO) def set_analysis(result, _partial): diff --git a/katrain/gui.kv b/katrain/gui.kv index 29adef8..8bf7ce7 100644 --- a/katrain/gui.kv +++ b/katrain/gui.kv @@ -763,6 +763,11 @@ icon: 'img/insert.png' shortcut: 'i' on_action: root.katrain("insert-mode") + AnalysisMenuItem: + text: i18n._("analysis:playtoend") + icon: 'img/Finish.png' + shortcut: 'l' + on_action: root.katrain("play-to-end") AnalysisMenuItem: text: i18n._("analysis:game") icon: 'img/analysis.png' @@ -778,11 +783,6 @@ icon: 'img/ai.png' shortcut: 'enter' on_action: root.katrain("ai-move") - AnalysisMenuItem: - text: i18n._("analysis:playtoend") - icon: 'img/Finish.png' - shortcut: 'l' - on_action: root.katrain("play-to-end") : diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index d9947fb..d6a1329 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -35,7 +35,6 @@ from katrain.core.lang import i18n, rank_label from katrain.core.utils import PATHS, find_package_resource from katrain.gui.kivyutils import BackgroundMixin, I18NSpinner from katrain.gui.style import DEFAULT_FONT, EVAL_COLORS -from katrain.gui.widgets import RankGraph from katrain.gui.widgets.progress_loader import ProgressLoader @@ -249,14 +248,35 @@ class NewGamePopup(QuickConfigGui): self.player_setup.update_player_info(bw, info) self.rules_spinner.value_refs = [name for abbr, name in katrain.engine.RULESETS_ABBR] + Clock.schedule_once(self.update_from_current_game, 0.1) - def update_playerinfo(self): + def normalized_rules(self): + rules = self.katrain.game.root.get_property("RU", "japanese").strip().lower() + for abbr, name in self.katrain.engine.RULESETS_ABBR: + if abbr==rules or abbr==rules: + return name + + + def update_playerinfo(self,*args): for bw, player_setup in self.player_setup.players.items(): name = self.player_name[bw].text if name: self.katrain.game.root.set_property("P" + bw, name) self.katrain.update_player(bw, **player_setup.player_type_dump) + def update_from_current_game(self): + for bw in "BW": + name = self.katrain.game.root.get_property("P" + bw, None) + if name: + self.player_name[bw].text = name + komi = self.katrain.game.root.komi + rules = self.normalized_rules() + if komi is not None: + self.km.text = str(komi) + if rules is not None: + self.rules_spinner.select_key(rules.strip()) + + def update_config(self, save_to_file=True): super().update_config(save_to_file=save_to_file) self.katrain.log(f"New game settings: {self.katrain.config('game')}", OUTPUT_DEBUG) @@ -270,14 +290,13 @@ class NewGamePopup(QuickConfigGui): props = self.collect_properties(self) root = self.katrain.game.root changed = False - for k, v in [("RU", props["game/rules"]), ("KM", props["game/komi"])]: - current = root.get_property(k) - if current != v: + for k, currentval, newval in [("RU",self.normalized_rules(), props["game/rules"]), ("KM", root.komi, props["game/komi"])]: + if currentval !=newval: changed = True self.katrain.log( - f"Property {k} changed from {current} to {v}, triggering re-analysis of entire game.", OUTPUT_INFO + f"Property {k} changed from {currentval} to {newval}, triggering re-analysis of entire game.", OUTPUT_INFO ) - self.katrain.game.root.set_property(k, v) + self.katrain.game.root.set_property(k, newval) self.update_playerinfo() if changed: self.katrain.engine.on_new_game() diff --git a/katrain/gui/widgets/movetree.py b/katrain/gui/widgets/movetree.py index ca36e0a..99d1728 100644 --- a/katrain/gui/widgets/movetree.py +++ b/katrain/gui/widgets/movetree.py @@ -227,7 +227,7 @@ class MoveTree(ScrollView, BackgroundMixin): super().__init__(**kwargs) self.insert_node = None self.redraw_tree_trigger = Clock.create_trigger( - lambda _dt: self.move_tree_canvas.draw_move_tree(self.current_node, self.insert_node) + lambda _dt: self.move_tree_canvas.draw_move_tree(self.current_node, self.insert_node), 0.1 ) self.bind(current_node=self.redraw_tree_trigger, size=self.redraw_tree_trigger) diff --git a/katrain/i18n/locales/de/LC_MESSAGES/katrain.mo b/katrain/i18n/locales/de/LC_MESS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A4)^xC=JhHCF&>_CQv4rLb+fIr7;ub`#qHNr|7}P3j+BU_c)0!#T(at xZ*e-XVC#rQR&~utX+~Vv^tGtAoiO5BI+aW;XS7XYBVy>WOyM@@FMb3A_CJ6SP@ez* diff --git a/katrain/i18n/locales/en/LC_MESSAGES/katrain.po b/katrain/i18n/locales/en/LC_MESSAGES/katrain.po index eed3f21..286c85b 100644 --- a/katrain/i18n/locales/en/LC_MESSAGES/katrain.po +++ b/katrain/i18n/locales/en/LC_MESSAGES/katrain.po @@ -11,7 +11,7 @@ msgid "menu:playersetup" msgstr "Player Setup" msgid "menu:newgame" -msgstr "New Game" +msgstr "New Game/Change Rules" msgid "menu:save" msgstr "Save Game" @@ -125,8 +125,8 @@ msgstr "Fast playout to game end" #. Status message msgid "playtoend:status" msgstr "" -"Playing the game quickly to the end, please wait ... {num_moves} moved played." -"moves played." +"Playing the game quickly to the end, please wait ... {num_moves} moved " +"played.moves played." #. Keep improving current position analysis when there is nothing else to do msgid "analysis:continuous" diff --git a/katrain/i18n/locales/es/LC_MESSAGES/katrain.mo b/katrain/i18n/locales/es/LC_MESSAGES/katrain.mo index f36f7d93956541035c988d5810ef08587d062e1c..139dbc976040fc6c55f513db82a9ddd78584af00 100644 GIT binary patch delta 443 zcmXZYy-Px26vy!sS{Z3CMm0$AAPrIAB-G8@PzX_b5j9EolF{uA3=)Ss1hure=-|-g zD%ctkjczRwZT$fbO$|YP5BHfq{Lb^7^Sm@`ty-s;3=c%abwo1Qz&U)xA$-Fue%Snr zW8~PXND9-qfCh88g}Q!?%Xo*{|BQM3!ZgknqJ4`62_-?np)iaaIEvdifV|{qga}kuPzL)FXI#cm~dAdLd delta 442 zcmXZYyGz4R6vy!+#s}E6qUfT+rHBZEI4Bw$MZw3ch>lV;w1sFz15!F<=;EY7+ zs0V(b{?Iq-MSc^lm3Y66+HVr)aFD!)+qi?W?)#?oV%KIS3;7ez1Z5KxJ>#7oo6AyA aG-qYMbW|}H!FfLL3YFVKC)>JqGS)u{W*(PHj^i~>;1~AbAC6+i7s=r?&fzNdVjUBB>Psx`6z2@6m+0aZI(Tn=zc$r8x?h`}C6OdKY4uRg>&G-^u^Y#5z~O<|M_w+*BApZ)MJBL7rY#K(Ezu}-QQ?+R7epNH;3BR;L$x#o zK~NdBML|$o^bfQ&yR-!beIL5Z`JCT*ea?ApS$2o>QtHer8jhcrFwA1BF^Zo&W#< diff --git a/katrain/i18n/locales/fr/LC_MESSAGES/katrain.po b/katrain/i18n/locales/fr/LC_MESSAGES/katrain.po index 3d1aae3..10f99d3 100644 --- a/katrain/i18n/locales/fr/LC_MESSAGES/katrain.po +++ b/katrain/i18n/locales/fr/LC_MESSAGES/katrain.po @@ -851,5 +851,5 @@ msgstr "Fast playout to game end" #. TODO - Status message msgid "playtoend:status" msgstr "" -"Playing game to the end with policy strategy, please wait ... {num_moves} " -"moves played." +"Playing the game quickly to the end, please wait ... {num_moves} moved " +"played.moves played." diff --git a/katrain/i18n/locales/jp/LC_MESSAGES/katrain.mo b/katrain/i18n/locales/jp/LC_MESSAGES/katrain.mo index 936768313de0cf9c69d6578c3a9fb2edfb07fe53..6d6ff7c02fbfeba5da20f20eb4eb84964cda2f3d 100644 GIT binary patch delta 445 zcmXZYyGsK>5XbR3dwdJh)Aj{EG$xrg_Zw6 z3L#*TM(njrk-}C%u&}WAJKk2Got@d=?QN&wbQ{j2pN{uMq_ZwEhOQ?vj@#Iehd762 zOyM1-@c}c~#93_PGJfJHP8CG5=vw!1k@^a?-$c!ME=c^pc(of{)DM4P4}M#JaEbcY z_H!G_Tpl%O)w+d4)VsD{vYw#+U={O@$PMa6+J2lIc=MB>chtcz)F9bR28VHgat8Y_ zhk8*L2XO`Ug*+U=9n|v&sCgCZHLg+Lqj*tdS}&Q&g^AixXv)P(XsVaTrPHWxYUf7x X!n5Gk@v^DFTtvls7|ge(y{Fzki8en^ delta 444 zcmXZYKTE?v7{~D^_#awCK@brCJY-}X#99 z)Qh?}jRn*f+QvEDL*0LbnipDQ+@ZchDL0#D@SI)VT&-7Ifr;8CY6K=YKQ&ij)G!zA XW?1W*PIOs~f_nG%r<5Dy%a7xKJPttj diff --git a/katrain/i18n/locales/jp/LC_MESSAGES/katrain.po b/katrain/i18n/locales/jp/LC_MESSAGES/katrain.po index 33ee94f..fd8ddae 100644 --- a/katrain/i18n/locales/jp/LC_MESSAGES/katrain.po +++ b/katrain/i18n/locales/jp/LC_MESSAGES/katrain.po @@ -808,5 +808,5 @@ msgstr "Fast playout to game end" #. TODO - Status message msgid "playtoend:status" msgstr "" -"Playing game to the end with policy strategy, please wait ... {num_moves} " -"moves played." +"Playing the game quickly to the end, please wait ... {num_moves} moved " +"played.moves played." diff --git a/katrain/i18n/locales/ko/LC_MESSAGES/katrain.mo b/katrain/i18n/locales/ko/LC_MESSAGES/katrain.mo index aa42ac63ec686f6a32f0fe853c9a5b0f6ac82bb0..f9931259fe4d92de54c1fe7fff748770d181b1ac 100644 GIT binary patch delta 445 zcmXZYy-EX75QgCi%c_wC{{o7!IBaJlA~uSwNwo0_EDS=(E-G37LIk&vC7_Zz7FJ$? zjS#T03PQj>wUSE^wbpmcDVAry8P1&HG+U{gR_bXxlkADey)QD2Uzo#@O+L)y8hSRD zQTtWQ;w7%*Ef%qhljsygb})w??&B&pQSW)iaeOOC^8eGPFh$`5b?_%T_-l2TUM7#C zE*4m8);j9I81?+M&25_>aGv@jeq+z}UrNdFK(8c{q0z?~9N+~0pl3HqW^oB~ zHgBQn?_vryF5?9j@d?w|!*xs-MDnxn=VWPEo(bAMDuvLn-QC=#)f~G`cu}Z#atIXf}?m_7}=v zf;@?4ksJ=;EDqxwnn8qT% ZtD{;_*$>sRuDjav!>dOp-~Mo>6Mq!NLOcKf diff --git a/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po b/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po index 5d2bd99..c04f90b 100644 --- a/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po +++ b/katrain/i18n/locales/ko/LC_MESSAGES/katrain.po @@ -778,5 +778,5 @@ msgstr "Fast playout to game end" #. TODO - Status message msgid "playtoend:status" msgstr "" -"Playing game to the end with policy strategy, please wait ... {num_moves} " -"moves played." +"Playing the game quickly to the end, please wait ... {num_moves} moved " +"played.moves played." diff --git a/katrain/i18n/locales/ru/LC_MESSAGES/katrain.mo b/katrain/i18n/locales/ru/LC_MESSAGES/katrain.mo index 852ca806a96b61e200bedbb7c7f2dc93d1da37f3..951f6ccb1f2b7020e038a7e00f8afff3b61b4371 100644 GIT binary patch delta 445 zcmXZX&npCB7{Kvow*0DHv}BXywdKIU!IF#1)E+49T84|$GP7uhUA5Gl)=7zyq?|-< zYNYnypp>LsxbH#9$seFZiSKLY^m(7B=Xu`ex%Q14-?&PK%kv`gloE+!e_AAglh}+~ zIDz{?T*Xe}cZ^_YN@NsUaTdq12TyPTZ&A(R5~Jv0H|}Mm{QtNh5hL-4ZTN~I z{0RKSJn=U+Vs2Wb0}H4Z-A3Ji6zHR_dq6$!8OQJq&kdHGsU31}m1`TnSRx}7{NNBK zIHv`37{yJbPj;{lcd;H1P=9ocVLZbDyu?1NqKUt#=a_TML<_}qT~)b@w3}U}Wk)S# lR~@y!v9g$VJyj|wopaXg!>?4l$yP-->pAvdC6+#I_yY&`N>=~? delta 444 zcmXZX&nrYx6u|NGlpl*X)DTJ2+$OWJQGR4Yc{K|*^Mk>9hG%A)$7nohO1)B|WFb~! zr4%)#W}#SU%1T+zLdnV>Fr}1~e6N|+=bqC!=brOWHtx#CZN&7JMC2tZ62fpyWE5wx z6L)YH51Vlf`-wl$hrc+1W?WOidfqcm;yYd%A_Mb{Lmrb}W8>GP$T$Vx zID*5R(}ijDV-e|-J#58&Y{MheADyC!7dV7B7{(e}_=9@R)S}2L#!)QCQI)E%#~RF} p)@ diff --git a/katrain/i18n/locales/ru/LC_MESSAGES/katrain.po b/katrain/i18n/locales/ru/LC_MESSAGES/katrain.po index 773c3ba..9955655 100644 --- a/katrain/i18n/locales/ru/LC_MESSAGES/katrain.po +++ b/katrain/i18n/locales/ru/LC_MESSAGES/katrain.po @@ -814,5 +814,5 @@ msgstr "Fast playout to game end" #. TODO - Status message msgid "playtoend:status" msgstr "" -"Playing game to the end with policy strategy, please wait ... {num_moves} " -"moves played." +"Playing the game quickly to the end, please wait ... {num_moves} moved " +"played.moves played." diff --git a/katrain/popups.kv b/katrain/popups.kv index f02c488..b432345 100644 --- a/katrain/popups.kv +++ b/katrain/popups.kv @@ -375,6 +375,7 @@ : restart: restart rules_spinner: rules_spinner + km: km player_setup: player_setup player_name: {"W": white_player_name, "B": black_player_name} PlayerSetupBlock: