Loading ...
Sorry, an error occurred while loading the content.

confused about http://www.red-bean.com/sgf/var.htm

Expand Messages
  • Ray Tayek
    hi, writing a parser. confused about the diagram at http://www.red-bean.com/sgf/var.htm. the doc says this is a pre-order traversal and the psuedo-code says
    Message 1 of 3 , Aug 19, 2002
    • 0 Attachment
      hi, writing a parser. confused about the diagram at
      http://www.red-bean.com/sgf/var.htm. the doc says this is a pre-order
      traversal and the psuedo-code says visit the node, then visit the children.
      the normal definition of pre-order is node, left (down) subtree, right
      (next) subtree (i am using binary trees).

      this does not give correct result. i find that one must visit the right
      (next) node before the (left) down node (otherwise, the ;C[a];C[b] would
      come out wrong). i have the diagram labeled "One variation at move 3" in
      core as:

      1-----2
      |
      3-----4-----5-----6
      |
      3'----4'

      the doc also says that "the first line of play is the main line". but the
      "line" in this case has a step in it (and could be a long staircase).

      so is the doc a bit misleading or am i perhaps confused?

      thanks

      ---
      ray tayek http://home.attbi.com/~rtayek/ actively seeking telecommuting work
      vice chair orange county java users group http://www.ocjug.org/
      mailto:chair@...
      hate spam? http://samspade.org/ssw/
    • Arno Hollosi
      ... Ok, so pre-order makes (only) sense for binary trees. In SGF multi-branch trees are possible. But the principle holds true. First the node, next the
      Message 2 of 3 , Aug 27, 2002
      • 0 Attachment
        > the normal definition of pre-order is node, left (down) subtree, right
        > (next) subtree (i am using binary trees).

        Ok, so pre-order makes (only) sense for binary trees. In SGF multi-branch
        trees are possible. But the principle holds true. First the node, next the
        subtrees.

        > this does not give correct result. i find that one must visit the right
        > (next) node before the (left) down node (otherwise, the ;C[a];C[b] would

        Ah, I see. You are implying that if you turn the diagram clockwise, then
        pre-order is left first (the variation) instead of right (the main line).

        Well, just don't look at the pictures like that :o) I think the first picture
        (the black&white one) gives the order rather nicely. And the other ones are
        correct too, if you not just turn them clock-wise but flip them once too.

        Speaking in pre-oder terminology: the main line is always the left most
        sub-tree.

        I thought the page would make variations easier to understand, rather than
        causing confusion.

        /Arno
      • Ray Tayek
        ... yes, i was confused about the sgf tree (it is not a binary tree). ... yes, the thing that threw me was that now matter how many subtrees you were in, the
        Message 3 of 3 , Aug 27, 2002
        • 0 Attachment
          At 10:48 PM 8/27/02 +0200, you wrote:
          > > the normal definition of pre-order is node, left (down) subtree, right
          > > (next) subtree (i am using binary trees).
          >
          >Ok, so pre-order makes (only) sense for binary trees. In SGF multi-branch
          >trees are possible. But the principle holds true. First the node, next the
          >subtrees.

          yes, i was confused about the sgf tree (it is not a binary tree).


          >Speaking in pre-oder terminology: the main line is always the left most
          >sub-tree.

          yes, the thing that threw me was that now matter how many subtrees you were
          in, the all end up being the main line down the binary tree.

          and printing in preorder does not do the right thing. you need to do it the
          way gnugo and smarto go do it. i ended up printing sgf the way they do (see
          below).

          the doc was very helpful. i was just confused :(

          thanks

          void toSgf(Indent indent,Writer writer)
          {
          try
          {
          writer.write(indent.indent()+'(');
          writer.write(toString());
          Node n=left;
          for(;n!=null&&n.right==null;n=n.left)
          writer.write(n.toString());
          indent.in();
          for(;n!=null;n=n.right)
          { writer.write(eoln);
          n.toSgf(indent,writer); }
          indent.out();
          writer.write(')');
          }
          catch(IOException e) { throw new RuntimeException(e); }
          }


          ---
          ray tayek http://home.attbi.com/~rtayek/ actively seeking telecommuting work
          vice chair orange county java users group http://www.ocjug.org/
          mailto:chair@...
          hate spam? http://samspade.org/ssw/
        Your message has been successfully submitted and would be delivered to recipients shortly.