Online analysis · 02

From SGF source to a KataGo variation tree

Start with FF[4] source text, learn nodes, properties, coordinates, and variations, export from OGS, KaTrain, Sabaki, or SmartGo, then analyze the record with Read19 and KataGo.

  1. Treat SGF as a text tree first

    SGF stands for Smart Game Format. A collection can contain one or more games; each game sits inside parentheses, a semicolon starts a node, and square brackets hold the value of an uppercase property. A minimal record is (;GM[1]FF[4]SZ[19];B[pd];W[dd]).

    Five tokens explain most of the grammar: parentheses enclose a GameTree, a semicolon begins a Node, uppercase letters form a Property identifier, square brackets contain its value, and a backslash escapes structural characters inside text. Whitespace outside values is generally insignificant, while whitespace inside a value may be content. A Collection can contain several GameTrees in sequence, so one .sgf file is not necessarily one game. Treat it as a recursive syntax tree, not as a CSV-style list of moves: comments, markup, and variations belong to particular nodes.

    The complete AlphaGo game-two record also begins with (;: a GameTree containing a root node, played nodes, and any analysis branches.
  2. Read the root node and verify assumptions

    The root node after the first semicolon stores game-wide facts. FF[4] is the format version, GM[1] means Go, CA[UTF-8] declares text encoding, and SZ[19] sets board size. KM, RU, HA, PL, AB, AW, and AE define komi, rules, handicap, player to move, and the initial position.

    Root properties may appear in different orders, but their values determine the analysis premise. FF[4] and GM[1] identify an FF[4] Go record; CA[UTF-8] prevents non-ASCII comments from becoming mojibake, and AP records the producing application. SZ[19], KM[7.5], RU[Chinese], and HA[0] define the board and rules. For a handicap game, inspect HA, AB, and PL together: HA[2] without two AB setup stones still describes the wrong board. KM[0] is also a real zero value and must never be mistaken for a missing property and replaced by default komi.

    Read FF, GM, CA, and AP first, then SZ, KM, RU, HA, PL, AB, AW, and AE. Metadata is KataGo input, not decoration.
  3. Read moves: SGF coordinates are different

    B[pd] is a Black move and W[dd] is a White move. SGF counts from aa at the upper left to ss at the lower right of a 19×19 board, using consecutive lowercase letters on both axes. Unlike display coordinates, it does not skip I. In FF[4], an empty B[] or W[] is the standard pass.

    An SGF point is two lowercase letters, horizontal first and vertical second, with the origin at the upper left: aa is upper left and ss is lower right on a 19×19 board. This differs from common display coordinates in both direction and alphabet. Display coordinates usually count upward from the lower left and skip I; SGF does neither. AlphaGo's move 37 therefore appears as P10 on the board but B[oj] in the source. Empty values matter too: B[] or W[] is the standard FF[4] pass. Older 19×19 files may use tt as a compatibility pass, but new files should not emit it as the canonical form.

    One move can be board coordinate P10 and SGF property B[oj]; the two systems differ in origin, case, and whether I is skipped.
  4. Read branches and markup: the source of the variation tree

    Sequential nodes form one path; sibling parentheses after a node create branches, with the first usually treated as the main variation. C stores comments, N names nodes, TR, SQ, CR, MA, and LB mark the board, while AB, AW, and AE set up positions. The variation tree visualizes this same tree.

    Writing (;B[oj]...) (;B[dc]...) after one node creates sibling variations, and either branch may contain further nested GameTrees. Viewers commonly treat the first branch as the main line, but the stored object remains a tree rather than video progress. C[text] attaches a comment to the current node and N names it; TR, SQ, CR, MA, and LB store triangles, squares, circles, crosses, and labels. Read19 maps these node relationships into the variation tree, so returning to move 36 and opening P10, D13, or E12 means switching among child subtrees under the same parent.

    Sibling parentheses in source become branch cards in the variation tree; played, candidate, and personal lines remain separate and reversible.
  5. Export or copy SGF from common software

    OGS offers Download SGF in the completed game's side panel. KaTrain copies the current SGF with Ctrl+C. In Sabaki, use File → Save As for .sgf; it can also open GIB and NGF before conversion. SmartGo provides Save As, while SmartGo Kifu exports selected games from My Games through sharing or email.

    Export the actual game record rather than a board screenshot. OGS exposes Download SGF in the completed game's side panel. KaTrain's documented Ctrl+C shortcut places the current complete SGF on the clipboard, ready to paste into Read19. Sabaki uses File → Save As for SGF and can open GIB or NGF before conversion. SmartGo desktop provides Save As, while SmartGo Kifu lets you select games in My Games and export through sharing or email. Labels vary slightly with operating-system language and application version.

    OGS downloads, KaTrain copies, Sabaki converts GIB/NGF, and SmartGo shares; Read19 ultimately receives SGF text from each route.
  6. Import into Read19 and experiment in the variation tree

    Choose an .sgf file or paste source beginning with an opening parenthesis. Verify players, final moves, SZ, KM, RU, HA, and setup stones before a light whole-game scan. Deepen the turning points, then keep the played line, KataGo candidates, and your own reply under one fork for comparison.

    A successful parse proves only that the syntax is readable, not that the game is correct. Jump to the end and compare the final three to five moves, total move count, and result with the source game. Then inspect PB, PW, SZ, KM, RU, HA, PL, AB, AW, and AE at the root. Only after those checks should a light whole-game analysis locate swings in win rate and score lead. In the variation tree, retain AlphaGo's played P10 branch, open D13 and E12 separately, and add the reply you would naturally choose. Compare threats, sente, and weak groups rather than memorizing coordinates.

    Parse → verify metadata → scan the game → deepen turning points → compare in the variation tree: all five layers make one complete analysis.

Specifications and export references

  1. Official SGF FF[4] specification
  2. OGS: download SGF from the game side panel
  3. KaTrain: SGF clipboard shortcut
  4. Sabaki: SGF, GIB, and NGF support
  5. SmartGo saving and export help

Verify after import

  • The source begins with a valid GameTree and parses fully
  • Players, move count, and final moves match the original
  • SZ, KM, RU, HA, PL, and setup stones are correct
  • The declared encoding renders comments correctly
  • Main line and variations were not accidentally swapped
  • At least one personal reply was tested in the variation tree
Open the KataGo analysis sample