summaryrefslogtreecommitdiff
path: root/apps/plugins/goban/sgf.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/goban/sgf.h')
-rw-r--r--apps/plugins/goban/sgf.h170
1 files changed, 170 insertions, 0 deletions
diff --git a/apps/plugins/goban/sgf.h b/apps/plugins/goban/sgf.h
new file mode 100644
index 0000000000..d2aca81ebb
--- /dev/null
+++ b/apps/plugins/goban/sgf.h
@@ -0,0 +1,170 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007-2009 Joshua Simmons <mud at majidejima dot com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef GOBAN_SGF_H
23#define GOBAN_SGF_H
24
25#include "types.h"
26
27/* Play one move. If play_mode is not PLAY_MODE_FORCE, this will fail if
28 an illegal move is played (plays by the "wrong" color are not counted
29 as illegal. pos may be a POS() on the board, or PASS_POS. Returns true
30 if the move was successfully played. */
31bool play_move_sgf (unsigned short pos, unsigned char color);
32
33/* Add a stone to the board, or remove one if color == EMPTY. returns true
34 if the stone is successfully added/removed (will return false if there
35 is nothing to add/remove there, eg. when adding a black stone when a
36 black stone is already there) */
37bool add_stone_sgf (unsigned short pos, unsigned char color);
38
39/* Add a mark to the board at the current node pos must be on the board
40 Returns false on failure. */
41bool add_mark_sgf (unsigned short pos, enum prop_type_t type);
42
43/* Returns true if there are more nodes before or after (respectively) the
44 current node */
45bool has_prev_nodes_sgf (void);
46bool has_more_nodes_sgf (void);
47
48/* When at the start of a branch, this will follow one of the branches.
49 Variations are numbered from 0. Returns false on failure. */
50bool go_to_variation_sgf (unsigned int num);
51
52/* Get the number of variations at the current move (will be 1 unless the
53 current node is a branch node */
54int num_variations_sgf (void);
55
56/* Calls into the display subsystem to mark any child variations of the
57 current node. Returns the number of variations marked */
58int mark_child_variations_sgf (void);
59
60/* Calls into the display subsystem to pass marks to be drawn on the board
61 for the current node. Does not do child variation marks. */
62void set_all_marks_sgf (void);
63
64/* Add a child regardless of if there is a child node already or not.
65 *variation_number will be set to the variation number of the added
66 variation Returns the handle of the new node. */
67int add_child_sgf (int *variation_number);
68
69/* Goes to the next variation after the current one if the current node is
70 a branch node. Returns the number of the new variation */
71int next_variation_sgf (void);
72
73/* ints in these are handles to storage locations, bools mean failure if
74 false */
75int add_prop_sgf (int node, enum prop_type_t type, union prop_data_t data);
76bool delete_prop_sgf (int node, enum prop_type_t type);
77bool delete_prop_handle_sgf (int node, int prop);
78int get_prop_sgf (int node, enum prop_type_t type, int *previous_prop);
79
80/* If there is already a property of the same type, it will be
81 overwritten, otherwise a new one is added Returns the handle of the
82 added property. */
83int add_or_set_prop_sgf (int node, enum prop_type_t type,
84 union prop_data_t data);
85
86/* Find a property of similar type with the same position in the current
87 node. (for example, if type == PROP_ADD_BLACK and pos == POS(0, 0), it
88 will find a prop with type == PROP_ADD_WHITE and pos == POS(0, 0), but
89 not any of the mark types with pos == POS(0, 0). returns the handle of
90 the found property */
91int get_prop_pos_sgf (enum prop_type_t type, union prop_data_t data);
92
93/* If there is a move in the current node, return its handle. */
94int get_move_sgf (void);
95
96/* If there is a comment in the current node, this will read it out into
97 the buffer. Returns the size of the comment read (including the '\0').
98 The buffer can be treated as a string. */
99int read_comment_sgf (char *buffer, size_t buffer_size);
100
101/* Write a comment property to the current node. This will overwrite any
102 comment that currently exists. Returns the number of characters
103 written. */
104int write_comment_sgf (char *string);
105
106/* Move forward or back in the SGF tree, following any chosen variations
107 (variations are "chosen" every time you go through one) These will
108 update the board showing any moves/added or removed stones/ marks/etc.
109 . */
110bool undo_node_sgf (void);
111bool redo_node_sgf (void);
112
113/* Returns true if the SGF property type is handled in some way. For
114 * real SGF properties (in other words, ones that can actually be read from
115 * a file, not psuedo-properties), if they are unhandled that just means that
116 * we copy them verbatim from the old file to the new, keeping them with the
117 * correct node
118 */
119bool is_handled_sgf (enum prop_type_t type);
120
121/* Sets up the handicap on the board (based on header.handicap) */
122void setup_handicap_sgf (void);
123
124/* Goes to the start of a handicap game. */
125void goto_handicap_start_sgf (void);
126
127/* Must be called after setting up a new game, either blank or loaded from
128 a file. (Picks a place to put the header properties if none was found,
129 and may do other stuff) */
130bool post_game_setup_sgf (void);
131
132/* Get the child that matches the given move.
133 *
134 * Returns the variation number of the matching move, or negative if
135 * none is found.
136 */
137int get_matching_child_sgf (unsigned short pos, unsigned char color);
138
139#define NO_NODE (-1)
140#define NO_PROP (-1)
141
142/* These flags are used in undo handling for moves and added/removed
143 stones */
144#define FLAG_ORIG_EMPTY ((uint8_t) (1 << 7))
145#define FLAG_ORIG_BLACK ((uint8_t) (1 << 6))
146#define FLAG_KO_THREAT ((uint8_t) (1 << 5))
147#define FLAG_SELF_CAP ((uint8_t) (1 << 4))
148#define FLAG_W_CAP ((uint8_t) (1 << 3))
149#define FLAG_E_CAP ((uint8_t) (1 << 2))
150#define FLAG_S_CAP ((uint8_t) (1 << 1))
151#define FLAG_N_CAP ((uint8_t) (1))
152
153#define MIN_STORAGE_BUFFER_SIZE 200
154#define UNHANDLED_PROP_LIST_FILE (PLUGIN_GAMES_DIR "/gbn_misc.bin")
155
156/* Handle of the current node, the start of the game, and the root
157 * of the tree
158 */
159extern int current_node;
160extern int tree_head;
161extern int start_node;
162
163extern int sgf_fd;
164extern int unhandled_fd;
165
166/* true if the header location has already been marked in the current
167 game, false otherwise */
168extern bool header_marked;
169
170#endif