Skip to content

Commit

Permalink
feature: add shortcut m for toggle the move num of nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Jan 1, 2024
1 parent 98ce47c commit 612d135
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions katrain/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def __init__(self, **kwargs):
self.contribute_popup = None

self.pondering = False
self.move_num = False

self.animate_contributing = False
self.message_queue = Queue()

Expand Down Expand Up @@ -173,6 +175,10 @@ def toggle_continuous_analysis(self, quiet=False):
self.pondering = not self.pondering
self.update_state()

def toggle_move_num(self):
self.move_num = not self.move_num
self.update_state()

def start(self):
if self.engine:
return
Expand Down Expand Up @@ -740,6 +746,8 @@ def _on_keyboard_down(self, _keyboard, keycode, _text, modifiers):

if keycode[1] == Theme.KEY_TOGGLE_CONTINUOUS_ANALYSIS:
self.toggle_continuous_analysis(quiet=shift_pressed)
elif keycode[1] == Theme.KEY_TOGGLE_MOVENUM:
self.toggle_move_num()
elif keycode[1] == Theme.KEY_TOGGLE_COORDINATES:
self.board_gui.toggle_coordinates()
elif keycode[1] in Theme.KEY_PAUSE_TIMER and not ctrl_pressed:
Expand Down
9 changes: 8 additions & 1 deletion katrain/gui/badukpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ def redraw(self, *_args):
self.draw_board_contents()

def draw_stone(
self, x, y, player, alpha=1, innercol=None, evalcol=None, evalscale=1.0, scale=1.0, ownership=None, loss=None
self, x, y, player, alpha=1, innercol=None, evalcol=None, evalscale=1.0, scale=1.0, ownership=None,
loss=None, depth=None
):
stone_size = self.stone_size * scale
if ownership is not None:
Expand Down Expand Up @@ -297,6 +298,11 @@ def draw_stone(
texture=cached_texture(Theme.LAST_MOVE_TEXTURE),
)

if depth:
text = str(depth)
Color(*Theme.NUMBER_COLOR)
draw_text(pos=self.gridpos[y][x], text=text, font_size=self.stone_size*0.9, font_name="Roboto")

def eval_color(self, points_lost, show_dots_for_class: List[bool] = None) -> Optional[List[float]]:
i = evaluation_class(points_lost, self.trainer_config["eval_thresholds"])
colors = Theme.EVAL_COLORS[self.trainer_config["theme"]]
Expand Down Expand Up @@ -663,6 +669,7 @@ def draw_board_contents(self, *_args):
if ownership_grid and not loss_grid and not new_move
else None,
loss=loss_grid[m.coords[1]][m.coords[0]] if loss_grid else None,
depth=node.depth if katrain.move_num else None,
)
realized_points_lost = node.parent_realized_points_lost

Expand Down
3 changes: 3 additions & 0 deletions katrain/gui/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class Theme:
PASS_CIRCLE_TEXT_COLOR = [0.85, 0.85, 0.85]

STONE_COLORS = {"B": BLACK, "W": WHITE}
NUMBER_COLOR = [0.85, 0.68, 0.40, 0.8]

NEXT_MOVE_DASH_CONTRAST_COLORS = {"B": LIGHTER_GREY, "W": GREY}
OUTLINE_COLORS = {"B": [0.3, 0.3, 0.3, 0.5], "W": [0.7, 0.7, 0.7, 0.5]}
PV_TEXT_COLORS = {"W": BLACK, "B": WHITE} # numbers in PV
Expand Down Expand Up @@ -198,6 +200,7 @@ class Theme:
KEY_SELFPLAY_TO_END = "l"
KEY_STOP_ANALYSIS = "escape"
KEY_TOGGLE_CONTINUOUS_ANALYSIS = "spacebar"
KEY_TOGGLE_MOVENUM = "m"

KEY_COPY = "c"
KEY_PASTE = "v"
Expand Down

0 comments on commit 612d135

Please sign in to comment.