new game fix

This commit is contained in:
Sander Land committed 2020-12-06 14:20:23 +01:00
1 parent 86fc714a94
commit a3815cb47a
21 files changed
+63 -30

No files matched your search

+6 -1
View File
@@ -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. * **[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. * **[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. * **[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. * **[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. * **[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 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. * **[arrow up/down]** Switch branch, as would be expected from the move tree.
* **[home/end]** Go to the beginning/end of the game. * **[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. * **[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. * **[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. * **[scroll up]**: Undo move. Only works when hovering the cursor over the board.
+1
View File
@@ -339,6 +339,7 @@ class KaTrainGui(Screen, KaTrainBase):
).__self__ ).__self__
self.new_game_popup.content.popup = self.new_game_popup self.new_game_popup.content.popup = self.new_game_popup
self.new_game_popup.open() self.new_game_popup.open()
self.new_game_popup.content.update_from_current_game()
def _do_timer_popup(self): def _do_timer_popup(self):
self.controls.timer.paused = True self.controls.timer.paused = True
+8 -1
View File
@@ -535,18 +535,25 @@ class Game:
def analyze_and_play_policy(node): def analyze_and_play_policy(node):
nonlocal count, cn nonlocal count, cn
cand = node.candidate_moves cand = node.candidate_moves
if self.katrain.game is not self:
return # a new game happened
if cand: if cand:
move = Move.from_gtp(cand[0]["move"], player=node.next_player) move = Move.from_gtp(cand[0]["move"], player=node.next_player)
else: else:
polmoves = node.policy_ranking polmoves = node.policy_ranking
move = polmoves[0][1] if polmoves else Move(None) move = polmoves[0][1] if polmoves else Move(None)
if move.is_pass: if move.is_pass:
cn.add_shortcut(node)
self.set_current_node(node) self.set_current_node(node)
self.katrain.controls.set_status("", STATUS_INFO) self.katrain.controls.set_status("", STATUS_INFO)
return return
count += 1 count += 1
new_node = GameNode(parent=node, move=move) 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) self.katrain.controls.set_status(i18n._("playtoend:status").format(num_moves=count), STATUS_INFO)
def set_analysis(result, _partial): def set_analysis(result, _partial):
+5 -5
View File
@@ -763,6 +763,11 @@
icon: 'img/insert.png' icon: 'img/insert.png'
shortcut: 'i' shortcut: 'i'
on_action: root.katrain("insert-mode") 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: AnalysisMenuItem:
text: i18n._("analysis:game") text: i18n._("analysis:game")
icon: 'img/analysis.png' icon: 'img/analysis.png'
@@ -778,11 +783,6 @@
icon: 'img/ai.png' icon: 'img/ai.png'
shortcut: 'enter' shortcut: 'enter'
on_action: root.katrain("ai-move") on_action: root.katrain("ai-move")
AnalysisMenuItem:
text: i18n._("analysis:playtoend")
icon: 'img/Finish.png'
shortcut: 'l'
on_action: root.katrain("play-to-end")
<AnalysisControls>: <AnalysisControls>:
+26 -7
View File
@@ -35,7 +35,6 @@ from katrain.core.lang import i18n, rank_label
from katrain.core.utils import PATHS, find_package_resource from katrain.core.utils import PATHS, find_package_resource
from katrain.gui.kivyutils import BackgroundMixin, I18NSpinner from katrain.gui.kivyutils import BackgroundMixin, I18NSpinner
from katrain.gui.style import DEFAULT_FONT, EVAL_COLORS from katrain.gui.style import DEFAULT_FONT, EVAL_COLORS
from katrain.gui.widgets import RankGraph
from katrain.gui.widgets.progress_loader import ProgressLoader from katrain.gui.widgets.progress_loader import ProgressLoader
@@ -249,14 +248,35 @@ class NewGamePopup(QuickConfigGui):
self.player_setup.update_player_info(bw, info) self.player_setup.update_player_info(bw, info)
self.rules_spinner.value_refs = [name for abbr, name in katrain.engine.RULESETS_ABBR] 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(): for bw, player_setup in self.player_setup.players.items():
name = self.player_name[bw].text name = self.player_name[bw].text
if name: if name:
self.katrain.game.root.set_property("P" + bw, name) self.katrain.game.root.set_property("P" + bw, name)
self.katrain.update_player(bw, **player_setup.player_type_dump) 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): def update_config(self, save_to_file=True):
super().update_config(save_to_file=save_to_file) super().update_config(save_to_file=save_to_file)
self.katrain.log(f"New game settings: {self.katrain.config('game')}", OUTPUT_DEBUG) 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) props = self.collect_properties(self)
root = self.katrain.game.root root = self.katrain.game.root
changed = False changed = False
for k, v in [("RU", props["game/rules"]), ("KM", props["game/komi"])]: for k, currentval, newval in [("RU",self.normalized_rules(), props["game/rules"]), ("KM", root.komi, props["game/komi"])]:
current = root.get_property(k) if currentval !=newval:
if current != v:
changed = True changed = True
self.katrain.log( 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() self.update_playerinfo()
if changed: if changed:
self.katrain.engine.on_new_game() self.katrain.engine.on_new_game()
+1 -1
View File
@@ -227,7 +227,7 @@ class MoveTree(ScrollView, BackgroundMixin):
super().__init__(**kwargs) super().__init__(**kwargs)
self.insert_node = None self.insert_node = None
self.redraw_tree_trigger = Clock.create_trigger( 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) self.bind(current_node=self.redraw_tree_trigger, size=self.redraw_tree_trigger)
Binary file not shown.
@@ -817,5 +817,5 @@ msgstr "Fast playout to game end"
#. TODO - Status message #. TODO - Status message
msgid "playtoend:status" msgid "playtoend:status"
msgstr "" msgstr ""
"Playing game to the end with policy strategy, please wait ... {num_moves} " "Playing the game quickly to the end, please wait ... {num_moves} moved "
"moves played." "played.moves played."
Binary file not shown.
@@ -11,7 +11,7 @@ msgid "menu:playersetup"
msgstr "Player Setup" msgstr "Player Setup"
msgid "menu:newgame" msgid "menu:newgame"
msgstr "New Game" msgstr "New Game/Change Rules"
msgid "menu:save" msgid "menu:save"
msgstr "Save Game" msgstr "Save Game"
@@ -125,8 +125,8 @@ msgstr "Fast playout to game end"
#. Status message #. Status message
msgid "playtoend:status" msgid "playtoend:status"
msgstr "" msgstr ""
"Playing the game quickly to the end, please wait ... {num_moves} moved played." "Playing the game quickly to the end, please wait ... {num_moves} moved "
"moves played." "played.moves played."
#. Keep improving current position analysis when there is nothing else to do #. Keep improving current position analysis when there is nothing else to do
msgid "analysis:continuous" msgid "analysis:continuous"
Binary file not shown.
@@ -824,5 +824,5 @@ msgstr "Fast playout to game end"
#. TODO - Status message #. TODO - Status message
msgid "playtoend:status" msgid "playtoend:status"
msgstr "" msgstr ""
"Playing game to the end with policy strategy, please wait ... {num_moves} " "Playing the game quickly to the end, please wait ... {num_moves} moved "
"moves played." "played.moves played."
Binary file not shown.
@@ -851,5 +851,5 @@ msgstr "Fast playout to game end"
#. TODO - Status message #. TODO - Status message
msgid "playtoend:status" msgid "playtoend:status"
msgstr "" msgstr ""
"Playing game to the end with policy strategy, please wait ... {num_moves} " "Playing the game quickly to the end, please wait ... {num_moves} moved "
"moves played." "played.moves played."
Binary file not shown.
@@ -808,5 +808,5 @@ msgstr "Fast playout to game end"
#. TODO - Status message #. TODO - Status message
msgid "playtoend:status" msgid "playtoend:status"
msgstr "" msgstr ""
"Playing game to the end with policy strategy, please wait ... {num_moves} " "Playing the game quickly to the end, please wait ... {num_moves} moved "
"moves played." "played.moves played."
Binary file not shown.
@@ -778,5 +778,5 @@ msgstr "Fast playout to game end"
#. TODO - Status message #. TODO - Status message
msgid "playtoend:status" msgid "playtoend:status"
msgstr "" msgstr ""
"Playing game to the end with policy strategy, please wait ... {num_moves} " "Playing the game quickly to the end, please wait ... {num_moves} moved "
"moves played." "played.moves played."
Binary file not shown.
@@ -814,5 +814,5 @@ msgstr "Fast playout to game end"
#. TODO - Status message #. TODO - Status message
msgid "playtoend:status" msgid "playtoend:status"
msgstr "" msgstr ""
"Playing game to the end with policy strategy, please wait ... {num_moves} " "Playing the game quickly to the end, please wait ... {num_moves} moved "
"moves played." "played.moves played."
+1
View File
@@ -375,6 +375,7 @@
<NewGamePopup>: <NewGamePopup>:
restart: restart restart: restart
rules_spinner: rules_spinner rules_spinner: rules_spinner
km: km
player_setup: player_setup player_setup: player_setup
player_name: {"W": white_player_name, "B": black_player_name} player_name: {"W": white_player_name, "B": black_player_name}
PlayerSetupBlock: PlayerSetupBlock: