A simple Ruby SGF parser.
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
data
examples
lib
test
web
LICENSE
README
Rakefile
kantan-sgf.gemspec

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}