Updated README: Equal sign not required with `--mode` flag.
[sgk-go] / engine / gnugo.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/* ---------------------------------------------------------------- *
25 * gnugo.h
26 * This file contains the public interface to the GNU Go engine.
27 * ---------------------------------------------------------------- */
28
29
30#ifndef _GNUGO_H_
31#define _GNUGO_H_
32
33#include "board.h"
34
35#include <stdio.h>
36
37#ifdef HAVE_CONFIG_H
38#include <config.h>
39#endif
40
41#ifdef HAVE_CRTDBG_H
42#include <crtdbg.h>
43#endif
44
45#include "sgftree.h"
46#include "clock.h"
47#include "winsocket.h"
48
49/* interface.c */
50/* Initialize the whole thing. Should be called once. */
51void init_gnugo(float memory, unsigned int random_seed);
52
53
54/* ================================================================ */
55/* some public macros used everywhere */
56/* ================================================================ */
57
58
59/* Used in matchpat.c. Have to be different from WHITE, BLACK. */
60#define ANCHOR_COLOR 6
61#define ANCHOR_OTHER 7
62
63/* Return codes for reading functions */
64
65#define WIN 5
66#define KO_A 4
67#define GAIN 3
68#define LOSS 2
69#define KO_B 1
70#define LOSE 0
71
72const char *result_to_string(int result);
73
74/* Used by break_through(). Must be different from 0 and WIN. */
75#define CUT 2
76
77
78/* Surrounded */
79
80#define SURROUNDED 1
81#define WEAKLY_SURROUNDED 2
82
83/* ================================================================ */
84/* Board manipulation */
85/* ================================================================ */
86
87
88int check_boardsize(int boardsize, FILE *out);
89void gnugo_clear_board(int boardsize);
90void gnugo_play_move(int move, int color);
91int gnugo_play_sgfnode(SGFNode *node, int to_move);
92int gnugo_sethand(int desired_handicap, SGFNode *node);
93float gnugo_estimate_score(float *upper, float *lower);
94
95/* ================================================================ */
96/* Game handling */
97/* ================================================================ */
98
99
100typedef struct {
101 int handicap;
102 int to_move; /* whose move it currently is */
103 SGFTree game_record; /* Game record in sgf format. */
104 int computer_player; /* BLACK, WHITE, or EMPTY (used as BOTH) */
105} Gameinfo;
106
107void gameinfo_clear(Gameinfo *ginfo);
108void gameinfo_print(Gameinfo *ginfo);
109int gameinfo_play_sgftree_rot(Gameinfo *gameinfo, SGFTree *tree,
110 const char *untilstr, int orientation);
111int gameinfo_play_sgftree(Gameinfo *gameinfo, SGFTree *tree,
112 const char *untilstr);
113
114
115/* ================================================================ */
116/* global variables */
117/* ================================================================ */
118
119
120/* Miscellaneous debug options. */
121extern int quiet; /* Minimal output. */
122extern int verbose; /* Bore the opponent. */
123extern int allpats; /* generate all patterns, even small ones */
124extern int printworms; /* print full data on each string */
125extern int printmoyo; /* print moyo board each move */
126extern int printdragons; /* print full data on each dragon */
127extern int printboard; /* print board each move */
128extern int showstatistics; /* print statistics */
129extern int profile_patterns; /* print statistics of pattern usage */
130extern char outfilename[128]; /* output file (-o option) */
131extern int output_flags; /* amount of output to outfile */
132
133/* output flag bits */
134#define OUTPUT_MARKDRAGONS 0x0001 /* mark dead and critical dragons */
135#define OUTPUT_MOVEVALUES 0x0002 /* output values of all moves in list */
136
137#define OUTPUT_DEFAULT 0 /* no debug output by default */
138
139/* debug flag bits */
140/* NOTE : can specify -d0x... */
141/* Please keep this list in sync with the DEBUG_FLAGS string below. */
142#define DEBUG_INFLUENCE 0x0001
143#define DEBUG_EYES 0x0002
144#define DEBUG_OWL 0x0004
145#define DEBUG_ESCAPE 0x0008
146#define DEBUG_MATCHER 0x0010
147#define DEBUG_DRAGONS 0x0020
148#define DEBUG_SEMEAI 0x0040
149#define DEBUG_LOADSGF 0x0080
150#define DEBUG_HELPER 0x0100
151#define DEBUG_READING 0x0200
152#define DEBUG_WORMS 0x0400
153#define DEBUG_MOVE_REASONS 0x0800
154#define DEBUG_OWL_PERFORMANCE 0x1000
155#define DEBUG_BREAKIN 0x2000
156#define DEBUG_FILLLIB 0x4000
157#define DEBUG_READING_PERFORMANCE 0x8000
158#define DEBUG_SCORING 0x010000
159#define DEBUG_AFTERMATH 0x020000
160#define DEBUG_ATARI_ATARI 0x040000
161#define DEBUG_READING_CACHE 0x080000
162#define DEBUG_TERRITORY 0x100000
163#define DEBUG_PERSISTENT_CACHE 0x200000
164#define DEBUG_TOP_MOVES 0x400000
165#define DEBUG_MISCELLANEOUS 0x800000
166#define DEBUG_ORACLE_STREAM 0x1000000
167#define DEBUG_LARGE_SCALE 0x1000000
168#define DEBUG_SPLIT_OWL 0x2000000
169#define DEBUG_TIME 0x4000000
170
171
172#define DEBUG_FLAGS "\
173DEBUG_INFLUENCE 0x0001\n\
174DEBUG_EYES 0x0002\n\
175DEBUG_OWL 0x0004\n\
176DEBUG_ESCAPE 0x0008\n\
177DEBUG_MATCHER 0x0010\n\
178DEBUG_DRAGONS 0x0020\n\
179DEBUG_SEMEAI 0x0040\n\
180DEBUG_LOADSGF 0x0080\n\
181DEBUG_HELPER 0x0100\n\
182DEBUG_READING 0x0200\n\
183DEBUG_WORMS 0x0400\n\
184DEBUG_MOVE_REASONS 0x0800\n\
185DEBUG_OWL_PERFORMANCE 0x1000\n\
186DEBUG_BREAKIN 0x2000\n\
187DEBUG_FILLLIB 0x4000\n\
188DEBUG_READING_PERFORMANCE 0x8000\n\
189DEBUG_SCORING 0x010000\n\
190DEBUG_AFTERMATH 0x020000\n\
191DEBUG_ATARI_ATARI 0x040000\n\
192DEBUG_READING_CACHE 0x080000\n\
193DEBUG_TERRITORY 0x100000\n\
194DEBUG_PERSISTENT_CACHE 0x200000\n\
195DEBUG_TOP_MOVES 0x400000\n\
196DEBUG_MISCELLANEOUS 0x800000\n\
197DEBUG_ORACLE_STREAM 0x1000000\n\
198DEBUG_LARGE_SCALE 0x1000000\n\
199DEBUG_SPLIT_OWL 0x2000000\n\
200DEBUG_TIME 0x4000000\n\
201"
202
203
204extern int debug; /* debug flags */
205extern int fusekidb; /* use fuseki database */
206extern int disable_fuseki; /* do not generate fuseki moves */
207extern int josekidb; /* use joseki database */
208extern int semeai_variations; /* max variations considered reading semeai */
209extern int showtime; /* print genmove time */
210extern int showscore; /* print score */
211extern int chinese_rules; /* use chinese (area) rules for counting */
212extern int experimental_owl_ext; /* use experimental owl (GAIN/LOSS) */
213extern int experimental_connections; /* use experimental connection module */
214extern int alternate_connections; /* use alternate connection module */
215extern int owl_threats; /* compute owl threats */
216extern int capture_all_dead; /* capture all dead opponent stones */
217extern int play_out_aftermath; /* make everything unconditionally settled */
218extern int resign_allowed; /* allows GG to resign hopeless games */
219extern int play_mirror_go; /* try to play mirror go if possible */
220extern int mirror_stones_limit; /* but stop at this number of stones */
221extern int gtp_version; /* version of Go Text Protocol */
222extern int use_monte_carlo_genmove; /* use Monte Carlo move generation */
223extern int mc_games_per_level; /* number of Monte Carlo simulations per level */
224
225/* Mandatory values of reading parameters. Normally -1, if set
226 * these override the values derived from the level. */
227extern int mandated_depth;
228extern int mandated_backfill_depth;
229extern int mandated_backfill2_depth;
230extern int mandated_break_chain_depth;
231extern int mandated_superstring_depth;
232extern int mandated_fourlib_depth;
233extern int mandated_ko_depth;
234extern int mandated_branch_depth;
235extern int mandated_aa_depth;
236extern int mandated_owl_distrust_depth;
237extern int mandated_owl_branch_depth;
238extern int mandated_owl_reading_depth;
239extern int mandated_owl_node_limit;
240extern int mandated_semeai_node_limit;
241
242extern int autolevel_on;
243
244extern float potential_moves[BOARDMAX];
245
246extern int oracle_exists; /* oracle is available for consultation */
247extern int metamachine; /* use metamachine_genmove */
248
249/* ================================================================ */
250/* tracing and debugging functions */
251/* ================================================================ */
252
253/* Colors. */
254#define GG_COLOR_BLACK 0
255#define GG_COLOR_RED 1
256#define GG_COLOR_GREEN 2
257#define GG_COLOR_YELLOW 3
258#define GG_COLOR_BLUE 4
259#define GG_COLOR_MAGENTA 5
260#define GG_COLOR_CYAN 6
261#define GG_COLOR_WHITE 7
262
263/* showbord.c */
264void start_draw_board(void);
265void draw_color_char(int m, int n, int c, int color);
266void draw_char(int m, int n, int c);
267void end_draw_board(void);
268void showboard(int xo); /* ascii rep. of board to stderr */
269
270
271/* influence.c */
272void debug_influence_move(int move);
273
274
275#define TRACE (!(verbose)) ? (void)0 : (void)gprintf
276
277#ifdef HAVE_VARIADIC_DEFINE
278
279/* gnuc allows variadic macros, so the tests can be done inline */
280#define DEBUG(level, fmt, args...) \
281 do { if ((debug & (level))) gprintf(fmt, ##args); } while (0)
282
283#else /*HAVE_VARIADIC_DEFINE*/
284
285/* if debug == 0, then can skip the function call. */
286#define DEBUG (!(debug)) ? (void)0 : (void)DEBUG_func
287int DEBUG_func(int level, const char *fmt, ...);
288
289#endif /*HAVE_VARIADIC_DEFINE*/
290
291
292/* genmove.c */
293#define EXAMINE_WORMS 1
294#define EXAMINE_INITIAL_INFLUENCE 2
295#define EXAMINE_DRAGONS_WITHOUT_OWL 3
296#define EXAMINE_DRAGONS 4
297#define EXAMINE_OWL_REASONS 5
298#define EXAMINE_INITIAL_INFLUENCE2 6
299#define FULL_EXAMINE_DRAGONS 7
300
301#define EXAMINE_ALL 99
302
303void reset_engine(void);
304void examine_position(int how_much, int aftermath_play);
305void silent_examine_position(int how_much);
306
307
308/* ================================================================ */
309/* statistics functions */
310/* ================================================================ */
311
312
313/* These are mostly used for GTP examination. */
314void reset_owl_node_counter(void);
315int get_owl_node_counter(void);
316void reset_reading_node_counter(void);
317int get_reading_node_counter(void);
318void reset_connection_node_counter(void);
319int get_connection_node_counter(void);
320
321
322
323/* ================================================================ */
324/* Low level functions */
325/* ================================================================ */
326
327/* utils.c */
328void who_wins(int color, FILE *outfile);
329
330/* high-level routine to generate the best move for the given color */
331int genmove(int color, float *value, int *resign);
332int genmove_conservative(int color, float *value);
333
334/* Play through the aftermath. */
335float aftermath_compute_score(int color, SGFTree *tree);
336
337/* Basic information gathering. */
338/* worm.c */
339void make_worms(void);
340void compute_worm_influence(void);
341
342/* dragon.c */
343void make_dragons(int stop_before_owl);
344void initialize_dragon_data(void);
345void show_dragons(void);
346enum dragon_status crude_status(int pos);
347enum dragon_status dragon_status(int pos);
348int same_dragon(int dr1, int dr2);
349
350/* debugging functions */
351void prepare_pattern_profiling(void);
352void report_pattern_profiling(void);
353
354/* sgffile.c */
355void sgffile_add_debuginfo(SGFNode *node, float value);
356void sgffile_output(SGFTree *tree);
357
358void sgffile_printsgf(int color_to_play, const char *filename);
359void sgffile_printboard(SGFTree *tree);
360void sgffile_recordboard(SGFNode *node);
361int get_sgfmove(SGFProperty *property);
362
363/* sgfdecide.c */
364void decide_string(int pos);
365void decide_connection(int apos, int bpos);
366void decide_owl(int pos);
367void decide_dragon_data(int pos);
368void decide_semeai(int apos, int bpos);
369void decide_tactical_semeai(int apos, int bpos);
370void decide_position(void);
371void decide_eye(int pos);
372void decide_combination(int color);
373void decide_surrounded(int pos);
374void decide_oracle(Gameinfo *gameinfo, char *infilename, char *untilstring);
375
376/*oracle.c*/
377void dismiss_oracle(void);
378void oracle_clear_board(int boardsize);
379
380#endif /* _GNUGO_H_ */
381
382
383/*
384 * Local Variables:
385 * tab-width: 8
386 * c-basic-offset: 2
387 * End:
388 */