fix
This commit is contained in:
1 parent
11964617a7
commit
6854812cbe
5 files changed
+13
-14
No files matched your search
@@ -199,7 +199,7 @@ class Game:
|
||||
def __repr__(self):
|
||||
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, path=None):
|
||||
def write_sgf(self, path=None, trainer_config={}, save_feedback=(True, True, True, True, True, True)):
|
||||
black, white = self.root.get_property("PB"), self.root.get_property("PW")
|
||||
black = re.sub(r"['<>:\"/\\|?*]", "", black or "Black")
|
||||
white = re.sub(r"['<>:\"/\\|?*]", "", white or "White")
|
||||
@@ -207,9 +207,9 @@ class Game:
|
||||
file_name = os.path.join(path, f"{game_name}.sgf")
|
||||
os.makedirs(os.path.dirname(file_name), exist_ok=True)
|
||||
|
||||
show_dots_for = {p: self.katrain.config("trainer/eval_show_ai") or "ai" not in self.katrain.controls.player_mode(p) for p in Move.PLAYERS}
|
||||
show_dots_for = {p: trainer_config.get("eval_show_ai", True) or "ai" not in self.katrain.controls.player_mode(p) for p in Move.PLAYERS}
|
||||
thresholds = self.katrain.config("trainer/eval_thresholds")
|
||||
sgf = self.root.sgf(save_comments_player=show_dots_for, save_comments_class=self.katrain.config("sgf/save_feedback"), eval_thresholds=thresholds)
|
||||
sgf = self.root.sgf(save_comments_player=show_dots_for, save_comments_class=save_feedback, eval_thresholds=thresholds)
|
||||
with open(file_name, "w") as f:
|
||||
f.write(sgf)
|
||||
return f"SGF with analysis written to {file_name}"
|
||||
|
||||
+2
-2
@@ -19,10 +19,10 @@ class GameNode(SGFNode):
|
||||
self.move_number = 0
|
||||
self.undo_threshold = random.random() # for fractional undos, store the random threshold in the move itself for consistency
|
||||
|
||||
def sgf_properties(self, save_comments_player, save_comments_player_class, eval_thresholds):
|
||||
def sgf_properties(self, save_comments_player, save_comments_class, eval_thresholds):
|
||||
properties = copy.copy(super().sgf_properties())
|
||||
if self.points_lost:
|
||||
show_class = save_comments_player_class[evaluation_class(self.points_lost, eval_thresholds)]
|
||||
show_class = save_comments_class[evaluation_class(self.points_lost, eval_thresholds)]
|
||||
else:
|
||||
show_class = False
|
||||
if save_comments_player.get(self.player, False) and show_class:
|
||||
|
||||
@@ -113,7 +113,6 @@ class BadukPanWidget(Widget):
|
||||
def eval_color(self, points_lost):
|
||||
colors = self.ui_config["eval_colors"]
|
||||
i = evaluation_class(points_lost, self.trainer_config["eval_thresholds"])
|
||||
print(i, colors)
|
||||
return colors[i]
|
||||
|
||||
def draw_board(self, *_args):
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
from collections import defaultdict
|
||||
from typing import Dict, List, DefaultDict
|
||||
from typing import Dict, List, DefaultDict, Tuple, Set
|
||||
|
||||
from kivy.clock import Clock
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
@@ -29,7 +29,7 @@ class InputParseError(Exception):
|
||||
|
||||
|
||||
class QuickConfigGui(BoxLayout):
|
||||
def __init__(self, katrain: "KaTrainGui", popup: Popup, initial_values: Dict = None, **kwargs):
|
||||
def __init__(self, katrain, popup: Popup, initial_values: Dict = None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.katrain = katrain
|
||||
self.popup = popup
|
||||
@@ -76,7 +76,7 @@ class LoadSGFPopup(BoxLayout):
|
||||
|
||||
|
||||
class NewGamePopup(QuickConfigGui):
|
||||
def __init__(self, katrain: "KaTrainGui", popup: Popup, properties: Dict, **kwargs):
|
||||
def __init__(self, katrain, popup: Popup, properties: Dict, **kwargs):
|
||||
properties["RU"] = KataGoEngine.get_rules(katrain.game.root)
|
||||
super().__init__(katrain, popup, properties, **kwargs)
|
||||
self.rules_spinner.values = list(set(self.katrain.engine.RULESETS.values()))
|
||||
@@ -95,7 +95,7 @@ class NewGamePopup(QuickConfigGui):
|
||||
|
||||
|
||||
class ConfigPopup(QuickConfigGui):
|
||||
def __init__(self, katrain: "KaTrainGui", popup: Popup, config: Dict, ignore_cats: List, **kwargs):
|
||||
def __init__(self, katrain, popup: Popup, config: Dict, ignore_cats: Tuple = (), **kwargs):
|
||||
self.config = config
|
||||
self.ignore_cats = ignore_cats
|
||||
self.orientation = "vertical"
|
||||
@@ -163,8 +163,8 @@ class ConfigPopup(QuickConfigGui):
|
||||
def restart_engine(_dt):
|
||||
old_engine = self.katrain.engine # type: KataGoEngine
|
||||
new_engine = KataGoEngine(self.katrain, self.config["engine"])
|
||||
self.katrain.engine = {"B": new_engine, "W": new_engine}
|
||||
self.katrain.game.engine = new_engine
|
||||
self.katrain.engine = new_engine
|
||||
self.katrain.game.engine = {"B": new_engine, "W": new_engine}
|
||||
if getattr(old_engine, "katago_process"):
|
||||
old_engine.shutdown(finish=True)
|
||||
else:
|
||||
@@ -176,7 +176,7 @@ class ConfigPopup(QuickConfigGui):
|
||||
|
||||
|
||||
class ConfigAIPopup(QuickConfigGui):
|
||||
def __init__(self, katrain, popup, ai_modes, **kwargs):
|
||||
def __init__(self, katrain, popup: Popup, ai_modes: Set, **kwargs):
|
||||
self.settings = katrain.config("ai")
|
||||
super().__init__(katrain, popup, self.settings, **kwargs)
|
||||
self.ai_modes = ai_modes
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ class KaTrainGui(BoxLayout):
|
||||
self.game.root.set_property(
|
||||
f"P{pl}", f"AI {self.controls.ai_mode(pl)} (KataGo { os.path.splitext(model_file)[0]})" if "ai" in self.controls.player_mode(pl) else "Player"
|
||||
)
|
||||
msg = self.game.write_sgf(self.config("files/sgf_save"))
|
||||
msg = self.game.write_sgf(self.config("files/sgf_save"), trainer_config=self.config("trainer"), save_feedback=self.config("sgf/save_feedback"))
|
||||
self.log(msg, OUTPUT_INFO)
|
||||
self.controls.set_status(msg)
|
||||
|
||||
|
||||
Reference in new issue
Block a user