interpret [tt] as pass in move, cleanup
This commit is contained in:
1 parent
a20475a97f
commit
eba8cddda1
2 files changed
+25
-25
No files matched your search
@@ -160,16 +160,17 @@ class Move:
|
||||
return self.analysis
|
||||
|
||||
# various output and conversion functions
|
||||
|
||||
def gtp2ix(self, gtpmove):
|
||||
@staticmethod
|
||||
def gtp2ix(gtpmove):
|
||||
if "pass" in gtpmove:
|
||||
return (None, None)
|
||||
return None, None
|
||||
return Move.GTP_COORD.index(gtpmove[0]), int(gtpmove[1:]) - 1
|
||||
|
||||
def sgf2ix(self, sgfmove_with_board_size):
|
||||
@staticmethod
|
||||
def sgf2ix(sgfmove_with_board_size):
|
||||
sgfmove, board_size = sgfmove_with_board_size
|
||||
if sgfmove == "":
|
||||
return (None, None)
|
||||
if sgfmove == "" or Move.SGF_COORD.index(sgfmove[0]) == board_size: # some servers use [tt] for pass
|
||||
return None, None
|
||||
return Move.SGF_COORD.index(sgfmove[0]), board_size - Move.SGF_COORD.index(sgfmove[1]) - 1
|
||||
|
||||
def gtp(self):
|
||||
@@ -201,7 +202,7 @@ class Board:
|
||||
|
||||
# -- move tree functions --
|
||||
def _init_chains(self):
|
||||
self.board = [[-1 for x in range(self.board_size)] for y in range(self.board_size)] # board pos -> chain id
|
||||
self.board = [[-1 for _x in range(self.board_size)] for _y in range(self.board_size)] # board pos -> chain id
|
||||
self.chains = [] # chain id -> chain
|
||||
self.prisoners = []
|
||||
self.last_capture = []
|
||||
@@ -263,7 +264,7 @@ class Board:
|
||||
played_move = self.current_move.play(move)
|
||||
try:
|
||||
self._validate_move_and_update_chains(played_move, ignore_ko)
|
||||
except IllegalMoveException as e:
|
||||
except IllegalMoveException:
|
||||
self.current_move.children = [m for m in self.current_move.children if m != played_move]
|
||||
self._init_chains() # restore
|
||||
raise
|
||||
@@ -317,12 +318,12 @@ class Board:
|
||||
|
||||
def store_analysis(self, json):
|
||||
if json["id"].startswith("PASS_"):
|
||||
id = int(json["id"].lstrip("PASS_"))
|
||||
move_id = int(json["id"].lstrip("PASS_"))
|
||||
is_pass = True
|
||||
else:
|
||||
id = int(json["id"])
|
||||
move_id = int(json["id"])
|
||||
is_pass = False
|
||||
move = self.all_moves.get(id)
|
||||
move = self.all_moves.get(move_id)
|
||||
if move: # else this should be old
|
||||
move.set_analysis(json, is_pass)
|
||||
else:
|
||||
@@ -341,7 +342,7 @@ class Board:
|
||||
return [sum([m.player == player for m in self.prisoners]) for player in [0, 1]]
|
||||
|
||||
def __repr__(self):
|
||||
return "\n".join("".join(Move.PLAYERS[self.chains[c][0].player] if c >= 0 else "-" for c in l) for l in self.board) + f"\ncaptures: {self.prisoner_count}"
|
||||
return "\n".join("".join(Move.PLAYERS[self.chains[c][0].player] if c >= 0 else "-" for c in line) for line in self.board) + f"\ncaptures: {self.prisoner_count}"
|
||||
|
||||
def write_sgf(self, komi, train_settings, file_name=None):
|
||||
def sgfify(mvs, comment=""):
|
||||
@@ -374,7 +375,7 @@ class Board:
|
||||
file_name = file_name or f"sgfout/katrain_{self.game_id}.sgf"
|
||||
try:
|
||||
os.makedirs(os.path.dirname(file_name))
|
||||
except:
|
||||
except FileExistsError:
|
||||
pass
|
||||
with open(file_name, "w") as f:
|
||||
f.write(sgfify(sgfmoves))
|
||||
|
||||
+11
-12
@@ -1,7 +1,6 @@
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import math
|
||||
import random
|
||||
import re
|
||||
import shlex
|
||||
@@ -101,7 +100,7 @@ class EngineControls(GridLayout):
|
||||
self.evaluation.text = f"{move.evaluation:.1%}"
|
||||
|
||||
# handles showing completed analysis and triggered actions like auto undo and ai move
|
||||
def update_evaluation(self, undo_triggered=False):
|
||||
def update_evaluation(self):
|
||||
current_move = self.board.current_move
|
||||
self.score.set_prisoners(self.board.prisoner_count)
|
||||
if self.eval.active(current_move.player) and current_move is not self.board.root:
|
||||
@@ -115,9 +114,9 @@ class EngineControls(GridLayout):
|
||||
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
|
||||
# TODO: is this overly generous wrt low visit outdated evaluations?
|
||||
eval = max(current_move.evaluation, current_move.outdated_evaluation or 0)
|
||||
points_lost = (current_move.parent or current_move).temperature_stats[2] * (1 - eval)
|
||||
if eval < ts["undo_eval_threshold"] and points_lost >= ts["undo_point_threshold"]:
|
||||
move_eval = max(current_move.evaluation, current_move.outdated_evaluation or 0)
|
||||
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 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"
|
||||
self.update_evaluation()
|
||||
@@ -155,11 +154,11 @@ class EngineControls(GridLayout):
|
||||
# don't play suicidal to balance score - pass when it's best
|
||||
if self.ai_balance.active and pos_moves[0][0] != "pass":
|
||||
sel_moves = [
|
||||
(move, score, eval)
|
||||
for move, score, eval in pos_moves
|
||||
if eval > ts["balance_play_randomize_eval"]
|
||||
(move, score, move_eval)
|
||||
for move, score, move_eval in pos_moves
|
||||
if move_eval > ts["balance_play_randomize_eval"]
|
||||
and -current_move.player_sign * score > 0
|
||||
or eval > ts["balance_play_min_eval"]
|
||||
or move_eval > ts["balance_play_min_eval"]
|
||||
and -current_move.player_sign * score > ts["balance_play_target_score"]
|
||||
] or sel_moves
|
||||
aimove = Move(player=self.board.current_player, gtpcoords=random.choice(sel_moves)[0], robot=True)
|
||||
@@ -189,8 +188,8 @@ class EngineControls(GridLayout):
|
||||
self.board.redo()
|
||||
self.update_evaluation()
|
||||
|
||||
def _do_redo_branch(self, dir):
|
||||
self.board.switch_branch(dir)
|
||||
def _do_redo_branch(self, direction):
|
||||
self.board.switch_branch(direction)
|
||||
self.update_evaluation()
|
||||
|
||||
def _do_init(self, board_size, komi=None):
|
||||
@@ -233,7 +232,7 @@ class EngineControls(GridLayout):
|
||||
bl.add_widget(blui)
|
||||
fileselect_popup.add_widget(bl)
|
||||
|
||||
def readfile(files, mouse):
|
||||
def readfile(files, _mouse):
|
||||
fileselect_popup.dismiss()
|
||||
self.action("analyze-sgf", self.universal_read((files[0])), cbfast.active, cbrewind.active)
|
||||
|
||||
|
||||
Reference in new issue
Block a user