boj / kantan-sgf

A simple Ruby SGF parser.

This URL has Read+Write access

name age message
file LICENSE Thu Feb 12 02:29:39 -0800 2009 first commit for the sake of peoples sanity [boj]
file README Mon Mar 02 22:42:51 -0800 2009 added more properties, comment tracking, and mo... [boj]
file Rakefile Mon Mar 02 04:45:05 -0800 2009 preparing folder structure for gem building [boj]
directory data/ Mon Mar 02 03:39:16 -0800 2009 upgraded parser to use Treetop grammar, handles... [boj]
directory examples/ Mon Mar 02 05:17:43 -0800 2009 small nil bug in a PR[] case [boj]
file kantan-sgf.gemspec Mon Mar 02 23:54:36 -0800 2009 version 0.0.2 [boj]
directory lib/ Mon Mar 02 23:54:36 -0800 2009 version 0.0.2 [boj]
directory test/ Mon Mar 02 04:45:05 -0800 2009 preparing folder structure for gem building [boj]
directory web/ Tue Mar 03 00:03:22 -0800 2009 added google analytics for this specific page [boj]
README
~~ ABOUT ~~~~~*

Author:  Brian "bojo" Jones
Email:  mojobojo@gmail.com

KANTAN means "simple" in Japanese.

Due to the lack of standalone Ruby SGF parsers,
I ended up writing this project to help with a
few other side projects.  Hopefully it benefits
other people interested in using Ruby for their
SGF parsing related projects.

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[:color], move[:x], move[:y]]
  end
  
Note that the move data is stored as:
 * move: The current move number
 * color: 'B' or 'W'
 * x, y:  Integer value from 0..board_size - 1
 * time: Clock time left
 * ot_stones: Overtime stones
 * pass: true

Properties can be accessed directly via
sgf.properties["prop_name"].

Comments can be access via
sgf.comments # {:move, :data}