Wednesday, February 26, 2014

SGF utils

As a software developer I spend great part of my time inside a text editor, in particular, Emacs. Fortunately, Go game records in SGF format are nothing but text, so I wrote some utilities to help dealing with these files.

For example:

I like to rename my SGF files in a consistent way:

[date]_[black player]_[white player]_[result].sgf

This involves parsing the SGF file and searching for the fields [DT], [PB], [PW] and [RE].
To do this I simply put the cursor over the file when in Diredmode and type

M-x sgf-rename-file-dired

where M-x means pressing the Alt key and the x.

Selecting all files in which I won or lost. In Dired mode type

M-x sgf-mark-wins

SGF files in which I won are selected

Rotate/mirror the board.

Something weird that I noticed in IGS: if you download the file directly from GoPanda2 (Pandanet client), it's rotated compared to the one you get when downloading from the web.

If curious, you can grab the code from here and here. It's in two files because one of them has the utilities, and the other is an incomplete mode that I started, that simply fulfills my needs, such as syntax highlighting, for example.