| 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. */ |
| 51 | void 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 | |
| 72 | const 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 | |
| 88 | int check_boardsize(int boardsize, FILE *out); |
| 89 | void gnugo_clear_board(int boardsize); |
| 90 | void gnugo_play_move(int move, int color); |
| 91 | int gnugo_play_sgfnode(SGFNode *node, int to_move); |
| 92 | int gnugo_sethand(int desired_handicap, SGFNode *node); |
| 93 | float gnugo_estimate_score(float *upper, float *lower); |
| 94 | |
| 95 | /* ================================================================ */ |
| 96 | /* Game handling */ |
| 97 | /* ================================================================ */ |
| 98 | |
| 99 | |
| 100 | typedef 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 | |
| 107 | void gameinfo_clear(Gameinfo *ginfo); |
| 108 | void gameinfo_print(Gameinfo *ginfo); |
| 109 | int gameinfo_play_sgftree_rot(Gameinfo *gameinfo, SGFTree *tree, |
| 110 | const char *untilstr, int orientation); |
| 111 | int gameinfo_play_sgftree(Gameinfo *gameinfo, SGFTree *tree, |
| 112 | const char *untilstr); |
| 113 | |
| 114 | |
| 115 | /* ================================================================ */ |
| 116 | /* global variables */ |
| 117 | /* ================================================================ */ |
| 118 | |
| 119 | |
| 120 | /* Miscellaneous debug options. */ |
| 121 | extern int quiet; /* Minimal output. */ |
| 122 | extern int verbose; /* Bore the opponent. */ |
| 123 | extern int allpats; /* generate all patterns, even small ones */ |
| 124 | extern int printworms; /* print full data on each string */ |
| 125 | extern int printmoyo; /* print moyo board each move */ |
| 126 | extern int printdragons; /* print full data on each dragon */ |
| 127 | extern int printboard; /* print board each move */ |
| 128 | extern int showstatistics; /* print statistics */ |
| 129 | extern int profile_patterns; /* print statistics of pattern usage */ |
| 130 | extern char outfilename[128]; /* output file (-o option) */ |
| 131 | extern 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 "\ |
| 173 | DEBUG_INFLUENCE 0x0001\n\ |
| 174 | DEBUG_EYES 0x0002\n\ |
| 175 | DEBUG_OWL 0x0004\n\ |
| 176 | DEBUG_ESCAPE 0x0008\n\ |
| 177 | DEBUG_MATCHER 0x0010\n\ |
| 178 | DEBUG_DRAGONS 0x0020\n\ |
| 179 | DEBUG_SEMEAI 0x0040\n\ |
| 180 | DEBUG_LOADSGF 0x0080\n\ |
| 181 | DEBUG_HELPER 0x0100\n\ |
| 182 | DEBUG_READING 0x0200\n\ |
| 183 | DEBUG_WORMS 0x0400\n\ |
| 184 | DEBUG_MOVE_REASONS 0x0800\n\ |
| 185 | DEBUG_OWL_PERFORMANCE 0x1000\n\ |
| 186 | DEBUG_BREAKIN 0x2000\n\ |
| 187 | DEBUG_FILLLIB 0x4000\n\ |
| 188 | DEBUG_READING_PERFORMANCE 0x8000\n\ |
| 189 | DEBUG_SCORING 0x010000\n\ |
| 190 | DEBUG_AFTERMATH 0x020000\n\ |
| 191 | DEBUG_ATARI_ATARI 0x040000\n\ |
| 192 | DEBUG_READING_CACHE 0x080000\n\ |
| 193 | DEBUG_TERRITORY 0x100000\n\ |
| 194 | DEBUG_PERSISTENT_CACHE 0x200000\n\ |
| 195 | DEBUG_TOP_MOVES 0x400000\n\ |
| 196 | DEBUG_MISCELLANEOUS 0x800000\n\ |
| 197 | DEBUG_ORACLE_STREAM 0x1000000\n\ |
| 198 | DEBUG_LARGE_SCALE 0x1000000\n\ |
| 199 | DEBUG_SPLIT_OWL 0x2000000\n\ |
| 200 | DEBUG_TIME 0x4000000\n\ |
| 201 | " |
| 202 | |
| 203 | |
| 204 | extern int debug; /* debug flags */ |
| 205 | extern int fusekidb; /* use fuseki database */ |
| 206 | extern int disable_fuseki; /* do not generate fuseki moves */ |
| 207 | extern int josekidb; /* use joseki database */ |
| 208 | extern int semeai_variations; /* max variations considered reading semeai */ |
| 209 | extern int showtime; /* print genmove time */ |
| 210 | extern int showscore; /* print score */ |
| 211 | extern int chinese_rules; /* use chinese (area) rules for counting */ |
| 212 | extern int experimental_owl_ext; /* use experimental owl (GAIN/LOSS) */ |
| 213 | extern int experimental_connections; /* use experimental connection module */ |
| 214 | extern int alternate_connections; /* use alternate connection module */ |
| 215 | extern int owl_threats; /* compute owl threats */ |
| 216 | extern int capture_all_dead; /* capture all dead opponent stones */ |
| 217 | extern int play_out_aftermath; /* make everything unconditionally settled */ |
| 218 | extern int resign_allowed; /* allows GG to resign hopeless games */ |
| 219 | extern int play_mirror_go; /* try to play mirror go if possible */ |
| 220 | extern int mirror_stones_limit; /* but stop at this number of stones */ |
| 221 | extern int gtp_version; /* version of Go Text Protocol */ |
| 222 | extern int use_monte_carlo_genmove; /* use Monte Carlo move generation */ |
| 223 | extern 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. */ |
| 227 | extern int mandated_depth; |
| 228 | extern int mandated_backfill_depth; |
| 229 | extern int mandated_backfill2_depth; |
| 230 | extern int mandated_break_chain_depth; |
| 231 | extern int mandated_superstring_depth; |
| 232 | extern int mandated_fourlib_depth; |
| 233 | extern int mandated_ko_depth; |
| 234 | extern int mandated_branch_depth; |
| 235 | extern int mandated_aa_depth; |
| 236 | extern int mandated_owl_distrust_depth; |
| 237 | extern int mandated_owl_branch_depth; |
| 238 | extern int mandated_owl_reading_depth; |
| 239 | extern int mandated_owl_node_limit; |
| 240 | extern int mandated_semeai_node_limit; |
| 241 | |
| 242 | extern int autolevel_on; |
| 243 | |
| 244 | extern float potential_moves[BOARDMAX]; |
| 245 | |
| 246 | extern int oracle_exists; /* oracle is available for consultation */ |
| 247 | extern 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 */ |
| 264 | void start_draw_board(void); |
| 265 | void draw_color_char(int m, int n, int c, int color); |
| 266 | void draw_char(int m, int n, int c); |
| 267 | void end_draw_board(void); |
| 268 | void showboard(int xo); /* ascii rep. of board to stderr */ |
| 269 | |
| 270 | |
| 271 | /* influence.c */ |
| 272 | void 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 |
| 287 | int 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 | |
| 303 | void reset_engine(void); |
| 304 | void examine_position(int how_much, int aftermath_play); |
| 305 | void silent_examine_position(int how_much); |
| 306 | |
| 307 | |
| 308 | /* ================================================================ */ |
| 309 | /* statistics functions */ |
| 310 | /* ================================================================ */ |
| 311 | |
| 312 | |
| 313 | /* These are mostly used for GTP examination. */ |
| 314 | void reset_owl_node_counter(void); |
| 315 | int get_owl_node_counter(void); |
| 316 | void reset_reading_node_counter(void); |
| 317 | int get_reading_node_counter(void); |
| 318 | void reset_connection_node_counter(void); |
| 319 | int get_connection_node_counter(void); |
| 320 | |
| 321 | |
| 322 | |
| 323 | /* ================================================================ */ |
| 324 | /* Low level functions */ |
| 325 | /* ================================================================ */ |
| 326 | |
| 327 | /* utils.c */ |
| 328 | void who_wins(int color, FILE *outfile); |
| 329 | |
| 330 | /* high-level routine to generate the best move for the given color */ |
| 331 | int genmove(int color, float *value, int *resign); |
| 332 | int genmove_conservative(int color, float *value); |
| 333 | |
| 334 | /* Play through the aftermath. */ |
| 335 | float aftermath_compute_score(int color, SGFTree *tree); |
| 336 | |
| 337 | /* Basic information gathering. */ |
| 338 | /* worm.c */ |
| 339 | void make_worms(void); |
| 340 | void compute_worm_influence(void); |
| 341 | |
| 342 | /* dragon.c */ |
| 343 | void make_dragons(int stop_before_owl); |
| 344 | void initialize_dragon_data(void); |
| 345 | void show_dragons(void); |
| 346 | enum dragon_status crude_status(int pos); |
| 347 | enum dragon_status dragon_status(int pos); |
| 348 | int same_dragon(int dr1, int dr2); |
| 349 | |
| 350 | /* debugging functions */ |
| 351 | void prepare_pattern_profiling(void); |
| 352 | void report_pattern_profiling(void); |
| 353 | |
| 354 | /* sgffile.c */ |
| 355 | void sgffile_add_debuginfo(SGFNode *node, float value); |
| 356 | void sgffile_output(SGFTree *tree); |
| 357 | |
| 358 | void sgffile_printsgf(int color_to_play, const char *filename); |
| 359 | void sgffile_printboard(SGFTree *tree); |
| 360 | void sgffile_recordboard(SGFNode *node); |
| 361 | int get_sgfmove(SGFProperty *property); |
| 362 | |
| 363 | /* sgfdecide.c */ |
| 364 | void decide_string(int pos); |
| 365 | void decide_connection(int apos, int bpos); |
| 366 | void decide_owl(int pos); |
| 367 | void decide_dragon_data(int pos); |
| 368 | void decide_semeai(int apos, int bpos); |
| 369 | void decide_tactical_semeai(int apos, int bpos); |
| 370 | void decide_position(void); |
| 371 | void decide_eye(int pos); |
| 372 | void decide_combination(int color); |
| 373 | void decide_surrounded(int pos); |
| 374 | void decide_oracle(Gameinfo *gameinfo, char *infilename, char *untilstring); |
| 375 | |
| 376 | /*oracle.c*/ |
| 377 | void dismiss_oracle(void); |
| 378 | void 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 | */ |