保存时间:2026/4/2 16:32:12
; separator to mark each turn, and the B (for black) and W (for white) tags to specify the color of the player making the move, followed by the coordinates of the stone placement on the board.;B[dd] indicates that the black player places a stone at the point dd on the Go - board. If after this move, white makes a move that captures black stones, it is recorded as ;W[ef] (where ef is the coordinate of the white stone's placement). The capture is inferred from the rules of Go and the change in the board state based on the sequence of moves.(;FF[4]GM[1]SZ[19]
;B[dd]
;W[ee]
;B[ff]
;W[gg]
)
FF[4] indicates the SGF file format version 4.GM[1] specifies that the game is Go.SZ[19] sets the board size to 19x19.; record the moves of the black and white players alternately.import re
def parse_sgf(sgf_content):
# Extract the game information and moves
game_info_pattern = r"\(;FF\[(\d+)\]GM\[(\d+)\]SZ\[(\d+)\]"
match = re.search(game_info_pattern, sgf_content)
if match:
format_version = int(match.group(1))
game_type = int(match.group(2))
board_size = int(match.group(3))
print(f"Format Version: {format_version}")
print(f"Game Type: {game_type}")
print(f"Board Size: {board_size}")
move_pattern = r";([BW])\[([a-z]{2})\]"
moves = re.findall(move_pattern, sgf_content)
for color, position in moves:
print(f"Player {color}: Move at {position}")
# Example SGF content
sgf_content = "(;FF[4]GM[1]SZ[19];B[dd];W[ee];B[ff];W[gg])"
parse_sgf(sgf_content)
ST property stands for "Style".ST property is used to control how the game record should be presented or displayed. It has integer values that correspond to different display styles:ST[0]: This is the default style. It implies that the SGF viewer should use its standard or default way of presenting the game record.ST[1]: When set to 1, it often indicates that the viewer should display the main variation in a more prominent way, perhaps highlighting it or giving it a different visual treatment compared to other variations.ST[2]: A value of 2 typically means that the viewer should show all variations in a more detailed or comprehensive manner.ST is not related to the game state itself but rather to the way the game record is to be styled or presented by a SGF - compatible viewer.