Updated README: Equal sign not required with `--mode` flag.
[sgk-go] / engine / liberty.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 _LIBERTY_H_
25#define _LIBERTY_H_
26
27#include "board.h"
28#include "hash.h"
29#include "gnugo.h"
30#include "winsocket.h"
31
32/* ================================================================ */
33/* public variables */
34/* ================================================================ */
35
36
37/* ================================================================ */
38
39
40#define FALSE_EYE 1
41#define HALF_EYE 2
42
43
44#define REVERSE_RESULT(result) (WIN - result)
45
46
47void start_timer(int n);
48double time_report(int n, const char *occupation, int move, double mintime);
49void showstats(void);
50void clearstats(void);
51
52void transformation_init(void);
53
54void ascii_report_worm(char *string);
55void report_dragon(FILE *outfile, int pos);
56void ascii_report_dragon(char *string);
57struct dragon_data2 *dragon2_func(int pos);
58
59/* Routine names used by persistent and non-persistent caching schemes. */
60enum routine_id {
61 OWL_ATTACK,
62 OWL_DEFEND,
63 SEMEAI,
64 FIND_DEFENSE,
65 ATTACK,
66 CONNECT,
67 DISCONNECT,
68 BREAK_IN,
69 BLOCK_OFF,
70 OWL_THREATEN_ATTACK,
71 OWL_THREATEN_DEFENSE,
72 OWL_DOES_DEFEND,
73 OWL_DOES_ATTACK,
74 OWL_CONNECTION_DEFENDS,
75 OWL_SUBSTANTIAL,
76 OWL_CONFIRM_SAFETY,
77 ANALYZE_SEMEAI,
78 NUM_CACHE_ROUTINES
79};
80
81#define ROUTINE_NAMES \
82 "owl_attack", \
83 "owl_defend", \
84 "semeai", \
85 "find_defense", \
86 "attack", \
87 "connect", \
88 "disconnect", \
89 "break_in", \
90 "block_off", \
91 "owl_threaten_attack", \
92 "owl_threatend_defense", \
93 "owl_does_defend", \
94 "owl_does_attack", \
95 "owl_connection_defends", \
96 "owl_substantial", \
97 "owl_confirm_safety", \
98 "analyze_semeai"
99
100/* To prioritize between different types of reading, we give a cost
101 * ranking to each of the routines above:
102 *
103 * 4 semeai
104 * 3 owl
105 * 2 break-in
106 * 1 connection
107 * 0 tactical reading
108 *
109 * -1 is left at the end for a consistency check.
110 */
111#define ROUTINE_COSTS \
112 3, 3, 4, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, -1
113
114
115const char *routine_id_to_string(enum routine_id routine);
116
117
118/* This is used for both the dragon status and safety fields.
119 * Also used for unconditional status in struct worm_data and for the
120 * final status computed by the aftermath code.
121 */
122enum dragon_status {
123 DEAD,
124 ALIVE,
125 CRITICAL,
126 UNKNOWN,
127 UNCHECKED,
128 CAN_THREATEN_ATTACK,
129 CAN_THREATEN_DEFENSE,
130 INESSENTIAL,
131 TACTICALLY_DEAD,
132 ALIVE_IN_SEKI,
133 STRONGLY_ALIVE,
134 INVINCIBLE,
135 INSUBSTANTIAL,
136 WHITE_TERRITORY,
137 BLACK_TERRITORY,
138 DAME,
139 NUM_DRAGON_STATUS
140};
141
142#define DRAGON_STATUS_NAMES \
143 "dead", \
144 "alive", \
145 "critical", \
146 "unknown", \
147 "unchecked", \
148 "can threaten attack", \
149 "can threaten defense", \
150 "inessential", \
151 "tactically dead", \
152 "alive in seki", \
153 "strongly alive", \
154 "invincible", \
155 "insubstantial", \
156 "white_territory", \
157 "black_territory", \
158 "dame"
159
160const char *status_to_string(enum dragon_status status);
161
162
163/* Forward struct declarations. */
164struct pattern;
165struct pattern_db;
166struct fullboard_pattern;
167struct corner_pattern;
168struct corner_db;
169struct half_eye_data;
170struct movelist;
171
172/*
173 * Try to match a pattern in the database to the board. Callbacks for
174 * each match.
175 */
176typedef void (*matchpat_callback_fn_ptr)(int anchor, int color,
177 struct pattern *, int rotation,
178 void *data);
179typedef void (*fullboard_matchpat_callback_fn_ptr)(int move,
180 struct fullboard_pattern *,
181 int rotation);
182typedef void (*corner_matchpat_callback_fn_ptr)(int move, int color,
183 struct corner_pattern *pattern,
184 int trans,
185 int *stones, int num_stones);
186void matchpat(matchpat_callback_fn_ptr callback, int color,
187 struct pattern_db *pdb, void *callback_data,
188 signed char goal[BOARDMAX]);
189void matchpat_goal_anchor(matchpat_callback_fn_ptr callback, int color,
190 struct pattern_db *pdb, void *callback_data,
191 signed char goal[BOARDMAX], int anchor_in_goal);
192void fullboard_matchpat(fullboard_matchpat_callback_fn_ptr callback,
193 int color, struct fullboard_pattern *pattern);
194void corner_matchpat(corner_matchpat_callback_fn_ptr callback, int color,
195 struct corner_db *database);
196void dfa_match_init(void);
197
198void reading_cache_init(int bytes);
199void reading_cache_clear(void);
200float reading_cache_default_size(void);
201
202/* reading.c */
203int attack(int str, int *move);
204int find_defense(int str, int *move);
205int attack_and_defend(int str,
206 int *attack_code, int *attack_point,
207 int *defend_code, int *defense_point);
208int attack_either(int astr, int bstr);
209int defend_both(int astr, int bstr);
210int break_through(int apos, int bpos, int cpos);
211int attack_threats(int pos, int max_points, int moves[], int codes[]);
212
213int restricted_defend1(int str, int *move,
214 int num_forbidden_moves, int *forbidden_moves);
215int restricted_attack2(int str, int *move,
216 int num_forbidden_moves, int *forbidden_moves);
217
218int simple_ladder(int str, int *move);
219#define MOVE_ORDERING_PARAMETERS 67
220void tune_move_ordering(int params[MOVE_ORDERING_PARAMETERS]);
221void draw_reading_shadow(void);
222
223/* persistent.c */
224void persistent_cache_init(void);
225void purge_persistent_caches(void);
226void clear_persistent_caches(void);
227
228int search_persistent_reading_cache(enum routine_id routine, int str,
229 int *result, int *move);
230void store_persistent_reading_cache(enum routine_id routine, int str,
231 int result, int move, int nodes);
232void reading_hotspots(float values[BOARDMAX]);
233int search_persistent_connection_cache(enum routine_id routine,
234 int str1, int str2,
235 int *result, int *move);
236void store_persistent_connection_cache(enum routine_id routine,
237 int str1, int str2,
238 int result, int move,
239 int tactical_nodes,
240 signed char connection_shadow[BOARDMAX]);
241int search_persistent_breakin_cache(enum routine_id routine,
242 int str, Hash_data *goal_hash,
243 int breakin_node_limit,
244 int *result, int *move);
245void store_persistent_breakin_cache(enum routine_id routine,
246 int str, Hash_data *goal_hash,
247 int result, int move,
248 int tactical_nodes,
249 int breakin_node_limit,
250 signed char breakin_shadow[BOARDMAX]);
251int search_persistent_owl_cache(enum routine_id routine,
252 int apos, int bpos, int cpos,
253 int *result, int *move, int *move2,
254 int *certain);
255void store_persistent_owl_cache(enum routine_id routine,
256 int apos, int bpos, int cpos,
257 int result, int move, int move2, int certain,
258 int tactical_nodes, signed char goal[BOARDMAX],
259 int goal_color);
260void owl_hotspots(float values[BOARDMAX]);
261int search_persistent_semeai_cache(enum routine_id routine,
262 int apos, int bpos, int cpos, int color,
263 Hash_data *goal_hash,
264 int *resulta, int *resultb,
265 int *move, int *certain);
266void store_persistent_semeai_cache(enum routine_id routine,
267 int apos, int bpos, int cpos, int color,
268 Hash_data *goal_hash,
269 int resulta, int resultb,
270 int move, int certain, int tactical_nodes,
271 signed char goala[BOARDMAX],
272 signed char goalb[BOARDMAX]);
273
274
275/* readconnect.c */
276int string_connect(int str1, int str2, int *move);
277int disconnect(int str1, int str2, int *move);
278int fast_disconnect(int str1, int str2, int *move);
279int non_transitivity(int str1, int str2, int str3, int *move);
280
281int break_in(int str, const signed char goal[BOARDMAX], int *move);
282int block_off(int str1, const signed char goal[BOARDMAX], int *move);
283
284int obvious_false_eye(int pos, int color);
285void estimate_lunch_eye_value(int lunch, int *min, int *probable, int *max,
286 int appreciate_one_two_lunches);
287int owl_topological_eye(int pos, int color);
288int vital_chain(int pos);
289int confirm_safety(int move, int color, int *defense_point,
290 signed char safe_stones[BOARDMAX]);
291int dragon_weak(int pos);
292float dragon_weakness(int pos, int ignore_dead_dragons);
293int size_of_biggest_critical_dragon(void);
294void change_dragon_status(int dr, enum dragon_status status);
295float blunder_size(int move, int color, int *defense_point,
296 signed char safe_stones[BOARDMAX]);
297void set_depth_values(int level, int report_levels);
298void modify_depth_values(int n);
299void increase_depth_values(void);
300void decrease_depth_values(void);
301int get_depth_modification(void);
302
303int safe_move(int move, int color);
304int does_secure(int color, int move, int pos);
305
306void compute_new_dragons(int dragon_origins[BOARDMAX]);
307void join_dragons(int d1, int d2);
308int dragon_escape(signed char goal[BOARDMAX], int color,
309 signed char escape_value[BOARDMAX]);
310void compute_refined_dragon_weaknesses(void);
311void compute_strategic_sizes(void);
312
313struct eyevalue;
314void compute_dragon_genus(int d, struct eyevalue *genus, int eye_to_exclude);
315float crude_dragon_weakness(int safety, struct eyevalue *genus, int has_lunch,
316 float moyo_value, float escape_route);
317
318int is_same_dragon(int d1, int d2);
319int are_neighbor_dragons(int d1, int d2);
320void mark_dragon(int pos, signed char mx[BOARDMAX], signed char mark);
321int first_worm_in_dragon(int d);
322int next_worm_in_dragon(int w);
323int lively_dragon_exists(int color);
324void compute_dragon_influence(void);
325void set_strength_data(int color, signed char safe_stones[BOARDMAX],
326 float strength[BOARDMAX]);
327void mark_inessential_stones(int color, signed char safe_stones[BOARDMAX]);
328
329void add_cut(int apos, int bpos, int move);
330void cut_reasons(int color);
331
332void get_lively_stones(int color, signed char safe_stones[BOARDMAX]);
333int is_same_worm(int w1, int w2);
334int is_worm_origin(int w, int pos);
335void propagate_worm(int pos);
336void find_cuts(void);
337void find_connections(void);
338
339/* movelist.c */
340int movelist_move_known(int move, int max_points, int points[], int codes[]);
341void movelist_change_point(int move, int code, int max_points,
342 int points[], int codes[]);
343
344/* surround.c */
345int compute_surroundings(int pos, int apos, int showboard,
346 int *surround_size);
347int is_surrounded(int pos);
348int does_surround(int move, int dragon);
349void reset_surround_data(void);
350int surround_map(int dr, int pos);
351
352/* functions to add (or remove) move reasons */
353void collect_move_reasons(int color);
354
355void clear_move_reasons(void);
356void add_lunch(int eater, int food);
357void add_attack_move(int pos, int ww, int code);
358void add_defense_move(int pos, int ww, int code);
359void add_attack_threat_move(int pos, int ww, int code);
360void remove_attack_threat_move(int pos, int ww);
361void add_defense_threat_move(int pos, int ww, int code);
362void add_connection_move(int pos, int dr1, int dr2);
363void add_cut_move(int pos, int dr1, int dr2);
364void add_antisuji_move(int pos);
365void add_semeai_move(int pos, int dr);
366void add_potential_semeai_attack(int pos, int dr1, int dr2);
367void add_potential_semeai_defense(int pos, int dr1, int dr2);
368void add_semeai_threat(int pos, int dr);
369
370void add_owl_attack_move(int pos, int dr, int kworm, int code);
371void add_owl_defense_move(int pos, int dr, int code);
372void add_owl_attack_threat_move(int pos, int dr, int code);
373void add_owl_defense_threat_move(int pos, int dr, int code);
374void add_owl_prevent_threat_move(int pos, int dr);
375void add_owl_uncertain_defense_move(int pos, int dr);
376void add_owl_uncertain_attack_move(int pos, int dr);
377void add_gain_move(int pos, int target1, int target2);
378void add_loss_move(int pos, int target1, int target2);
379
380void add_my_atari_atari_move(int pos, int size);
381void add_your_atari_atari_move(int pos, int size);
382void add_vital_eye_move(int pos, int eyespace, int color);
383void add_invasion_move(int pos);
384void add_expand_territory_move(int pos);
385void add_expand_moyo_move(int pos);
386void add_strategical_attack_move(int pos, int dr);
387void add_strategical_defense_move(int pos, int dr);
388void add_worthwhile_threat_move(int pos);
389void add_replacement_move(int from, int to, int color);
390
391/* Parameters to add_either_move and add_all_move */
392#define ATTACK_STRING 1
393#define DEFEND_STRING 2
394void add_either_move(int pos, int reason1, int target1,
395 int reason2, int target2);
396void add_all_move(int pos, int reason1, int target1,
397 int reason2, int target2);
398
399int set_minimum_move_value(int pos, float value);
400void set_maximum_move_value(int pos, float value);
401void set_minimum_territorial_value(int pos, float value);
402void set_maximum_territorial_value(int pos, float value);
403void add_shape_value(int pos, float value);
404void add_followup_value(int pos, float value);
405void add_reverse_followup_value(int pos, float value);
406int list_move_reasons(FILE *out, int pos);
407void print_all_move_values(FILE *output);
408void record_top_move(int move, float val);
409void remove_top_move(int move);
410void scale_randomness(int pos, float scaling);
411void compute_move_probabilities(float probabilities[BOARDMAX]);
412
413void register_good_attack_threat(int move, int target);
414int is_known_good_attack_threat(int move, int target);
415
416void register_known_safe_move(int move);
417int is_known_safe_move(int move);
418
419int get_attack_threats(int pos, int max_strings, int strings[]);
420int get_defense_threats(int pos, int max_strings, int strings[]);
421void get_saved_worms(int pos, signed char saved[BOARDMAX]);
422void get_saved_dragons(int pos, signed char saved[BOARDMAX]);
423void mark_safe_stones(int color, int move_pos,
424 const signed char saved_dragons[BOARDMAX],
425 const signed char saved_worms[BOARDMAX],
426 signed char safe_stones[BOARDMAX]);
427
428
429int owl_lively(int pos);
430int owl_escape_value(int pos);
431int owl_goal_dragon(int pos);
432int owl_eyespace(int pos);
433int owl_big_eyespace(int pos);
434int owl_mineye(int pos);
435int owl_maxeye(int pos);
436int owl_proper_eye(int pos);
437int owl_eye_size(int pos);
438int owl_lunch(int str);
439int owl_strong_dragon(int pos);
440void owl_reasons(int color);
441
442void unconditional_life(int unconditional_territory[BOARDMAX], int color);
443void clear_unconditionally_meaningless_moves(void);
444void find_unconditionally_meaningless_moves(int unconditional_territory[BOARDMAX],
445 int color);
446int unconditionally_meaningless_move(int pos, int color,
447 int *replacement_move);
448void unconditional_move_reasons(int color);
449
450void find_superstring(int str, int *num_stones, int *stones);
451void find_superstring_conservative(int str, int *num_stones, int *stones);
452void find_superstring_liberties(int str, int *liberties, int *libs,
453 int liberty_cap);
454void find_proper_superstring_liberties(int str, int *liberties, int *libs,
455 int liberty_cap);
456void find_superstring_stones_and_liberties(int str, int *num_stones,
457 int *stones, int *liberties,
458 int *libs, int liberty_cap);
459void superstring_chainlinks(int str, int *num_adj, int adj[MAXCHAIN],
460 int liberty_cap);
461void proper_superstring_chainlinks(int str, int *num_adj,
462 int adj[MAXCHAIN], int liberty_cap);
463
464int place_fixed_handicap(int handicap); /* place stones on board only */
465int place_free_handicap(int handicap); /* place stones on board only */
466int free_handicap_remaining_stones(void);
467int free_handicap_total_stones(void);
468
469
470/* Various different strategies for finding a move */
471void fuseki(int color);
472void semeai(void);
473void semeai_move_reasons(int color);
474void shapes(int color);
475void endgame(int color);
476void endgame_shapes(int color);
477
478void combinations(int color);
479int atari_atari(int color, int *attack_move,
480 signed char defense_moves[BOARDMAX],
481 int save_verbose);
482int atari_atari_confirm_safety(int color, int tpos, int *move, int minsize,
483 const signed char saved_dragons[BOARDMAX],
484 const signed char saved_worms[BOARDMAX]);
485
486int atari_atari_blunder_size(int color, int tpos,
487 signed char defense_moves[BOARDMAX],
488 const signed char safe_stones[BOARDMAX]);
489
490int review_move_reasons(int *move, float *value, int color,
491 float pure_threat_value, float our_score,
492 int allowed_moves[BOARDMAX],
493 int use_thrashing_dragon_heuristics);
494void prepare_move_influence_debugging(int pos, int color);
495int fill_liberty(int *move, int color);
496int aftermath_genmove(int color, int do_capture_dead_stones,
497 int allowed_moves[BOARDMAX]);
498enum dragon_status aftermath_final_status(int color, int pos);
499
500int mc_get_size_of_pattern_values_table(void);
501int mc_load_patterns_from_db(const char *filename, unsigned int *values);
502void mc_init_patterns(const unsigned int *values);
503int choose_mc_patterns(char *name);
504void list_mc_patterns(void);
505
506void uct_genmove(int color, int *move, int *forbidden_moves,
507 int *allowed_moves, int nodes, float *move_values,
508 int *move_frequencies);
509
510int owl_attack(int target, int *attack_point, int *certain, int *kworm);
511int owl_defend(int target, int *defense_point, int *certain, int *kworm);
512int owl_threaten_attack(int target, int *attack1, int *attack2);
513int owl_threaten_defense(int target, int *defend1, int *defend2);
514int owl_does_defend(int move, int target, int *kworm);
515int owl_confirm_safety(int move, int target, int *defense_point, int *kworm);
516int owl_does_attack(int move, int target, int *kworm);
517int owl_connection_defends(int move, int target1, int target2);
518int owl_substantial(int str);
519void owl_analyze_semeai(int apos, int bpos,
520 int *resulta, int *resultb, int *semeai_move,
521 int owl, int *semeai_result_certain);
522void owl_analyze_semeai_after_move(int move, int color, int apos, int bpos,
523 int *resulta, int *resultb,
524 int *semeai_move, int owl,
525 int *semeai_result_certain,
526 int recompute_dragons);
527
528void set_limit_search(int value);
529void set_search_diamond(int pos);
530void reset_search_mask(void);
531void set_search_mask(int pos, int value);
532int oracle_play_move(int pos, int color);
533void consult_oracle(int color);
534void summon_oracle(void);
535void oracle_loadsgf(char *infilename, char *untilstring);
536int oracle_threatens(int move, int target);
537int within_search_area(int pos);
538int metamachine_genmove(int color, float *value);
539void draw_search_area(void);
540
541int genmove_restricted(int color, int allowed_moves[BOARDMAX]);
542
543void change_attack(int str, int move, int acode);
544void change_defense(int str, int move, int dcode);
545void change_attack_threat(int str, int move, int acode);
546void change_defense_threat(int str, int move, int dcode);
547int attack_move_known(int move, int str);
548int defense_move_known(int move, int str);
549int attack_threat_move_known(int move, int str);
550int defense_threat_move_known(int move, int str);
551void worm_reasons(int color);
552
553int semeai_move_reason_known(int move, int dr);
554
555int does_attack(int move, int str);
556int does_defend(int move, int str);
557int double_atari(int move, int color, float *value,
558 signed char safe_stones[BOARDMAX]);
559int playing_into_snapback(int move, int color);
560int play_attack_defend_n(int color, int do_attack, int num_moves, ...);
561int play_attack_defend2_n(int color, int do_attack, int num_moves, ...);
562int play_break_through_n(int color, int num_moves, ...);
563int play_connect_n(int color, int do_connect, int num_moves, ...);
564int play_lib_n(int color, int num_moves, ...);
565int cut_possible(int pos, int color);
566int defend_against(int move, int color, int apos);
567int somewhere(int color, int check_alive, int num_moves, ...);
568int visible_along_edge(int color, int apos, int bpos);
569int test_symmetry_after_move(int move, int color, int strict);
570
571/* Printmoyo values, specified by -m flag. */
572#define PRINTMOYO_TERRITORY 0x01
573#define PRINTMOYO_MOYO 0x02
574#define PRINTMOYO_AREA 0x04
575/* The following have been borrowed by the influence functions below. */
576#define PRINTMOYO_INITIAL_INFLUENCE 0x08
577#define PRINTMOYO_PRINT_INFLUENCE 0x10
578#define PRINTMOYO_NUMERIC_INFLUENCE 0x20
579#define PRINTMOYO_PERMEABILITY 0x40
580#define PRINTMOYO_STRENGTH 0x80
581#define PRINTMOYO_ATTENUATION 0x100
582#define PRINTMOYO_VALUE_TERRITORY 0x200
583
584/* These values are used to communicate whether stones are safe or
585 * have been saved, when computing influence.
586 */
587#define INFLUENCE_SAFE_STONE 1
588#define INFLUENCE_SAVED_STONE 2
589
590/* These values are used to communicate the status of stones when analyzing
591 * a move for potentially being a blunder.
592 */
593/* dead 0 */
594#define SAFE_STONE 1
595#define OWL_SAVED_STONE 2
596
597/* This format is used when exporting the moyo segmentation. */
598#define MAX_MOYOS MAX_BOARD*MAX_BOARD
599
600struct moyo_data
601{
602 int number; /* Number of moyos. */
603 int segmentation[BOARDMAX]; /* Numbers the moyos. */
604 int size[MAX_MOYOS];
605 int owner[MAX_MOYOS];
606 float territorial_value[MAX_MOYOS];
607};
608
609/* We use a forward declaration of influence_data so that the rest
610 * of the engine can reference influence data. It can only be accessed
611 * in influence.c, however!
612 */
613struct influence_data;
614extern struct influence_data initial_black_influence;
615extern struct influence_data initial_white_influence;
616extern struct influence_data move_influence;
617extern struct influence_data followup_influence;
618
619#define INITIAL_INFLUENCE(color) ((color) == WHITE ? \
620 &initial_white_influence \
621 : &initial_black_influence)
622#define OPPOSITE_INFLUENCE(color) (INITIAL_INFLUENCE(OTHER_COLOR(color)))
623
624#define DEFAULT_STRENGTH 100.0
625
626/* Influence functions. */
627void compute_influence(int color, const signed char safe_stones[BOARDMAX],
628 const float strength[BOARDMAX],
629 struct influence_data *q,
630 int move, const char *trace_message);
631void compute_followup_influence(const struct influence_data *base,
632 struct influence_data *q,
633 int move, const char *trace_message);
634void compute_escape_influence(int color,
635 const signed char safe_stones[BOARDMAX],
636 const signed char goal[BOARDMAX],
637 const float strength[BOARDMAX],
638 signed char escape_value[BOARDMAX]);
639
640float influence_delta_territory(const struct influence_data *base,
641 const struct influence_data *q, int color,
642 int move);
643int retrieve_delta_territory_cache(int pos, int color, float *move_value,
644 float *followup_value,
645 const struct influence_data *base,
646 Hash_data safety_hash);
647void store_delta_territory_cache(int pos, int color, float move_value,
648 float followup_value,
649 const struct influence_data *base,
650 Hash_data safety_hash);
651
652int whose_territory(const struct influence_data *q, int pos);
653int whose_moyo(const struct influence_data *q, int pos);
654int whose_moyo_restricted(const struct influence_data *q, int pos);
655int whose_area(const struct influence_data *q, int pos);
656float influence_territory(const struct influence_data *q, int pos, int color);
657void influence_get_territory_segmentation(struct influence_data *q,
658 struct moyo_data *moyo);
659void get_influence(const struct influence_data *q,
660 float white_influence[BOARDMAX],
661 float black_influence[BOARDMAX],
662 float white_strength[BOARDMAX],
663 float black_strength[BOARDMAX],
664 float white_attenuation[BOARDMAX],
665 float black_attenuation[BOARDMAX],
666 float white_permeability[BOARDMAX],
667 float black_permeability[BOARDMAX],
668 float territory_value[BOARDMAX],
669 int influence_regions[BOARDMAX],
670 int non_territory[BOARDMAX]);
671float influence_score(const struct influence_data *q, int chinese_rules);
672float game_status(int color);
673void influence_mark_non_territory(int pos, int color);
674int influence_considered_lively(const struct influence_data *q, int pos);
675void influence_erase_territory(struct influence_data *q, int pos, int color);
676
677void break_territories(int color_to_move, struct influence_data *q,
678 int store, int pos);
679void clear_break_in_list(void);
680void break_in_move_reasons(int color);
681
682void choose_strategy(int color, float our_score, float game_status);
683
684/* Eye space functions. */
685int is_eye_space(int pos);
686int is_proper_eye_space(int pos);
687int is_marginal_eye_space(int pos);
688int max_eye_value(int pos);
689void test_eyeshape(int eyesize, int *eye_vertices);
690int analyze_eyegraph(const char *coded_eyegraph, struct eyevalue *value,
691 char *analyzed_eyegraph);
692
693
694/* debugging support */
695void goaldump(const signed char goal[BOARDMAX]);
696void move_considered(int move, float value);
697
698
699/* Transformation stuff. */
700#define MAX_OFFSET (2*MAX_BOARD - 1) * (2*MAX_BOARD - 1)
701#define OFFSET(dx, dy)\
702 ((dy + MAX_BOARD - 1) * (2*MAX_BOARD - 1) + (dx + MAX_BOARD - 1))
703#define OFFSET_DELTA(dx, dy) (OFFSET(dx, dy) - OFFSET(0, 0))
704#define CENTER_OFFSET(offset) (offset - OFFSET(0, 0))
705#define TRANSFORM(offset, trans) (transformation[offset][trans])
706#define AFFINE_TRANSFORM(offset, trans, delta)\
707 (transformation[offset][trans] + delta)
708#define TRANSFORM2(x, y, tx, ty, trans)\
709 do {\
710 *tx = transformation2[trans][0][0] * (x) + transformation2[trans][0][1] * (y);\
711 *ty = transformation2[trans][1][0] * (x) + transformation2[trans][1][1] * (y);\
712 } while (0)
713
714
715/* ================================================================ */
716/* global variables */
717/* ================================================================ */
718
719extern int disable_threat_computation;
720extern int disable_endgame_patterns;
721extern int doing_scoring;
722
723/* Reading parameters */
724extern int depth; /* deep reading cutoff */
725extern int backfill_depth; /* deep reading cutoff */
726extern int backfill2_depth; /* deep reading cutoff */
727extern int break_chain_depth; /* deep reading cutoff */
728extern int superstring_depth; /* deep reading cutoff */
729extern int branch_depth; /* deep reading cutoff */
730extern int fourlib_depth; /* deep reading cutoff */
731extern int ko_depth; /* deep ko reading cutoff */
732extern int aa_depth; /* deep global reading cutoff */
733extern int depth_offset; /* keeps track of temporary depth changes */
734extern int owl_distrust_depth; /* below this owl trusts the optics code */
735extern int owl_branch_depth; /* below this owl tries only one variation */
736extern int owl_reading_depth; /* owl does not read below this depth */
737extern int owl_node_limit; /* maximum number of nodes considered */
738extern int semeai_branch_depth;
739extern int semeai_branch_depth2;
740extern int semeai_node_limit;
741extern int connect_depth;
742extern int connect_depth2;
743extern int connection_node_limit;
744extern int breakin_depth;
745extern int breakin_node_limit;
746extern int semeai_variations; /* max variations considered reading semeai */
747extern float best_move_values[10];
748extern int best_moves[10];
749
750extern int experimental_owl_ext; /* use experimental owl (GAIN/LOSS) */
751extern int experimental_semeai; /* use experimental semeai module */
752extern int experimental_connections; /* use experimental connection module */
753extern int alternate_connections; /* use alternate connection module */
754extern int owl_threats; /* compute owl threats */
755extern int experimental_break_in; /* use experimental module breakin.c */
756extern int cosmic_gnugo; /* use center oriented influence */
757extern int large_scale; /* seek large scale captures */
758
759extern int thrashing_dragon; /* Dead opponent's dragon trying to live */
760extern signed char thrashing_stone[BOARDMAX]; /* All thrashing stones. */
761
762extern int transformation[MAX_OFFSET][8];
763extern const int transformation2[8][2][2];
764
765
766/* Arrays pointing out the closest worms from each vertex. The first
767 * one is the closest worms of either color, the last two ones ignore
768 * worms of the other color. Beyond a certain distance from any worm
769 * no close worm is listed at all. Only the closest worm is listed
770 * and if more than one are equally close they are all listed. The
771 * number of equally close worms is given in the number_*_worms
772 * arrays. If more than MAX_CLOSE_WORMS are equally close, none is
773 * listed.
774 *
775 * See compute_effective_worm_sizes() in worm.c for details.
776 */
777#define MAX_CLOSE_WORMS 4
778extern int close_worms[BOARDMAX][MAX_CLOSE_WORMS];
779extern int number_close_worms[BOARDMAX];
780extern int close_black_worms[BOARDMAX][MAX_CLOSE_WORMS];
781extern int number_close_black_worms[BOARDMAX];
782extern int close_white_worms[BOARDMAX][MAX_CLOSE_WORMS];
783extern int number_close_white_worms[BOARDMAX];
784
785extern int false_eye_territory[BOARDMAX];
786extern int forced_backfilling_moves[BOARDMAX];
787
788extern double slowest_time; /* Timing statistics */
789extern int slowest_move;
790extern int slowest_movenum;
791extern double total_time;
792
793
794struct eyevalue {
795 unsigned char a; /* number of eyes if attacker plays first twice */
796 unsigned char b; /* number of eyes if attacker plays first */
797 unsigned char c; /* number of eyes if defender plays first */
798 unsigned char d; /* number of eyes if defender plays first twice */
799};
800
801
802struct half_eye_data {
803 float value; /* Topological eye value. */
804 unsigned char type; /* HALF_EYE or FALSE_EYE; */
805 int num_attacks; /* number of attacking points */
806 int attack_point[4]; /* the moves to attack a topological halfeye */
807 int num_defenses; /* number of defending points */
808 int defense_point[4]; /* the moves to defend a topological halfeye */
809};
810
811/* array of half-eye data */
812extern struct half_eye_data half_eye[BOARDMAX];
813
814/*
815 * data concerning a worm. A copy is kept at each vertex of the worm.
816 */
817
818#define MAX_TACTICAL_POINTS 10
819
820struct worm_data {
821 int color; /* its color */
822 int size; /* its cardinality */
823 float effective_size; /* stones and surrounding spaces */
824 int origin; /* the origin of the string. Two vertices are in */
825 /* the same worm iff they have same origin. */
826 int liberties; /* number of liberties */
827 int liberties2; /* number of second order liberties */
828 int liberties3; /* third order liberties (empty vertices at distance 3) */
829 int liberties4; /* fourth order liberties */
830 int lunch; /* if lunch != 0 then lunch points to a boundary */
831 /* worm which can be captured easily. */
832 int cutstone; /* 1=potential cutting stone; 2=cutting stone */
833 int cutstone2; /* Number of potential cuts involving the worm. */
834 int genus; /* number of connected components of the complement, less one */
835 int inessential; /* 1=inessential worm */
836 int invincible; /* 1=strongly unconditionally non-capturable */
837 enum dragon_status unconditional_status; /* ALIVE, DEAD, WHITE_TERRITORY,
838 BLACK_TERRITORY, UNKNOWN */
839
840 /* The following arrays keeps track of up to MAX_TACTICAL_POINTS
841 * different attack, defense, attack threat, and defense threat
842 * points with corresponding result codes. (0 = loss, 1 = bad ko, 2
843 * = good ko, 3 = win). The arrays are guaranteed to be sorted with
844 * respect to the codes so that the first element contains the best
845 * result.
846 */
847 int attack_points[MAX_TACTICAL_POINTS];
848 int attack_codes[MAX_TACTICAL_POINTS];
849 int defense_points[MAX_TACTICAL_POINTS];
850 int defense_codes[MAX_TACTICAL_POINTS];
851 int attack_threat_points[MAX_TACTICAL_POINTS];
852 int attack_threat_codes[MAX_TACTICAL_POINTS];
853 int defense_threat_points[MAX_TACTICAL_POINTS];
854 int defense_threat_codes[MAX_TACTICAL_POINTS];
855};
856
857extern struct worm_data worm[BOARDMAX];
858
859/* Unconditionally meaningless moves. */
860int meaningless_black_moves[BOARDMAX];
861int meaningless_white_moves[BOARDMAX];
862
863/* Surround cache (see surround.c) */
864
865#define MAX_SURROUND 10
866
867struct surround_data {
868 int dragon_number; /* number of the (surrounded) beast */
869 signed char surround_map[BOARDMAX]; /* surround map */
870};
871
872extern struct surround_data surroundings[MAX_SURROUND];
873extern int surround_pointer;
874
875/*
876 * data concerning a dragon. A copy is kept at each stone of the string.
877 */
878
879struct dragon_data {
880 int color; /* its color */
881 int id; /* the index into the dragon2 array */
882 int origin; /* the origin of the dragon. Two vertices are in the same */
883 /* dragon iff they have same origin. */
884 int size; /* size of the dragon */
885 float effective_size; /* stones and surrounding spaces */
886 enum dragon_status crude_status; /* (ALIVE, DEAD, UNKNOWN, CRITICAL) */
887 enum dragon_status status; /* best trusted status */
888};
889
890extern struct dragon_data dragon[BOARDMAX];
891
892/* Supplementary data concerning a dragon. Only one copy is stored per
893 * dragon in the dragon2 array.
894 */
895
896#define MAX_NEIGHBOR_DRAGONS 10
897
898struct dragon_data2 {
899 int origin; /* the origin of the dragon */
900 int adjacent[MAX_NEIGHBOR_DRAGONS]; /* adjacent dragons */
901 int neighbors; /* number of adjacent dragons */
902 int hostile_neighbors; /* neighbors of opposite color */
903
904 int moyo_size; /* size of surrounding influence moyo, */
905 float moyo_territorial_value; /* ...and its territorial value */
906 enum dragon_status safety; /* a more detailed status estimate */
907 float weakness; /* a continuous estimate of the dragon's safety */
908 float weakness_pre_owl; /* dragon safety based on pre-owl computations */
909 float strategic_size; /* An effective size including weakness of neighbors */
910 int escape_route; /* a measurement of likelihood of escape */
911 struct eyevalue genus; /* the number of eyes (approximately) */
912 int heye; /* coordinates of a half eye */
913 int lunch; /* if lunch != 0 then lunch points to a boundary worm which */
914 /* can be captured easily. */
915 int surround_status; /* Is it surrounded? */
916 int surround_size; /* Size of the surrounding area */
917
918 int semeais; /* number of semeais in which the dragon is involved */
919 int semeai_defense_code ;/* Result code for semeai defense. */
920 int semeai_defense_point;/* Move found by semeai code to rescue dragon */
921 int semeai_defense_certain;
922 int semeai_defense_target; /* The opponent dragon involved in the semeai */
923 int semeai_attack_code ; /* Result code for semeai attack. */
924 int semeai_attack_point; /* Move found by semeai code to kill dragon */
925 int semeai_attack_certain;
926 int semeai_attack_target; /* The opponent dragon involved in the semeai */
927 enum dragon_status owl_threat_status; /* CAN_THREATEN_ATTACK/DEFENSE */
928 enum dragon_status owl_status; /* (ALIVE, DEAD, UNKNOWN, CRITICAL, UNCHECKED) */
929 int owl_attack_point; /* vital point for attack */
930 int owl_attack_code; /* ko result code */
931 int owl_attack_certain; /* 0 if owl reading node limit is reached */
932 int owl_attack_node_count;
933 int owl_second_attack_point;/* if attacker gets both attack points, wins */
934 int owl_defense_point; /* vital point for defense */
935 int owl_defense_code; /* ko result code */
936 int owl_defense_certain; /* 0 if owl reading node limit is reached */
937 int owl_second_defense_point;/* if defender gets both attack points, wins */
938 int owl_attack_kworm; /* only valid when owl_attack_code is GAIN */
939 int owl_defense_kworm; /* only valid when owl_defense_code is LOSS */
940};
941
942/* dragon2 is dynamically allocated */
943extern int number_of_dragons;
944extern struct dragon_data2 *dragon2;
945
946/* Macros for accessing the dragon2 data with board coordinates and
947 * the dragon data with a dragon id.
948 */
949#if 1 /* Trust DRAGON2 accesses */
950#define DRAGON2(pos) dragon2[dragon[pos].id]
951#else
952struct dragon_data2 *dragon2_func(int pos);
953#define DRAGON2(pos) (*dragon2_func(pos))
954#endif
955
956#define DRAGON(d) dragon[dragon2[d].origin]
957
958extern float white_score, black_score;
959
960/* Global variables to tune strategy. */
961
962extern float minimum_value_weight;
963extern float maximum_value_weight;
964extern float invasion_malus_weight;
965extern float strategical_weight;
966extern float territorial_weight;
967extern float attack_dragon_weight;
968extern float followup_weight;
969
970struct aftermath_data {
971 int white_captured;
972 int black_captured;
973 int white_prisoners;
974 int black_prisoners;
975 int white_territory;
976 int black_territory;
977 int white_area;
978 int black_area;
979 int white_control[BOARDMAX];
980 int black_control[BOARDMAX];
981 enum dragon_status final_status[BOARDMAX];
982};
983
984#define MAX_EYE_ATTACKS 3
985
986struct eye_data {
987 int color; /* BLACK, WHITE, or GRAY */
988 int esize; /* size of the eyespace */
989 int msize; /* number of marginal vertices */
990 int origin; /* The origin */
991 struct eyevalue value; /* Number of eyes. */
992
993 /* The above fields are constant on the whole eyespace. */
994 /* ---------------------------------------------------------------- */
995 /* The below fields are not. */
996
997 unsigned char marginal; /* This vertex is marginal */
998 unsigned char neighbors; /* number of neighbors in eyespace */
999 unsigned char marginal_neighbors; /* number of marginal neighbors */
1000};
1001
1002struct vital_eye_points {
1003 int attack_points[MAX_EYE_ATTACKS];
1004 int defense_points[MAX_EYE_ATTACKS];
1005};
1006
1007extern struct vital_eye_points black_vital_points[BOARDMAX];
1008extern struct vital_eye_points white_vital_points[BOARDMAX];
1009
1010extern struct eye_data white_eye[BOARDMAX];
1011extern struct eye_data black_eye[BOARDMAX];
1012
1013/* Array with the information which was previously stored in the cut
1014 * field and in the INHIBIT_CONNECTION bit of the type field in struct
1015 * eye_data.
1016 */
1017extern int cutting_points[BOARDMAX];
1018
1019/* The following declarations have to be postponed until after the
1020 * definition of struct eye_data or struct half_eye_data.
1021 */
1022
1023void compute_eyes(int pos, struct eyevalue *value,
1024 int *attack_point, int *defense_point,
1025 struct eye_data eye[BOARDMAX],
1026 struct half_eye_data heye[BOARDMAX],
1027 int add_moves);
1028void compute_eyes_pessimistic(int pos, struct eyevalue *value,
1029 int *pessimistic_min,
1030 int *attack_point, int *defense_point,
1031 struct eye_data eye[BOARDMAX],
1032 struct half_eye_data heye[BOARDMAX]);
1033void propagate_eye(int pos, struct eye_data eye[BOARDMAX]);
1034int find_eye_dragons(int origin, struct eye_data eye[BOARDMAX], int eye_color,
1035 int dragons[], int max_dragons);
1036void make_domains(struct eye_data b_eye[BOARDMAX],
1037 struct eye_data w_eye[BOARDMAX],
1038 int owl_call);
1039void partition_eyespaces(struct eye_data eye[BOARDMAX], int color);
1040void find_half_and_false_eyes(int color, struct eye_data eye[BOARDMAX],
1041 struct half_eye_data heye[BOARDMAX],
1042 int find_mask[BOARDMAX]);
1043
1044void set_eyevalue(struct eyevalue *e, int a, int b, int c, int d);
1045int min_eye_threat(struct eyevalue *e);
1046int min_eyes(struct eyevalue *e);
1047int max_eyes(struct eyevalue *e);
1048int max_eye_threat(struct eyevalue *e);
1049void add_eyevalues(struct eyevalue *e1, struct eyevalue *e2,
1050 struct eyevalue *sum);
1051int eye_move_urgency(struct eyevalue *e);
1052char *eyevalue_to_string(struct eyevalue *e);
1053
1054int is_halfeye(struct half_eye_data heye[BOARDMAX], int pos);
1055int is_false_eye(struct half_eye_data heye[BOARDMAX], int pos);
1056
1057#endif /* _LIBERTY_H_ */
1058
1059
1060/*
1061 * Local Variables:
1062 * tab-width: 8
1063 * c-basic-offset: 2
1064 * End:
1065 */