Trevoke / SGFParser

A Ruby library to parse SGF (Smart Game Format) files, best-known for holding weiqi / go game records
MIT License
35 stars 12 forks source link

each should not stop processing if block returns nil #15

Closed Tempus closed 12 years ago

Tempus commented 12 years ago

        sgf_raw = open(row["url"]).read
        puts row["url"]
        parser = SGF::Parser.new 
        tree = parser.parse sgf_raw

        tree.each do |x|
          puts x.inspect
        end

        tree.games[0].each do |x|
          puts x.inspect
        end

Output for both using http://files.gokgs.com/games/2011/11/29/andrew-ninecrane.sgf as source:

#<SGF::Node:2179137740, Children: 1, Parent: true, Properties:{"FF"=>"4", "ST"=>"2", "KM"=>"0.50", "RU"=>"Japanese", "TM"=>"900", "C"=>"andrew [3d]: hi\nninecrane [2d]: hi\n", "AP"=>"CGoban:3", "OT"=>"5x40 byo-yomi", "WR"=>"3d", "BR"=>"2d", "DT"=>"2011-11-29", "GM"=>"1", "SZ"=>"19", "PW"=>"andrew", "PB"=>"ninecrane", "CA"=>"UTF-8", "PC"=>"The KGS Go Server at http://www.gokgs.com/", "RE"=>"B+3.50”}>

Tempus commented 12 years ago

I expected game.each do |node| to return nodes starting with the topmost. Instead, if only ever returned the the topmost node. Confirmed loop only went over 1 iteration, yet .inspect showed 319 moves in my sample single branch sgf.

Trevoke commented 12 years ago

Oh, that's INTERESTING. If you write 'puts' you get nothing interesting, but if you do 'p x.inspect' instead, you do get an output. Doing 'p x' works Doing 'puts x' works but only for the first node.

Interesting stuff. The problem is not with the iterator (I think) but apparently with how I'm organizing the output. I'm still going to look into 'each' implementations just in case.

Trevoke commented 12 years ago

1.9.3p0 :006 > p 5 5 => 5 1.9.3p0 :007 > puts 5 5 => nil

It actually might well be a bug with the iteration.. I think it's the fact that it returns 'nil'.