support for reading non-utf8 sgf files / with out of range moves (weiqi101)

This commit is contained in:
Sander Land committed 2020-02-22 14:35:00 +01:00
1 parent 847eb10c7d
commit 0a91688d59
3 files changed
+15 -3

No files matched your search

+1 -1
View File
@@ -94,7 +94,7 @@ The `trainer` block has the following options to tweak:
* `balance_play_min_eval`: when needing to balance score, the AI will pick a move which is at least this good. * `balance_play_min_eval`: when needing to balance score, the AI will pick a move which is at least this good.
* `balance_play_min_visits`: never pick a move with fewer playouts than this. * `balance_play_min_visits`: never pick a move with fewer playouts than this.
* `undo_eval_threshold`, `undo_point_threshold`: prompt player to undo if move is worse than this in terms of points AND evaluation. * `undo_eval_threshold`, `undo_point_threshold`: prompt player to undo if move is worse than this in terms of points AND evaluation.
* `num_undo_prompts`: automatically undo bad moves when `undo` is on at most this many times. * `num_undo_prompts`: automatically undo bad moves when `undo` is on at most this many times. Can be a fraction like 0.5 for 50% chance of being granted an undo on a bad move.
The cfg file has additional configuration for kata. In particular, it changes the default to being more exploratory and score-based (and therefore nicer as an opponent, but weaker as analysis tool). The cfg file has additional configuration for kata. In particular, it changes the default to being more exploratory and score-based (and therefore nicer as an opponent, but weaker as analysis tool).
+2
View File
@@ -259,6 +259,8 @@ class Board:
# Play a Move from the current position, raise IllegalMoveException if invalid. # Play a Move from the current position, raise IllegalMoveException if invalid.
def play(self, move, ignore_ko=False): def play(self, move, ignore_ko=False):
if not move.is_pass and not (0 <= move.coords[0] < self.board_size and 0 <= move.coords[1] < self.board_size):
raise IllegalMoveException(f"Move {move} outside of board coordinates")
played_move = self.current_move.play(move) played_move = self.current_move.play(move)
try: try:
self._validate_move_and_update_chains(played_move, ignore_ko) self._validate_move_and_update_chains(played_move, ignore_ko)
+12 -2
View File
@@ -201,6 +201,17 @@ class EngineControls(GridLayout):
for el in [self.ai_lock.checkbox, self.hints.black, self.hints.white, self.ai_auto.black, self.ai_auto.white, self.auto_undo.black, self.auto_undo.white, self.ai_move]: for el in [self.ai_lock.checkbox, self.hints.black, self.hints.white, self.ai_auto.black, self.ai_auto.white, self.auto_undo.black, self.auto_undo.white, self.ai_move]:
el.disabled = False el.disabled = False
def universal_read(self, file):
with open(file, "rb") as f:
bin_c = f.read()
for encoding in ["utf-8", "iso-8859-1", "cp949", "GB18030"]:
try:
return bin_c.decode(encoding=encoding)
except:
pass
self.info.text = f"could not decode file contents of {file}"
return ""
def _do_analyze_sgf(self, sgf, faster=False, rewind=False): def _do_analyze_sgf(self, sgf, faster=False, rewind=False):
sgfprops = {k: v for k, v in re.findall(r"\b(\w+)\[(.*?)\]", sgf)} sgfprops = {k: v for k, v in re.findall(r"\b(\w+)\[(.*?)\]", sgf)}
size = int(sgfprops.get("SZ", self.board_size)) size = int(sgfprops.get("SZ", self.board_size))
@@ -220,8 +231,7 @@ class EngineControls(GridLayout):
def readfile(files, mouse): def readfile(files, mouse):
fileselect_popup.dismiss() fileselect_popup.dismiss()
with open(files[0]) as f: self.action("analyze-sgf", self.universal_read((files[0])), cbfast.active, cbrewind.active)
self.action("analyze-sgf", f.read(), cbfast.active, cbrewind.active)
fc.on_submit = readfile fc.on_submit = readfile
fileselect_popup.open() fileselect_popup.open()