def get_setup_and_moves(sgf_game, board=None): """Return the initial setup and the following moves from an Sgf_game. Returns a pair (board, plays) board -- boards.Board plays -- list of pairs (colour, move) moves are (row, col), or None for a pass. The board represents the position described by AB and/or AW properties in the root node. The moves are from the game's 'leftmost' variation. Raises ValueError if this position isn't legal. Raises ValueError if there are any AB/AW/AE properties after the root node. Doesn't check whether the moves are legal. If the optional 'board' parameter is provided, it must be an empty board of the right size; the same object will be returned. """ size = sgf_game.get_size() if board is None: board = boards.Board(size) else: if board.side != size: raise ValueError("wrong board size, must be %d" % size) if not board.is_empty(): raise ValueError("board not empty") root = sgf_game.get_root() nodes = sgf_game.main_sequence_iter() ab, aw, ae = root.get_setup_stones() if ab or aw: is_legal = board.apply_setup(ab, aw, ae) if not is_legal: raise ValueError("setup position not legal") colour, raw = root.get_raw_move() if colour is not None: raise ValueError("mixed setup and moves in root node") nodes.next() moves = [] for node in nodes: if node.has_setup_stones(): raise ValueError("setup properties after the root node") colour, raw = node.get_raw_move() if colour is not None: moves.append((colour, sgf_properties.interpret_go_point(raw, size))) return board, moves
def get_move(self): """Retrieve the move from a node. Returns a pair (colour, move) colour is 'b' or 'w'. move is (row, col), or None for a pass. Returns None, None if the node contains no B or W property. """ colour, raw = self.get_raw_move() if colour is None: return None, None return (colour, sgf_properties.interpret_go_point(raw, self._presenter.size))