Skip to content

Commit

Permalink
komi display, fix fox
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander Land committed Aug 28, 2020
1 parent fd67ea8 commit 341d016
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions katrain/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def update_gui(self, cn, redraw_board=False):
self.board_controls.mid_circles_container.add_widget(top)
self.board_controls.branch.disabled = not cn.parent or len(cn.parent.children) <= 1
self.controls.players["W"].captures = prisoners["W"]
self.controls.players["W"].komi = self.game.komi
self.controls.players["B"].captures = prisoners["B"]

# update engine status dot
Expand Down
4 changes: 2 additions & 2 deletions katrain/core/base_katrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def __init__(self, force_package_config=False, debug_level=0, **kwargs):
if self.debug_level >= OUTPUT_DEBUG:
Config.set("kivy", "log_enable", 1)
Config.set("kivy", "log_level", "debug")
if self.debug_level >= OUTPUT_EXTRA_DEBUG:
Config.set("kivy", "log_level", "trace")
# if self.debug_level >= OUTPUT_EXTRA_DEBUG:
# Config.set("kivy", "log_level", "trace")
self.players_info = {"B": Player("B"), "W": Player("W")}
self.reset_players()

Expand Down
5 changes: 3 additions & 2 deletions katrain/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ def request_analysis(
next_move: Optional[GameNode] = None,
extra_settings: Optional[Dict] = None,
):
moves = [m for node in analysis_node.nodes_from_root for m in node.moves]
initial_stones = analysis_node.root.placements
nodes = analysis_node.nodes_from_root
moves = [m for node in nodes for m in node.moves]
initial_stones = [m for node in nodes for m in node.placements]
if next_move:
moves.append(next_move)
if ownership is None:
Expand Down
10 changes: 8 additions & 2 deletions katrain/core/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def __init__(
self.root = move_tree
self.komi = self.root.komi
handicap = int(self.root.get_property("HA", 0))
if handicap >= 2 and not self.root.placements:
if (
handicap >= 2
and not self.root.placements
and not (not self.root.move_with_placements and self.root.children and self.root.children[0].placements)
): # not really according to sgf, and not sure if still needed, last clause for fox
self.root.place_handicap_stones(handicap)
else:
board_size = katrain.config("game/size")
Expand Down Expand Up @@ -310,7 +314,9 @@ def analyze_extra(self, mode, **kwargs):

if mode == "extra":
if kwargs.get("continuous", False):
visits = max(engine.config["max_visits"], math.ceil(cn.analysis_visits_requested * 1.25))
visits = min(
1_000_000_000, max(engine.config["max_visits"], math.ceil(cn.analysis_visits_requested * 1.25))
)
else:
visits = cn.analysis_visits_requested + engine.config["max_visits"]
self.katrain.controls.set_status(i18n._("extra analysis").format(visits=visits), STATUS_ANALYSIS)
Expand Down
10 changes: 8 additions & 2 deletions katrain/core/sgf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,15 @@ def parse_sgf(cls, input_str) -> SGFNode:
match = re.search(cls.SGF_PAT, input_str)
clipped_str = match.group() if match else input_str
root = cls(clipped_str).root
# Fix weird FoxGo server KM values
if "foxwq" in root.get_list_property("AP"):
fixed_komi = 0.5 if root.get_property("HA") == 1 else 7.5
root.set_property("KM", fixed_komi)
if int(root.get_property("HA", 0)) >= 1:
corrected_komi = 0.5
elif root.get_property("RU").lower() in ["chinese", "cn"]:
corrected_komi = 7.5
else:
corrected_komi = 6.5
root.set_property("KM", corrected_komi)
return root

@classmethod
Expand Down
15 changes: 12 additions & 3 deletions katrain/gui.kv
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,25 @@
<PlayerInfo>:
captures: 0
player: 'B'
komi: 0
player_type: 'player:human'
player_subtype: 'game:normal'
background_color: BOX_BACKGROUND_COLOR if self.active else BACKGROUND_COLOR
outline_color: BOX_BACKGROUND_COLOR
outline_width: 2
padding: [2*CP_PADDING,CP_PADDING,CP_PADDING,CP_PADDING]
CircleWithText:
player: root.player
text: str(root.captures)
BoxLayout:
size_hint: 0.32, 1
orientation: 'vertical'
CircleWithText:
player: root.player
text: str(root.captures)
Label:
size_hint: 1,0.25
halign: 'center'
valign: 'middle'
font_size: self.height
text: "%s: %.1f" % (i18n._('komi'), root.komi) if root.player=='W' else ''
BoxLayout:
size_hint: 0.75, 1
pos_hint: {'x':0,'y':0}
Expand Down
1 change: 1 addition & 0 deletions katrain/gui/kivyutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ class PlayerInfo(MDBoxLayout, BackgroundMixin):
captures = NumericProperty(0)
player = OptionProperty("B", options=["B", "W"])
player_type = StringProperty("Player")
komi = NumericProperty(0)
player_subtype = StringProperty("")
name = StringProperty("", allownone=True)
rank = StringProperty("", allownone=True)
Expand Down

0 comments on commit 341d016

Please sign in to comment.