From 9dcbce32e6dfc922f83d7b05d14d938ef654f162 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Tue, 29 Sep 2020 22:32:07 +0200 Subject: [PATCH] timer, simple fix --- katrain/config.json | 5 +++-- katrain/core/ai.py | 13 +++++++------ katrain/core/constants.py | 5 +++-- katrain/gui.kv | 4 ++-- katrain/gui/badukpan.py | 4 +++- katrain/gui/popups.py | 1 + 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/katrain/config.json b/katrain/config.json index 6df45ce..3419c7d 100644 --- a/katrain/config.json +++ b/katrain/config.json @@ -89,8 +89,9 @@ "opening_moves": 22.0 }, "ai:simple": { - "max_points_lost": 2.0, - "settled_weight": 1.0 + "max_points_lost": 1.75, + "settled_weight": 1.0, + "opponent_fac": 0.5 }, "ai:p:weighted": { "weaken_fac": 1.25, diff --git a/katrain/core/ai.py b/katrain/core/ai.py index 61bcccf..b57f290 100644 --- a/katrain/core/ai.py +++ b/katrain/core/ai.py @@ -378,21 +378,22 @@ def generate_ai_move(game: Game, ai_mode: str, ai_settings: Dict) -> Tuple[Move, ai_thoughts += f"ScoreLoss strategy found {len(candidate_ai_moves)} candidate moves (best {top_cand.gtp()}) and chose {aimove.gtp()} (weight {topmove[1]:.3f}, point loss {topmove[0]:.1f}) based on score weights." elif ai_mode == AI_SIMPLE_OWNERSHIP: - def settledness(d): - return sum([abs(o) for o in d["ownership"]]) + def settledness(d, player_fac): + return sum([abs(o) for o in d["ownership"] if player_fac * o > 0]) + next_player_sign = cn.player_sign(cn.next_player) moves_with_settledness = sorted( [ - (Move.from_gtp(d["move"], player=cn.next_player), settledness(d), d) + (Move.from_gtp(d["move"], player=cn.next_player), settledness(d,next_player_sign), settledness(d,-next_player_sign), d) for d in candidate_ai_moves if d["pointsLost"] < ai_settings["max_points_lost"] and "ownership" in d ], - key=lambda t: t[2]["pointsLost"] - ai_settings["settled_weight"] * t[1], + key=lambda t: t[3]["pointsLost"] - ai_settings["settled_weight"] * (t[1] + ai_settings["opponent_fac"] * t[2]), ) if moves_with_settledness: cands = [ - f"{move.gtp()} ({d['pointsLost']:.1f} pt lost, {settled:.1f} settledness)" - for move, settled, d in moves_with_settledness + f"{move.gtp()} ({d['pointsLost']:.1f} pt lost, {d['visits']} visits, {settled:.1f} settledness, {oppsettled:.1f} opponent settledness)" + for move, settled, oppsettled, d in moves_with_settledness ] ai_thoughts += f"Simple ownership strategy. Candidates {', '.join(cands)} " aimove = moves_with_settledness[0][0] diff --git a/katrain/core/constants.py b/katrain/core/constants.py index 94373ab..8a39dc0 100644 --- a/katrain/core/constants.py +++ b/katrain/core/constants.py @@ -70,7 +70,7 @@ AI_STRENGTH = { # dan ranks, backup if model is missing. TODO: remove some? AI_INFLUENCE: -7, AI_TERRITORY: -7, AI_RANK: float("nan"), - AI_SIMPLE_OWNERSHIP: 9, + AI_SIMPLE_OWNERSHIP: 3, } AI_OPTION_VALUES = { @@ -90,7 +90,8 @@ AI_OPTION_VALUES = { "automatic": "bool", "pda": [(x / 10, f"{'W' if x<0 else 'B'}+{abs(x/10):.1f}") for x in range(-30, 31)], "max_points_lost": [x / 10 for x in range(51)], - "settled_weight": [x / 10 for x in range(-100, 101)], + "settled_weight": [x / 4 for x in range(1, 17)], + "opponent_fac": [x / 10 for x in range(-20, 11)], } AI_KEY_PROPERTIES = {"kyu_rank", "strength", "weaken_fac", "pick_frac", "pick_n", "automatic"} diff --git a/katrain/gui.kv b/katrain/gui.kv index 7d8825e..f4dd0cd 100644 --- a/katrain/gui.kv +++ b/katrain/gui.kv @@ -364,7 +364,7 @@ size_hint: 0.4,1 TimerLabel: color: BACKGROUND_COLOR - text: '{}:88'.format('188' if root.state[0] >= 6000 else ('88' if root.state[0] >= 600 else '8')) + text: '{}:88'.format('188' if root.state[0] >= 6000 else '88') font_size: 0.85*self.height pos_hint: {'right':1,'center_y':0.5} halign: 'right' @@ -372,7 +372,7 @@ TimerLabel: id: timer timeout: root.timeout - text: "{:01d}:{:02d}".format(int(root.state[0]+0.99)//60,int((root.state[0]+0.99) % 60) ) + text: "{:2d}:{:02d}".format(int(root.state[0]+0.99)//60,int((root.state[0]+0.99) % 60) ) font_size: 0.85*self.height pos_hint: {'right':1,'center_y':0.5} halign: 'right' diff --git a/katrain/gui/badukpan.py b/katrain/gui/badukpan.py index 18ba0e0..35cb671 100644 --- a/katrain/gui/badukpan.py +++ b/katrain/gui/badukpan.py @@ -106,13 +106,15 @@ class BadukPanWidget(Widget): return katrain = self.katrain if self.ghost_stone and ("button" not in touch.profile or touch.button == "left"): - current_node = self.katrain and self.katrain.game and self.katrain.game.current_node + game = self.katrain and self.katrain.game + current_node = game and self.katrain.game.current_node if ( current_node and not current_node.children and not self.katrain.next_player_info.ai and not self.katrain.controls.timer.paused and self.katrain.play_analyze_mode == MODE_PLAY + and self.katrain.config("timer/main_time",0) * 60 - game.main_time_used <= 0 and current_node.time_used < self.katrain.config("timer/minimal_use", 0) ): self.katrain.controls.set_status( diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index 43a108c..f8808c0 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -238,6 +238,7 @@ class ConfigTimerPopup(QuickConfigGui): p.periods_used = 0 self.katrain.controls.timer.paused = True self.katrain.game.current_node.time_used = 0 + self.katrain.game.main_time_used = 0 self.katrain.update_state()