aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--imago/sgfParser/astNode.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/imago/sgfParser/astNode.py b/imago/sgfParser/astNode.py
index f87d9c1..ff0c517 100644
--- a/imago/sgfParser/astNode.py
+++ b/imago/sgfParser/astNode.py
@@ -1,6 +1,7 @@
from imago.gameLogic.gameData import GameData
from imago.gameLogic.gameMove import GameMove
from imago.gameLogic.gameBoard import GameBoard
+from imago.data.enums import Player
class ASTNode:
"""Abstract Syntax Tree Node of SGF parser"""
@@ -67,7 +68,7 @@ class ASTNode:
gameData.roundInfo = prop.value
if prop.name == "RU": # Rules used for the game
gameData.rules = prop.value
- if prop.name == "SO": # Source of the gamw
+ if prop.name == "SO": # Source of the game
gameData.source = prop.source
if prop.name == "TM": # Time limit in seconds
gameData.timeInfo = prop.source
@@ -81,20 +82,28 @@ class ASTNode:
return GameTree(firstMoves, gameData)
def toGameMoveTree(self, previousMove=None):
- coords = None
if previousMove is None:
# Game root node
size = int(self.getPropertyValue("SZ"))
board = GameBoard(size, size)
gameMove = GameMove(board)
else:
+ coords = []
+ player = None
for prop in self.props:
if prop.name == "B" or prop.name == "W":
- coords = textToCoords(prop.value)
- gameMove = previousMove.addMoveByCoords(coords)
+ if prop.value != "tt" and prop.value != "":
+ coords = textToCoords(prop.value)
+ if prop.name == "B":
+ player = Player.BLACK
+ else:
+ player = Player.WHITE
+ if len(coords) == 2:
+ gameMove = previousMove.addMoveForPlayer(coords[0], coords[1], player)
+ else:
+ gameMove = previousMove.addPassForPlayer(player)
for child in self.children:
- newMove = child.toGameMoveTree(gameMove)
- newMove.previousMove = gameMove
+ child.toGameMoveTree(previousMove=gameMove)
return gameMove
def hasProperty(self, propertyName):