diff options
author | Mustapha Senhaji <moos@rockbox.org> | 2009-02-11 16:03:17 +0000 |
---|---|---|
committer | Mustapha Senhaji <moos@rockbox.org> | 2009-02-11 16:03:17 +0000 |
commit | f2d5c3532fd21c04e77aa86732742b578283b697 (patch) | |
tree | 1c55cb7e69ed11391f77187c86ff8c435ed85877 /apps/plugins/goban/types.h | |
parent | 21f0c9a2829415f52b64cbdf965b01525e78f17a (diff) | |
download | rockbox-f2d5c3532fd21c04e77aa86732742b578283b697.tar.gz rockbox-f2d5c3532fd21c04e77aa86732742b578283b697.zip |
New game plugin by Joshua Simmons FS#7369: Goban plugin, Go/Igo/Weiqi/Baduk game recorder and viewer.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19972 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/goban/types.h')
-rw-r--r-- | apps/plugins/goban/types.h | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/apps/plugins/goban/types.h b/apps/plugins/goban/types.h new file mode 100644 index 0000000000..216d41bc21 --- /dev/null +++ b/apps/plugins/goban/types.h | |||
@@ -0,0 +1,289 @@ | |||
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_TYPES_H | ||
23 | #define GOBAN_TYPES_H | ||
24 | |||
25 | #include "plugin.h" | ||
26 | |||
27 | /* A generic stack sp is the stack pointer (0 for an empty stack) */ | ||
28 | struct stack_t | ||
29 | { | ||
30 | size_t size; | ||
31 | size_t sp; | ||
32 | char *buffer; | ||
33 | }; | ||
34 | |||
35 | /* All of the types of SGF properties that we understand. Not all of these | ||
36 | are handled, even if we understand them, unhandled properties are | ||
37 | handled differently (basically they are copied to a secondary location | ||
38 | and copied back if we output the tree) The ones at the end aren't real | ||
39 | SGF properties, they are only to help us in parsing/outputting/keeping | ||
40 | track of variations/etc. IMPORTANT: if you edit this, you must be | ||
41 | careful to keep it in line with prop_names, PROP_NAMES_SIZE, and | ||
42 | PROP_NAME_LEN otherwise really bad things will happen. There is too much | ||
43 | information on each of these to list here, please see | ||
44 | http://www.red-bean.com/sgf/ */ | ||
45 | enum prop_type_t | ||
46 | { | ||
47 | PROP_BLACK_MOVE, | ||
48 | PROP_WHITE_MOVE, | ||
49 | |||
50 | PROP_ADD_BLACK, | ||
51 | PROP_ADD_WHITE, | ||
52 | PROP_ADD_EMPTY, | ||
53 | |||
54 | PROP_PLAYER_TO_PLAY, | ||
55 | PROP_COMMENT, | ||
56 | |||
57 | /* information about the position reached by the current node */ | ||
58 | PROP_EVEN, | ||
59 | PROP_BLACK_GOOD, | ||
60 | PROP_WHITE_GOOD, | ||
61 | PROP_HOTSPOT, | ||
62 | PROP_UNCLEAR, | ||
63 | PROP_VALUE, | ||
64 | |||
65 | /* information about the current move */ | ||
66 | PROP_BAD, | ||
67 | PROP_DOUBTFUL, | ||
68 | PROP_INTERESTING, | ||
69 | PROP_TESUJI, | ||
70 | |||
71 | /* marks on the board */ | ||
72 | PROP_CIRCLE, | ||
73 | PROP_SQUARE, | ||
74 | PROP_TRIANGLE, | ||
75 | PROP_DIM, | ||
76 | PROP_MARK, | ||
77 | PROP_SELECTED, | ||
78 | |||
79 | /* labels go on points, names name the node */ | ||
80 | PROP_LABEL, | ||
81 | PROP_NODE_NAME, | ||
82 | |||
83 | /* root props */ | ||
84 | PROP_APPLICATION, | ||
85 | PROP_CHARSET, | ||
86 | PROP_FILE_FORMAT, | ||
87 | PROP_GAME, | ||
88 | PROP_VARIATION_TYPE, | ||
89 | PROP_SIZE, | ||
90 | |||
91 | /* game info props */ | ||
92 | PROP_ANNOTATOR, | ||
93 | PROP_BLACK_NAME, | ||
94 | PROP_WHITE_NAME, | ||
95 | PROP_HANDICAP, | ||
96 | PROP_KOMI, | ||
97 | PROP_BLACK_TERRITORY, | ||
98 | PROP_WHITE_TERRITORY, | ||
99 | PROP_BLACK_RANK, | ||
100 | PROP_WHITE_RANK, | ||
101 | PROP_BLACK_TEAM, | ||
102 | PROP_WHITE_TEAM, | ||
103 | PROP_COPYRIGHT, | ||
104 | PROP_DATE, | ||
105 | PROP_EVENT, | ||
106 | PROP_ROUND, | ||
107 | PROP_GAME_NAME, | ||
108 | PROP_GAME_COMMENT, | ||
109 | PROP_OPENING_NAME, | ||
110 | PROP_OVERTIME, | ||
111 | PROP_PLACE, | ||
112 | PROP_RESULT, | ||
113 | PROP_RULESET, | ||
114 | PROP_SOURCE, | ||
115 | PROP_TIME_LIMIT, | ||
116 | PROP_USER, | ||
117 | |||
118 | /* these are all the <whatever> left /after/ the current move */ | ||
119 | PROP_BLACK_TIME_LEFT, | ||
120 | PROP_WHITE_TIME_LEFT, | ||
121 | PROP_BLACK_STONES_LEFT, /* the number of stones left in a canadian | ||
122 | style overtime period */ | ||
123 | PROP_WHITE_STONES_LEFT, /* same for white */ | ||
124 | |||
125 | |||
126 | /* these are mostly used for printing, we don't handle these */ | ||
127 | PROP_FIGURE, | ||
128 | PROP_PRINT_MOVE_MODE, | ||
129 | |||
130 | /* view only part of the board. probably don't handle this */ | ||
131 | PROP_VIEW, | ||
132 | |||
133 | |||
134 | |||
135 | /* psuedo PROP types, used for variations and parsing and such */ | ||
136 | |||
137 | PROP_VARIATION, /* used for branches */ | ||
138 | PROP_INVALID, | ||
139 | PROP_GENERIC_UNHANDLED, /* used to mark the place where an | ||
140 | unhandled property was copied to | ||
141 | secondary storage (so we can output it | ||
142 | again when we output the game tree) */ | ||
143 | PROP_ANY, /* Used as a parameter when any property | ||
144 | type is supposed to match */ | ||
145 | PROP_VARIATION_TO_PROCESS, /* Used in parsing/outputting */ | ||
146 | PROP_VARIATION_CHOICE, /* Used to store which variation we should | ||
147 | follow when we get to a branch */ | ||
148 | PROP_ROOT_PROPS /* Marks the place where we should output | ||
149 | the information from struct header_t | ||
150 | header */ | ||
151 | }; | ||
152 | |||
153 | extern char *prop_names[]; | ||
154 | /* IMPORTANT: keep this array full of all properties that we want to be | ||
155 | able to parse out of an SGF file. This next part assumes that they go | ||
156 | before unparseable (psuedo) props in the above enum, or else we need to | ||
157 | insert placeholders in the array for unparseables */ | ||
158 | |||
159 | #define PROP_NAMES_SIZE (63) | ||
160 | |||
161 | /* The only one character property names are the moves, everything else is | ||
162 | two characters */ | ||
163 | #define PROP_NAME_LEN(type) ((type == PROP_BLACK_MOVE || \ | ||
164 | type == PROP_WHITE_MOVE) ? 1 : 2) | ||
165 | |||
166 | /* Data for a property. Can be a number, a node handle (for variations), | ||
167 | or a position and either a short or a character (the extras are for | ||
168 | label characters, and stone undo data (moves and added/removed)) */ | ||
169 | union prop_data_t | ||
170 | { | ||
171 | unsigned int number; | ||
172 | int node; | ||
173 | struct | ||
174 | { | ||
175 | unsigned short position; | ||
176 | union | ||
177 | { | ||
178 | unsigned short stone_extra; | ||
179 | unsigned char label_extra; | ||
180 | }; | ||
181 | }; | ||
182 | }; | ||
183 | |||
184 | /* What should happen when the user "plays" a move */ | ||
185 | enum play_mode_t | ||
186 | { | ||
187 | MODE_PLAY, | ||
188 | MODE_FORCE_PLAY, | ||
189 | MODE_ADD_BLACK, | ||
190 | MODE_ADD_WHITE, | ||
191 | MODE_REMOVE, | ||
192 | MODE_MARK, | ||
193 | MODE_CIRCLE, | ||
194 | MODE_SQUARE, | ||
195 | MODE_TRIANGLE, | ||
196 | MODE_LABEL | ||
197 | }; | ||
198 | |||
199 | /* Different types of board marks */ | ||
200 | enum mark_t | ||
201 | { | ||
202 | MARK_VARIATION, | ||
203 | MARK_SQUARE, | ||
204 | MARK_CIRCLE, | ||
205 | MARK_TRIANGLE, | ||
206 | MARK_LAST_MOVE, | ||
207 | MARK_LABEL | ||
208 | }; | ||
209 | |||
210 | /* An SGF property next is the handle to the next property in the node, or | ||
211 | less than zero if there isn't another */ | ||
212 | struct prop_t | ||
213 | { | ||
214 | union prop_data_t data; | ||
215 | enum prop_type_t type; | ||
216 | int next; | ||
217 | }; | ||
218 | |||
219 | |||
220 | /* The names of the rulesets, ex. "AGA", "Japanese", etc. */ | ||
221 | extern char *ruleset_names[]; | ||
222 | |||
223 | /* IMPORTANT! keep in sync with ruleset_names!!! */ | ||
224 | enum ruleset_t | ||
225 | { | ||
226 | RULESET_AGA = 0, | ||
227 | RULESET_JAPANESE, | ||
228 | RULESET_CHINESE, | ||
229 | RULESET_NEW_ZEALAND, | ||
230 | RULESET_ING, | ||
231 | __RULESETS_SIZE /* make sure i am last! */ | ||
232 | }; | ||
233 | |||
234 | #define NUM_RULESETS ((int) __RULESETS_SIZE) | ||
235 | |||
236 | |||
237 | /* One SGF node which can contain an indefinite number of SGF properties | ||
238 | Less than zero for any of these means that there is nothing in that | ||
239 | direction. */ | ||
240 | struct node_t | ||
241 | { | ||
242 | int props; | ||
243 | int next; | ||
244 | int prev; | ||
245 | }; | ||
246 | |||
247 | |||
248 | /* convenience union for keeping a mixed array of props and nodes */ | ||
249 | union storage_t | ||
250 | { | ||
251 | struct prop_t prop; | ||
252 | struct node_t node; | ||
253 | }; | ||
254 | |||
255 | |||
256 | /* The game metadata which can be stored in the SGF file */ | ||
257 | |||
258 | #define MAX_NAME 59 | ||
259 | #define MAX_EVENT 100 | ||
260 | #define MAX_RESULT 16 | ||
261 | #define MAX_RANK 10 | ||
262 | #define MAX_TEAM 32 | ||
263 | #define MAX_DATE 32 | ||
264 | #define MAX_ROUND 8 | ||
265 | #define MAX_PLACE 100 | ||
266 | #define MAX_OVERTIME 32 | ||
267 | #define MAX_RULESET 32 | ||
268 | |||
269 | struct header_t | ||
270 | { | ||
271 | char white[MAX_NAME]; | ||
272 | char black[MAX_NAME]; | ||
273 | char white_rank[MAX_RANK]; | ||
274 | char black_rank[MAX_RANK]; | ||
275 | char white_team[MAX_TEAM]; | ||
276 | char black_team[MAX_TEAM]; | ||
277 | char date[MAX_DATE]; | ||
278 | char round[MAX_ROUND]; | ||
279 | char event[MAX_EVENT]; | ||
280 | char place[MAX_PLACE]; | ||
281 | char result[MAX_RESULT]; | ||
282 | char overtime[MAX_OVERTIME]; | ||
283 | char ruleset[MAX_RULESET]; | ||
284 | int time_limit; | ||
285 | int komi; | ||
286 | uint8_t handicap; | ||
287 | }; | ||
288 | |||
289 | #endif | ||