[Welcome to Sensei's Library!]

StartingPoints
ReferenceSection
About


Aliases (info)
SGF
SmartGameFormat
SmartGoFormat

Paths
DGSWishlist

Referenced by
KGSTheKiseidoGoSe...
SGFFile
TextFormattingRules
GNUGo
Kombilo
GGo
HowDiagramsWork
KogoSJosekiDictio...
PalmPilot
Jago
Ishi
GoServerDiscussion
SmartGo
LittleGolem
MessagesToPeopleC...
SGFOrganizer
WinMGT
SGFAtSLDiscussion
WikiOrphans
TheManyFacesOfGo

Homepages
Axd
Bathrmsink
Chtito
Frs
KRITZ
SteffenGlueckselig
Velobici

 

SGF file
    Keywords: Software

SGF is an abbreviation for Smart Game Format, which has become a common file format.

The SGF file format is designed to store game records of board games for two players. It's a text-only, tree-based format.

Games stored in SGF format can easily be emailed, posted or processed with text-based tools.

The main purposes of SGF are to store records of played games and to provide features for storing annotated and analyzed games (e.g. board markup, variations).

Furthermore, a lot of information about the game can be added to a SGF file:

  • Name: name of the game record
  • Size: size of the board, non square boards are supported
  • Komi: komi
  • White Name: name of the white player
  • White Rank: rank of the white player
  • Black Name: name of the black player
  • Black Rank: rank of the black player
  • White Team: name of the white team
  • Black Team: name of the black team
  • Result: result, usually in the format "B+R" (black wins by resign) or "B+3.5" (black wins by 3.5 moku)
  • Date: date of the game
  • Event: name of the event (e.g. 58th Honinbo Title Match)
  • Place: place where the game was played (e.g.: Tokyo)
  • Round: round (e.g.: 5th game)
  • Rules: ruleset (e.g.: japanese)
  • Time limit: time limit in seconds
  • Opening: information about the opening (fuseki), rarely used in any file
  • Overtime: overtime system
  • Annotations: name of the person commenting the game
  • User: name of the person who created the SGF file
  • Copyright: copyright information
  • Source: source of the file
  • Application: application that was used to create the file (e.g. CGOban2,...)

There is no strict checking of the contents of these tags, so it is possible to put any text into the result tag for example.


Most Go servers are able to send you an SGF file of a game you played. SGF files are used by many Go editing programs and are even used on rec.games.go.

Sensei's Library also uses SGF files - all the diagrams on SL can be downloaded as SGF simply by clicking on them (see How Diagrams Work).


Links


Discussion

Frs: What is the easiest way to merge two sgf files into one sgf file? The resulting sgf should contain all comments etc. from both sources. I have added comments, board markup and variants to a sgf file. My opponent has done the same. Our comments etc. are not identicial, but they are based upon the same game.

Arno: As far as I know there is no such software. I looked around for something similar about a year ago and did find nothing.

wms: I have a little command line java app that does just that. Makes the two files into separate variations off the root node. Email me if you want it, I can send it back.

TimBrent The hardball way is to take the two files and copy them, then change the copies' extention from. sgf to .txt. They can now be edited with any text editor that way (copying A.txt and pasting it into B.txt to create C.txt that can be renamed C.sgf.) Do it with copies to be safe,you'll still have the sgf files.

MK Such tool would be appreciated, if available publicly. Also another one is in need: application to divide an sgf into separate files containing only one variation, so that it would be possible to create a diagram out of it. [ext] http://senseis.xmp.net/tools/sgf2diagram.php doesn't cover variations so far...


Benjamin Geiger: I am currently writing a sgf Python parser. How common are FF[1]-[3]? Are they likely to be encountered, or is FF[4] exclusively dominant? Is it worth the extra time and code required to load, or generate, the old formats properly?

Arno: If you are writing a general purpose parser you will find no way around FF1-3. It is still in use. Heck, people still use 10 year old GoWrite 1, which produces faulty FF1.

Benjamin Geiger: On the second thought, maybe I'll just use the one that's already out there...


This is an example of a tsumego problem in sgf files format. Please note that this example comes from [ext] GoProblems. See that site for copyright information.

( ;GM[1]FF[3] RU[Japanese]SZ[19]HA[0]KM5.5 PW[White] PB[Black] GN[Copyright goproblems.com] DT[1999-07-21] SY[Cgoban 1.9.2]TM[30:00(5x1:00)] ;C[Black to play and live.] AW[bb][cb][cc][cd][de][df][cg][ch][dh][ai][bi][ci] AB[ba][ab][ac][bc][bd][be][cf][bg][bh] (;B[af];W[ah] (;B[ce];W[ag] C[only one eye this way])

(;B[ag];W[ce]) )

(;B[ah];W[af] (;B[ae];W[bf];B[ag];W[bf] (;B[af];W[ce] C[oops! you can't take this stone])

(;B[ce];W[af];B[bg] C[RIGHT black plays under the stones and lives]) )

(;B[bf];W[ae]) )

(;B[ae];W[ag])

)


Martin Kelley?: I have recently started reading r.g.g and notice that people post game records in a text format. How do I take that text and make it into a file that my sgf reader can handle? For example, the sgf text posted above; How do I put that into a reader?

Charles The answer may depend on your computer system, naturally enough. For me, I can save text as a plain text file from a word processor; and then change the file name from filename.txt to filename.sgf. Then my SGF reader will automatically open the file when I double-click it, because an association is created. It may be, in general, that an SGF reader can be asked to open any *.txt file: and will succeed.


Martin Kelley? : Thanks, Charles. I used cgoban2 (thanks WMS) and it works for both sgf and text files. Note that there are brackets missing for the komi value in the above example ;-)


Froese?: While playing around with SGFs I noticed that there is no unique representation of a given game tree. For example "(;A;B;C)" and "(;A(;B(;C)))" describe the same game tree. Should applications solely work on the defined tree or is it allowed to present data differently depending on the SGF-representation? Has anyone tested applications against the later format? It may overflow parsers...

Arno: your later variant is over-defined, as defining a sub-tree without alternatives is equivalent to having no sub-trees. SGFC normalizes SGF data and produces unique representations. However, there is no unique representation defined in the SGF standard itself. As both your variants are equivalent from their content I don't know how you would "present" them differently.

Froese?: Over-defined? I dare to disagree. I would call it the canoncial form (in contrast to the compact form). A node has properties and a list of children (sub-trees). The canonical way to write this is ";properties (child1) (child2)...". The compact form makes a special case out of nodes with a single child (";properties ;child ;child-of-child...").
Regarding "how to present differently": one example is given above - you can write the SGFs in differnt ways, preserve the canonical/compact syntax. Or, insert special "variation" markers in a tree window when seeing a sub-tree.
Sure, I wouldn't want to see an application behave like that. It should only consider the defined tree. But I found nothing in the SGF specs regarding this ambiguity and hence my question, especially the "has anyone tested apps" one. I for example, encountered stack overflows in my parser when given long games in canonical form.

(Sebastian:) You do have a point that it makes a considerable storage difference. But why is that an issue if there is no need for what you call "canonical form"? As far as I can see, this situation can only arise when you

  1. add a variation for every move,
  2. then delete each main variation,
  3. and then your program doesn't clean up nicely.

wms: Froese, I don't know where this "canonical" form term comes from. If you read the SGF spec, it does not use this term. A careful read indicates that either form is acceptable, but if you look at all the examples you will see that when a node has only one child (ie, no variations) none of the examples have the extra parenthesis. Thus, I would say that your form is not "canonical," but instead is a non-standard (but technically correct) variant form.

Froese?: Well, I introduced the term "canonical" form :-) I think it fits when talking about n-ary trees as does "compact" form for the representation of degenerated (1-ary) trees. I didn't want to raise a discussion about whether the one is better/worse/more correct then the other. I only noticed that the "compact" form is always used in the examples and wondered if that has any consequences...


Good SGF Edit(GoAssistant)


Peter Williamson? Can you put move times into a SGF file? For example, if you want to keep track of how much time remaining each player has, can you somehow put the amount of time left for each moves into SGF? I did a quick check of the spec, and I didnt' see any way to do this except comments. Is there a standard way?

axd: to store timing information, see [ext] http://www.red-bean.com/sgf/properties.html#BL



This is a copy of the living page "SGF file" at Sensei's Library.
(OC) 2004 the Authors, published under the OpenContent License V1.0.