Understanding SGF in Go Game

保存时间:2026/4/2 16:32:12


Understanding SGF in Go Game
内容由豆包 AI 生成
in game GO, the SGF is a file format to record game playing. I wonder what does "DB" stands for. somebody says it means Delete Black. so, I assume it is white player playing turn and it deletes or remove black stones, right?
In the SGF (Smart Game Format) used for recording Go games, "DB" doesn't mean "Delete Black". Instead, "DB" stands for "Dead Black".
It's a way to mark black stones that are considered dead during the game or at the end of the game for the purpose of scoring or discussing the state of the board. It's not about a move where white deletes black stones during their turn. It's more of a notation for indicating stones that both players would agree are not going to survive and won't contribute to the final score. For instance, when players are counting the score or discussing the game's outcome, they can use "DB" to mark black stones that they believe are dead. Similarly, "DW" stands for "Dead White", which is used to mark white stones that are considered dead.
then tell me how to represent capture black stone, meaning with white stone placement to kill some black stone, what does this encoded in SGF? do you have a SGF rule specification?
In SGF (Smart Game Format) for Go, there isn't a specific tag that directly means "capture black stones". Instead, the capture of stones is implied by the normal move - recording mechanism.

1. Move Recording

Moves in SGF are typically recorded using the ; 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.
For example, ;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.

2. SGF Rule Specification

The official SGF specification can be found at http://www.red-bean.com/sgf/. Here is a basic breakdown of how a simple SGF file is structured and how moves are recorded:
plaintext
(;FF[4]GM[1]SZ[19]
;B[dd]
;W[ee]
;B[ff]
;W[gg]
)
In this example:
  • 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.
  • The subsequent lines starting with ; record the moves of the black and white players alternately.
If a white move captures black stones, it will just be another normal move record in the sequence, and the capture effect is determined by applying the rules of Go to the sequence of moves.
Here is a Python code example to parse a simple SGF file:
python
运行
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)
This code parses the basic information and move sequence from a simple SGF file. It first extracts the format version, game type, and board size, and then lists all the moves made by the black and white players.
in SGF what is ST stand for, is it game state?
In the context of the Smart Game Format (SGF), the ST property stands for "Style".
The 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.
So, 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.
Are there any other commonly used properties in SGF besides ST?
Can the ST property be customized in a SGF viewer?
How does the SGF format differ from other game file formats?