aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2022-06-18 16:22:06 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2022-06-18 16:22:06 +0200
commit6527b7d98843a13bd5499ec9aaf9e9f409bf8d2f (patch)
treeaa1cf8488ae949e70c4576014bce8f0acb291300
parente9af1d809f25f6499a9aeb43264ce809118e63e8 (diff)
downloadimago-6527b7d98843a13bd5499ec9aaf9e9f409bf8d2f.tar.gz
imago-6527b7d98843a13bd5499ec9aaf9e9f409bf8d2f.zip
Handling pass annotation in sgfParser.astNode
-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):