/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* This is GNU Go, a Go program. Contact gnugo@gnu.org, or see *
* http://www.gnu.org/software/gnugo/ for more information. *
* Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
* 2008 and 2009 by the Free Software Foundation. *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation - version 3 or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License in file COPYING for more details. *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02111, USA. *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
sgftree_clear(SGFTree
*tree
)
sgftree_readfile(SGFTree
*tree
, const char *infilename
)
SGFNode
*savetree
= tree
->root
;
tree
->root
= readsgffile(infilename
);
if (tree
->root
== NULL
) {
/* Go back one node in the tree. If lastnode is NULL, go to the last
* node (the one in main variant which has no children).
sgftreeBack(SGFTree
*tree
)
if (tree
->lastnode
->parent
)
tree
->lastnode
= tree
->lastnode
->parent
;
while (sgftreeForward(tree
))
/* Go forward one node in the tree. If lastnode is NULL, go to the
sgftreeForward(SGFTree
*tree
)
if (tree
->lastnode
->child
)
tree
->lastnode
= tree
->lastnode
->child
;
tree
->lastnode
= tree
->root
;
/* ================================================================ */
/* High level functions */
/* ================================================================ */
* Returns the node to modify. Use lastnode if available, otherwise
* follow the main variation to the current end of the game.
sgftreeNodeCheck(SGFTree
*tree
)
* Add a stone to the current or the given node.
* Return the node where the stone was added.
sgftreeAddStone(SGFTree
*tree
, int color
, int movex
, int movey
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
sgfAddStone(node
, color
, movex
, movey
);
* Add a move to the gametree.
sgftreeAddPlay(SGFTree
*tree
, int color
, int movex
, int movey
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
tree
->lastnode
= sgfAddPlay(node
, color
, movex
, movey
);
* Add a move to the gametree. New variations are added after the old
* ones rather than before.
sgftreeAddPlayLast(SGFTree
*tree
, int color
, int movex
, int movey
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
tree
->lastnode
= sgfAddPlayLast(node
, color
, movex
, movey
);
sgftreeCreateHeaderNode(SGFTree
*tree
, int boardsize
, float komi
, int handicap
)
SGFNode
*root
= sgfNewNode();
sgfAddPropertyInt(root
, "SZ", boardsize
);
sgfAddPropertyFloat(root
, "KM", komi
);
sgfAddPropertyInt(root
, "HA", handicap
);
* Add a comment to a gametree.
sgftreeAddComment(SGFTree
*tree
, const char *comment
)
assert(tree
&& tree
->root
);
node
= sgftreeNodeCheck(tree
);
sgfAddComment(node
, comment
);
* Place text on the board at position (i, j).
sgftreeBoardText(SGFTree
*tree
, int i
, int j
, const char *text
)
node
= sgftreeNodeCheck(tree
);
sgfBoardText(node
, i
, j
, text
);
* Place a character on the board at position (i, j).
sgftreeBoardChar(SGFTree
*tree
, int i
, int j
, char c
)
node
= sgftreeNodeCheck(tree
);
sgfBoardChar(node
, i
, j
, c
);
* Place a number on the board at position (i, j).
sgftreeBoardNumber(SGFTree
*tree
, int i
, int j
, int number
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
sgfBoardNumber(node
, i
, j
, number
);
* Place a circle mark on the board at position (i, j).
sgftreeTriangle(SGFTree
*tree
, int i
, int j
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
* Place a circle mark on the board at position (i, j).
sgftreeCircle(SGFTree
*tree
, int i
, int j
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
* Place a square mark on the board at position (i, j).
sgftreeSquare(SGFTree
*tree
, int i
, int j
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
* Place a (square) mark on the board at position (i, j).
sgftreeMark(SGFTree
*tree
, int i
, int j
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
sgftreeStartVariant(SGFTree
*tree
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
tree
->lastnode
= sgfStartVariant(node
);
* Start a new variant as first child.
sgftreeStartVariantFirst(SGFTree
*tree
)
SGFNode
*node
= sgftreeNodeCheck(tree
);
tree
->lastnode
= sgfStartVariantFirst(node
);
* Write result of the game to the game tree.
sgftreeWriteResult(SGFTree
*tree
, float score
, int overwrite
)
sgfWriteResult(tree
->root
, score
, overwrite
);
sgftreeSetLastNode(SGFTree
*tree
, SGFNode
*last_node
)
tree
->lastnode
= last_node
;