The sgf_moves module¶
The sgfmill.sgf_moves module contains some higher-level functions for processing moves and game positions.
(They are the sort of thing you might need to implement ‘load SGF’ and ‘save as SGF’ features in a Go-playing program.)
-
sgfmill.sgf_moves.get_setup_and_moves(sgf_game[, board])[source]¶ Return type: tuple ( Board, list of tuples (colour, move))Returns the initial setup and the following moves from an
Sgf_game.The board represents the position described by
ABand/orAWproperties in the SGF game’s root node.ValueErroris raised if this position isn’t legal.The moves are from the game’s leftmost variation. Doesn’t check that the moves are legal.
Raises
ValueErrorif the game has structure it doesn’t support.Currently doesn’t support
AB/AW/AEproperties after the root node.If the optional board parameter is provided, it must be an empty
Boardof the right size; the same object will be returned. This option is provided so you can use a different Board class (seeInterface_for_get_setup_and_movesfor what it needs to implement).See also the
show_sgf.pyexample script.
-
sgfmill.sgf_moves.set_initial_position(sgf_game, board)[source]¶ Adds
AB/AW/AEproperties to anSgf_game‘s root node, to reflect the position from aBoard.Replaces any existing
AB/AW/AEproperties in the root node.If you wish to use your own board class, see
Interface_for_set_initial_positionfor what it needs to implement.
-
sgfmill.sgf_moves.indicate_first_player(sgf_game)[source]¶ Adds a
PLproperty to anSgf_game‘s root node if appropriate, to indicate which colour is first to play.Looks at the first child of the root to see who the first player is, and sets
PLit isn’t the expected player (Black normally, but White if there is a handicap), or if there are non-handicap setup stones.