initial player
This commit is contained in:
1 parent
4d8956c214
commit
b6b1fe2d5b
3 files changed
+31
-10
No files matched your search
@@ -329,7 +329,7 @@ class KataGoEngine:
|
||||
"includeMovesOwnership": ownership and not next_move,
|
||||
"includePolicy": not next_move,
|
||||
"initialStones": [[m.player, m.gtp()] for m in initial_stones],
|
||||
"initialPlayer": analysis_node.root.next_player,
|
||||
"initialPlayer": analysis_node.initial_player,
|
||||
"moves": [[m.player, m.gtp()] for m in moves],
|
||||
"overrideSettings": {**settings, **(extra_settings or {})},
|
||||
}
|
||||
|
||||
@@ -300,23 +300,33 @@ class SGFNode:
|
||||
return self.__class__(parent=self, move=move)
|
||||
|
||||
@property
|
||||
def next_player(self):
|
||||
"""Returns player to move"""
|
||||
if "PL" in self.properties: # explicit
|
||||
def initial_player(self): # player for first node
|
||||
root = self.root
|
||||
if "PL" in root.properties: # explicit
|
||||
return "B" if self.get_property("PL").upper().strip() == "B" else "W"
|
||||
elif self.children: # child exist, use it if not placement
|
||||
for child in self.children:
|
||||
elif root.children: # child exist, use it if not placement
|
||||
for child in root.children:
|
||||
for color in "BW":
|
||||
if color in child.properties:
|
||||
return color
|
||||
# b move or setup with only black moves like root handicap
|
||||
if "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 handicap
|
||||
if "AB" in self.properties and "AW" not in self.properties:
|
||||
return "W"
|
||||
else:
|
||||
return "B"
|
||||
|
||||
@property
|
||||
def next_player(self):
|
||||
"""Returns player to move"""
|
||||
if self.is_root:
|
||||
return self.initial_player
|
||||
elif "B" in self.properties:
|
||||
return "W"
|
||||
elif "W" in self.properties:
|
||||
return "B"
|
||||
else: # only placements, find a parent node with a real move. TODO: better placement support
|
||||
return self.parent.next_player
|
||||
|
||||
@property
|
||||
def player(self):
|
||||
"""Returns player that moved last. nb root is considered white played if no handicap stones are placed"""
|
||||
|
||||
@@ -157,11 +157,22 @@ def test_foxwq():
|
||||
def test_next_player():
|
||||
input_sgf = "(;GM[1]FF[4]AB[aa]AW[bb])"
|
||||
assert "B" == SGF.parse_sgf(input_sgf).next_player
|
||||
assert "B" == SGF.parse_sgf(input_sgf).initial_player
|
||||
input_sgf = "(;GM[1]FF[4]AB[aa]AW[bb]PL[B])"
|
||||
assert "B" == SGF.parse_sgf(input_sgf).next_player
|
||||
assert "B" == SGF.parse_sgf(input_sgf).initial_player
|
||||
input_sgf = "(;GM[1]FF[4]AB[aa]AW[bb]PL[W])"
|
||||
assert "W" == SGF.parse_sgf(input_sgf).next_player
|
||||
assert "W" == SGF.parse_sgf(input_sgf).initial_player
|
||||
input_sgf = "(;GM[1]FF[4]AB[aa])"
|
||||
assert "W" == SGF.parse_sgf(input_sgf).next_player
|
||||
assert "W" == SGF.parse_sgf(input_sgf).initial_player
|
||||
input_sgf = "(;GM[1]FF[4]AB[aa]PL[B])"
|
||||
assert "B" == SGF.parse_sgf(input_sgf).next_player
|
||||
assert "B" == SGF.parse_sgf(input_sgf).initial_player
|
||||
input_sgf = "(;GM[1]FF[4]AB[aa];B[dd])" # branch exists
|
||||
assert "B" == SGF.parse_sgf(input_sgf).next_player
|
||||
assert "B" == SGF.parse_sgf(input_sgf).initial_player
|
||||
input_sgf = "(;GM[1]FF[4]AB[aa];W[dd])" # branch exists
|
||||
assert "W" == SGF.parse_sgf(input_sgf).next_player
|
||||
assert "W" == SGF.parse_sgf(input_sgf).initial_player
|
||||
Reference in new issue
Block a user