minor bugfixes

This commit is contained in:
Sander Land committed 2020-02-24 21:40:14 +01:00
1 parent 2cce7ed4af
commit 6126bf45df
2 files changed
+9 -7

No files matched your search

+2 -2
View File
@@ -24,7 +24,7 @@ class Move:
self.analysis = None self.analysis = None
self.pass_analysis = None self.pass_analysis = None
self.ownership = None self.ownership = None
self.x_comment = "" self.x_comment = {}
self.auto_undid = False self.auto_undid = False
self.move_number = 0 self.move_number = 0
self.undo_threshold = random.random() # for fractional undos, store the random threshold in the move itself for consistency self.undo_threshold = random.random() # for fractional undos, store the random threshold in the move itself for consistency
@@ -83,7 +83,7 @@ class Move:
text = "" text = ""
text += f"Move {self.move_number}: {self.bw_player()} {self.gtp()} {'(AI Move)' if self.robot else ''}\n" text += f"Move {self.move_number}: {self.bw_player()} {self.gtp()} {'(AI Move)' if self.robot else ''}\n"
text += self.x_comment text += "\n".join(self.x_comment.values())
if self.analysis_ready: if self.analysis_ready:
score, _, temperature = self.temperature_stats score, _, temperature = self.temperature_stats
+7 -5
View File
@@ -109,7 +109,7 @@ class EngineControls(GridLayout):
if not self.ai_auto.active(current_move.player): if not self.ai_auto.active(current_move.player):
self.show_evaluation_stats(current_move) self.show_evaluation_stats(current_move)
if current_move.analysis_ready and current_move.parent and current_move.parent.analysis_ready and not current_move.children and not current_move.x_comment: if current_move.analysis_ready and current_move.parent and current_move.parent.analysis_ready and not current_move.children and not current_move.x_comment.get("undo"):
# handle automatic undo # handle automatic undo
if self.auto_undo.active(current_move.player) and not self.ai_auto.active(current_move.player) and not current_move.auto_undid: if self.auto_undo.active(current_move.player) and not self.ai_auto.active(current_move.player) and not current_move.auto_undid:
ts = self.train_settings ts = self.train_settings
@@ -118,14 +118,14 @@ class EngineControls(GridLayout):
points_lost = (current_move.parent or current_move).temperature_stats[2] * (1 - move_eval) points_lost = (current_move.parent or current_move).temperature_stats[2] * (1 - move_eval)
if move_eval < ts["undo_eval_threshold"] and points_lost >= ts["undo_point_threshold"]: if move_eval < ts["undo_eval_threshold"] and points_lost >= ts["undo_point_threshold"]:
if self.num_undos(current_move) == 0: if self.num_undos(current_move) == 0:
current_move.x_comment = f"Move was below threshold, but no undo granted (probability is {ts['num_undo_prompts']:.0%}).\n" current_move.x_comment["undid"] = f"Move was below threshold, but no undo granted (probability is {ts['num_undo_prompts']:.0%}).\n"
self.update_evaluation() self.update_evaluation()
else: else:
current_move.auto_undid = True current_move.auto_undid = True
self.board.undo() self.board.undo()
if len(current_move.parent.children) >= ts["num_undo_prompts"] + 1: if len(current_move.parent.children) >= ts["num_undo_prompts"] + 1:
best_move = sorted([m for m in current_move.parent.children], key=lambda m: -(m.evaluation_info[0] or 0))[0] best_move = sorted([m for m in current_move.parent.children], key=lambda m: -(m.evaluation_info[0] or 0))[0]
best_move.x_comment = f"Automatically played as best option after max. {ts['num_undo_prompts']} undo(s).\n" best_move.x_comment["undo_autoplay"] = f"Automatically played as best option after max. {ts['num_undo_prompts']} undo(s).\n"
self.board.play(best_move) self.board.play(best_move)
self.update_evaluation() self.update_evaluation()
return return
@@ -149,7 +149,9 @@ class EngineControls(GridLayout):
time.sleep(0.05) time.sleep(0.05)
# select move # select move
current_move = self.board.current_move current_move = self.board.current_move
pos_moves = [(d["move"], float(d["scoreLead"]), d["evaluation"]) for d in current_move.ai_moves if int(d["visits"]) >= ts["balance_play_min_visits"]] pos_moves = [
(d["move"], float(d["scoreLead"]), d["evaluation"]) for i, d in enumerate(current_move.ai_moves) if i == 0 or int(d["visits"]) >= ts["balance_play_min_visits"]
]
sel_moves = pos_moves[:1] sel_moves = pos_moves[:1]
# don't play suicidal to balance score - pass when it's best # don't play suicidal to balance score - pass when it's best
if self.ai_balance.active and pos_moves[0][0] != "pass": if self.ai_balance.active and pos_moves[0][0] != "pass":
@@ -163,7 +165,7 @@ class EngineControls(GridLayout):
] or sel_moves ] or sel_moves
aimove = Move(player=self.board.current_player, gtpcoords=random.choice(sel_moves)[0], robot=True) aimove = Move(player=self.board.current_player, gtpcoords=random.choice(sel_moves)[0], robot=True)
if len(sel_moves) > 1: if len(sel_moves) > 1:
aimove.x_comment = "AI Balance on, moves considered: " + ", ".join(f"{move} ({aimove.format_score(score)})" for move, score, _ in sel_moves) + "\n" aimove.x_comment["ai"] = "AI Balance on, moves considered: " + ", ".join(f"{move} ({aimove.format_score(score)})" for move, score, _ in sel_moves) + "\n"
self.play(aimove) self.play(aimove)
def num_undos(self, move): def num_undos(self, move):