fix sgf PL tag

This commit is contained in:
Sander Land committed 2020-12-16 17:54:26 +01:00
1 parent e29593517a
commit eac72f8386
4 files changed
+26 -3

No files matched your search

+1
View File
@@ -3,6 +3,7 @@
import json
import os
import kivy
kivy.require("2.0.0")
os.environ["KCFG_KIVY_LOG_LEVEL"] = os.environ.get("KCFG_KIVY_LOG_LEVEL", "warning")
+11 -2
View File
@@ -64,10 +64,15 @@ class Move:
"""Returns True if the move is a pass"""
return self.coords is None
@staticmethod
def opponent_player(player):
"""Returns the opposing player, i.e. W <-> B"""
return "W" if player == "B" else "B"
@property
def opponent(self):
"""Returns the opposing player, i.e. W <-> B"""
return "W" if self.player == "B" else "B"
return self.opponent_player(self.player)
class SGFNode:
@@ -288,7 +293,11 @@ class SGFNode:
@property
def next_player(self):
"""Returns player to move"""
if "B" in self.properties or ("AB" in self.properties and "W" not in self.properties): # root or black moved
if "PL" in self.properties: # explicit
return "B" if self.get_property("PL").upper().strip() == "B" else "W"
elif "B" in self.properties or (
"AB" in self.properties and "W" not in self.properties and "AW" not in self.properties
): # b move or setup with only black moves like root handicap
return "W"
else:
return "B"
+1 -1
View File
@@ -696,7 +696,7 @@ class BadukPanWidget(Widget):
def draw_pv(self, pv, node, up_to_move):
katrain = self.katrain
next_last_player = [node.next_player, node.player]
next_last_player = [node.next_player, Move.opponent_player(node.next_player)]
cn = katrain.game.current_node
if node != cn and node.parent != cn:
hide_node = cn
+13
View File
@@ -152,3 +152,16 @@ def test_foxwq():
while game.current_node.children:
assert 1 == len(game.current_node.children)
game.redo(1)
def test_next_player():
input_sgf = "(;GM[1]FF[4]AB[aa]AW[bb])"
assert "B" == SGF.parse_sgf(input_sgf).next_player
input_sgf = "(;GM[1]FF[4]AB[aa]AW[bb]PL[B])"
assert "B" == SGF.parse_sgf(input_sgf).next_player
input_sgf = "(;GM[1]FF[4]AB[aa]AW[bb]PL[W])"
assert "W" == SGF.parse_sgf(input_sgf).next_player
input_sgf = "(;GM[1]FF[4]AB[aa])"
assert "W" == SGF.parse_sgf(input_sgf).next_player
input_sgf = "(;GM[1]FF[4]AB[aa]PL[B])"
assert "B" == SGF.parse_sgf(input_sgf).next_player