Updated README: Equal sign not required with `--mode` flag.
[sgk-go] / sgf / sgftree.h
CommitLineData
7eeb782e
AT
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see *
3 * http://www.gnu.org/software/gnugo/ for more information. *
4 * *
5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
6 * 2008 and 2009 by the Free Software Foundation. *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License as *
10 * published by the Free Software Foundation - version 3 or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License in file COPYING for more details. *
17 * *
18 * You should have received a copy of the GNU General Public *
19 * License along with this program; if not, write to the Free *
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
21 * Boston, MA 02111, USA. *
22\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23
24#ifndef _SGFTREE_H_
25#define _SGFTREE_H_
26
27#include <stdio.h>
28
29#include "sgf_properties.h"
30
31
32#ifndef _BOARD_H_
33/*
34 * NOTE: These MUST coincide with the definitions for the engine that we
35 * are using. In this case they are defined in engine/gnugo.h.
36 *
37 * The reason that we put them here within the #ifndef clause is because
38 * we want to decouple the GNU Go engine from SGF library, but we don't
39 * want to redefine these symbols if we include this file into board.h.
40 */
41
42#define EMPTY 0
43#define WHITE 1
44#define BLACK 2
45#endif
46
47
48void *xalloc(unsigned int);
49
50/*
51 * A property of an SGF node. An SGF node is described by a linked
52 * list of these.
53 */
54
55typedef struct SGFProperty_t {
56 struct SGFProperty_t *next;
57 short name;
58 char *value;
59} SGFProperty;
60
61
62typedef struct SGFNode_t {
63 SGFProperty *props;
64 struct SGFNode_t *parent;
65 struct SGFNode_t *child;
66 struct SGFNode_t *next;
67} SGFNode;
68
69
70/* low level functions */
71SGFNode *sgfPrev(SGFNode *node);
72SGFNode *sgfRoot(SGFNode *node);
73SGFNode *sgfNewNode(void);
74void sgfFreeNode(SGFNode *node);
75
76int sgfGetIntProperty(SGFNode *node, const char *name, int *value);
77int sgfGetFloatProperty(SGFNode *node, const char *name, float *value);
78int sgfGetCharProperty(SGFNode *node, const char *name, char **value);
79void sgfAddProperty(SGFNode *node, const char *name, const char *value);
80void sgfAddPropertyInt(SGFNode *node, const char *name, long val);
81void sgfAddPropertyFloat(SGFNode *node, const char *name, float val);
82void sgfOverwriteProperty(SGFNode *node, const char *name, const char *text);
83void sgfOverwritePropertyFloat(SGFNode *node, const char *name, float val);
84void sgfOverwritePropertyInt(SGFNode *node, const char *name, int val);
85void *xrealloc(void *pt, unsigned int size);
86SGFProperty *sgfMkProperty(const char *name, const char *value,
87 SGFNode *node, SGFProperty *last);
88void sgfFreeProperty(SGFProperty *prop);
89
90SGFNode *sgfAddStone(SGFNode *node, int color, int movex, int movey);
91SGFNode *sgfAddPlay(SGFNode *node, int who, int movex, int movey);
92SGFNode *sgfAddPlayLast(SGFNode *node, int who, int movex, int movey);
93
94void sgfWriteResult(SGFNode *node, float score, int overwrite);
95void sgf_write_header(SGFNode *root, int overwrite, int seed, float komi,
96 int handicap, int level, int rules);
97
98SGFNode *sgfLabel(SGFNode *node, const char *label, int i, int j);
99SGFNode *sgfLabelInt(SGFNode *node, int num, int i, int j);
100SGFNode *sgfCircle(SGFNode *node, int i, int j);
101SGFNode *sgfSquare(SGFNode *node, int i, int j);
102SGFNode *sgfTriangle(SGFNode *node, int i, int j);
103SGFNode *sgfMark(SGFNode *node, int i, int j);
104SGFNode *sgfAddComment(SGFNode *node, const char *comment);
105SGFNode *sgfBoardText(SGFNode *node, int i, int j, const char *text);
106SGFNode *sgfBoardChar(SGFNode *node, int i, int j, char c);
107SGFNode *sgfBoardNumber(SGFNode *node, int i, int j, int number);
108SGFNode *sgfStartVariant(SGFNode *node);
109SGFNode *sgfStartVariantFirst(SGFNode *node);
110SGFNode *sgfAddChild(SGFNode *node);
111
112SGFNode *sgfCreateHeaderNode(int boardsize, float komi, int handicap);
113
114/* Read SGF tree from file. */
115SGFNode *readsgffile(const char *filename);
116/* Specific solution for fuseki */
117SGFNode *readsgffilefuseki(const char *filename, int moves_per_game);
118
119/* Write SGF tree to a file. */
120int writesgf(SGFNode *root, const char *filename);
121
122
123/* ---------------------------------------------------------------- */
124/* --- SGFTree --- */
125/* ---------------------------------------------------------------- */
126
127
128typedef struct SGFTree_t {
129 SGFNode *root;
130 SGFNode *lastnode;
131} SGFTree;
132
133
134void sgftree_clear(SGFTree *tree);
135int sgftree_readfile(SGFTree *tree, const char *infilename);
136
137int sgftreeBack(SGFTree *tree);
138int sgftreeForward(SGFTree *tree);
139
140void sgftreeAddPlay(SGFTree *tree, int color, int movex, int movey);
141void sgftreeAddPlayLast(SGFTree *tree, int color, int movex, int movey);
142void sgftreeAddStone(SGFTree *tree, int color, int movex, int movey);
143void sgftreeWriteResult(SGFTree *tree, float score, int overwrite);
144SGFNode *sgftreeNodeCheck(SGFTree *tree);
145
146void sgftreeCircle(SGFTree *tree, int i, int j);
147void sgftreeSquare(SGFTree *tree, int i, int j);
148void sgftreeTriangle(SGFTree *tree, int i, int j);
149void sgftreeMark(SGFTree *tree, int i, int j);
150void sgftreeAddComment(SGFTree *tree, const char *comment);
151void sgftreeBoardText(SGFTree *tree, int i, int j, const char *text);
152void sgftreeBoardChar(SGFTree *tree, int i, int j, char c);
153void sgftreeBoardNumber(SGFTree *tree, int i, int j, int number);
154void sgftreeStartVariant(SGFTree *tree);
155void sgftreeStartVariantFirst(SGFTree *tree);
156void sgftreeCreateHeaderNode(SGFTree *tree, int boardsize, float komi,
157 int handicap);
158void sgftreeSetLastNode(SGFTree *tree, SGFNode *lastnode);
159
160
161/* ---------------------------------------------------------------- */
162/* --- Utilities --- */
163/* ---------------------------------------------------------------- */
164
165
166int get_moveX(SGFProperty *property, int boardsize);
167int get_moveY(SGFProperty *property, int boardsize);
168int get_moveXY(SGFProperty *property, int *i, int *j, int boardsize);
169
170int show_sgf_properties(SGFNode *node);
171int show_sgf_tree(SGFNode *node);
172int is_markup_node(SGFNode *node);
173int is_move_node(SGFNode *node);
174int is_pass_node(SGFNode *node, int boardsize);
175int find_move(SGFNode *node);
176
177
178#endif
179