CmdrDats / igoki

Clojure Go Kifu recorder and OGS player
Eclipse Public License 1.0
162 stars 15 forks source link

Rework internal SGF represenation for simpler tree structure #22

Closed CmdrDats closed 9 years ago

CmdrDats commented 9 years ago

Currently it uses a 'easy' vector format :

[:a :b [:c [:d :g] [:h :i]] [:e :f]]

While this is optimized in the sense of efficiency, readability and exporting, it isn't great from a manipulation point of view.

A better solution would to treat each node as if the successive step has multiple branches always - so:

{:move :a
 :branches [{:move :b 
             :branches [{:move :c :branches [{:move :d :branches [{:move :g}]} 
                                             {:move :h :branches [{:move :i}]}]}
                        {:move :e :branches [{:move :f}]}]}]}

Would be the direct equivalent.

This means that sgf writing needs to add the parens only for the nodes that have >1 branches - but this is strictly an optimization, really.

The current-path would then represent each choice down every node, as opposed to the currently compact form. ie - in the vector format, to get to :i, the path was [2 2], with move-count 4 - where the new method only requires a path from root branches - [0 0 1 0] (get-in root [:branches 0 :branches 0 :branches 1 :branches 0]) and no move count required (since you always get back the node.