~~ ABOUT ~~~~~*
KANTAN means “simple” or “easy” in that wacky Japanese language.
There doesn’t seem to be any such thing as a dedicated Ruby SGF project. I know because I’ve been looking for a few years.
If I missed one, sorry.
Anyways, I got sick of searching around, and an SGF parser applies to the project I am working on, so I broke down and wrote this.
It doesn’t do node parsing (yet).
I just upgraded it using Treetop grammar to parse the file, so a good majority of the data is pulled out now. Some of it will get refined with more internal handling, but for now enjoy!
~~ Requirements ~~~~~*
Requires the Treetop gem to run.
$ gem install treetop
~~ USAGE ~~~~~*
You pretty much run it like so:
# Load and parse
sgf = KantanSgf::Sgf.new(‘data/stoic-bojo.sgf’) sgf.parse # Pull back properties puts sgf.player_black puts sgf.player_white puts sgf.komi puts sgf.result # do some magic with the move hash for move in sgf.move_list puts “%s: (%i, %i)” % [move, move, move] end Note that the move data is stored as:
* color: 'B' or 'W'
* x, y: Integer value from 0..board_size - 1
* time: Clock time left
* ot_stones: Overtime stones