Updated README: Equal sign not required with `--mode` flag.
[sgk-go] / doc / overview.texi
CommitLineData
7eeb782e
AT
1
2This chapter is an overview of the GNU Go internals. Further
3documentation of how any one module or routine works may be found in
4later chapters or comments in the source files.
5
6GNU Go starts by trying to understand the current board position as
7good as possible. Using the information found in this first phase, and
8using additional move generators, a list of candidate moves is generated.
9Finally, each of the candidate moves is valued according to its territorial
10value (including captures or life-and-death effects), and possible
11strategical effects (such as strengthening a weak group).
12
13Note that while GNU Go does, of course, do a lot of reading to analyze
14possible captures, life and death of groups etc., it does not (yet) have
15a fullboard lookahead.
16
17@menu
18* Examining the Position:: Gathering Information
19* Move Generators:: Selecting Candidate Moves
20* Move Valuation:: Selecting the best Move
21* Detailed Sequence of Events:: Outline of @code{genmove()}.
22* Roadmap:: Description of the different files.
23* Coding Styles:: Coding conventions.
24* Navigating the Source:: Navigating the Source.
25@end menu
26
27
28@node Examining the Position
29@section Gathering Information
30
31This is by far the most important phase in the move generation.
32Misunderstanding life-and-death situations can cause gross mistakes.
33Wrong territory estimates will lead to inaccurate move valuations.
34Bad judgement of weaknesses of groups make strategic mistakes likely.
35
36This information gathering is done by the function @code{examine_position()}.
37It first calls @code{make_worms()}.
38
39Its first steps are very simple: it identifies sets of directly connected
40stones, called @dfn{worms}, and notes their sizes and their number of
41liberties.
42
43Soon after comes the most important step of the worm analysis:
44the tactical reading code (@pxref{Tactical Reading}) is called for every
45worm. It tries to read
46out which worms can be captured directly, giving up as soon as a worm
47can reach 5 liberties. If a worm can be captured, the engine of course
48looks for moves defending against this capture. Also, a lot of effort
49is made to find virtually all moves that achieve the capture or defense
50of a worm.
51
52After knowing which worms are tactically stable, we can make a first
53picture of the balance of power across the board: the @ref{Influence}
54code is called for the first time.
55
56This is to aid the next step, the analysis of dragons. By a @dfn{dragon}
57we mean a group of stones that cannot be disconnected.
58
59Naturally the first step in the responsible function @code{make_dragons()}
60is to identify these dragons, i.e. determine which worms cannot be
61disconnected from each other. This is partly done by patterns, but
62in most cases the specialized readconnect code
63@comment FIXME: Put in cross-ref here once Connection is documented
64is called. This module does a minimax search to determine whether two
65given worms can be connected with, resp. disconnected from each other.
66
67Then we compute various measures to determine how strong or weak any given
68dragon is:
69@itemize @bullet
70@item A crude estimate of the number of eyes is made.
71@item The results of the influence computations is used to see which dragons
72are adjacent to own territory or a moyo.
73@item A guess is made for the potential to escape if the dragon got
74under attack.
75@end itemize
76
77For those dragons that are considered weak, a life and death analysis
78is made (@pxref{The Owl Code}). If two dragons next to each other are found
79that are both not alive, we try to resolve this situation with the semeai
80module.
81
82For a more detailed reference of the worm and dragon analysis (and
83explanations of the data structures used to store the information),
84see @xref{Worms and Dragons}.
85
86The influence code is then called second time to make a detailed analysis
87of likely territory. Of course, the life-and-death status of dragons are
88now taken into account.
89
90The territorial results of the influence module get corrected by the break-in
91module. This specifically tries to analyze where an opponent could break
92into an alleged territory, with sequences that would be too difficult to
93see for the influence code.
94
95
96@node Move Generators
97@section Move Generators
98@cindex move generation
99@cindex move generators
100@cindex move reasons
101
102Once we have found out all about the position it is time to generate
103the best move. Moves are proposed by a number of different modules
104called @dfn{move generators}. The move generators themselves
105do not set the values of the moves, but enumerate justifications for
106them, called @dfn{move reasons}. The valuation of the moves comes
107last, after all moves and their reasons have been generated.
108
109For a list and explanation of move reasons used in GNU Go, and how they
110are evaluated, see @xref{Move Generation}.
111
112There are a couple of move generators that only extract data found in
113the previous phase, examining the position:
114
115@itemize @bullet
116@item @code{worm_reasons()}
117@findex worm_reasons
118@quotation
119Moves that have been found to capture or defend a worm are proposed as
120candidates.
121@end quotation
122
123@item @code{owl_reasons()}
124@findex owl_reasons
125@quotation
126The status of every dragon, as it has been determined by the owl code
127(@pxref{The Owl Code}) in the previous phase, is reviewed. If the status
128is critical, the killing or defending move gets a corresponding move
129reason.
130@end quotation
131
132@item @code{semeai_move_reasons()}
133@findex semeai
134@quotation
135Similarly as @code{owl_reasons}, this function proposes moves relevant
136for semeais.
137@end quotation
138
139@item @code{break_in_move_reasons()}
140@quotation
141This suggests moves that have been found to break into opponent's territory
142by the break-in module.
143@end quotation
144@end itemize
145
146The following move generators do additional work:
147
148@itemize @bullet
149
150@item @code{fuseki()}
151@findex fuseki
152@quotation
153Generate a move in the early fuseki, either in an empty corner of from
154the fuseki database.
155@end quotation
156
157@item @code{shapes()}
158@findex shapes
159@quotation
160This is probably the most important move generator.
161It finds patterns from @file{patterns/patterns.db},
162@file{patterns/patterns2.db}, @file{patterns/fuseki.db}, and the joseki
163files in the current position. Each pattern is matched in each
164of the 8 possible orientations obtainable by rotation and
165reflection. If the pattern matches, a so called "constraint"
166may be tested which makes use of reading to determine if the
167pattern should be used in the current situation. Such
168constraints can make demands on number of liberties of
169strings, life and death status, and reading out ladders,
170etc. The patterns may call helper functions, which may
171be hand coded (in @file{patterns/helpers.c}) or
172autogenerated.
173
174The patterns can be of a number of different classes
175with different goals. There are e.g. patterns which
176try to attack or defend groups, patterns which try to
177connect or cut groups, and patterns which simply try
178to make good shape. (In addition to the large pattern
179database called by @code{shapes()}, pattern matching
180is used by other modules for different tasks throughout
181the program. @xref{Patterns}, for a complete documentation
182of patterns.)
183@end quotation
184
185@item @code{combinations()}
186@findex atari_atari
187@quotation
188See if there are any combination threats or atari sequences and either
189propose them or defend against them.
190@end quotation
191
192@item @code{revise_thrashing_dragon()}
193@findex revise_thrashing_dragon
194@quotation
195This module does not directly propose move: If we are clearly ahead,
196and the last move played by the opponent is part of a dead dragon, we
197want to attack that dragon again to be on the safe side. This is done
198be setting the status of this @dfn{thrashing dragon} to unkown and
199repeating the shape move generation and move valution.
200@end quotation
201
202@item @code{endgame_shapes()}
203@findex endgame_shapes
204@quotation
205If no move is found with a value greater than 6.0, this module matches a
206set of extra patterns which are designed for the endgame. The endgame
207patterns can be found in @file{patterns/endgame.db}.
208@end quotation
209
210@item @code{revise_semeai()}
211@findex revise_semeai
212@quotation
213If no move is found, this module changes the status of opponent groups
214involved in a semeai from @code{DEAD} to @code{UNKNOWN}. After this,
215genmove runs @code{shapes} and @code{endgame_shapes} again to see if a
216new move turns up.
217@end quotation
218
219@item @code{fill_liberty()}
220@findex fill_liberty
221@quotation
222Fill a common liberty. This is only used at the end
223of the game. If necessary a backfilling or backcapturing
224move is generated.
225@end quotation
226@end itemize
227
228@node Move Valuation
229@section Move Valuation
230
231After the move generation modules have run, each proposed candidate
232move goes through a detailed valuation by the function
233@code{review_move_reasons}. This invokes some analysis to try to turn
234up other move reasons that may have been missed.
235
236The most important value of a move is its territorial effect.
237@pxref{Influence and Territory} explains in detail how this is determined.
238
239This value is modified for all move reasons that cannot be expressed
240directly in terms of territory, such as combination attacks (where it
241is not clear which of several strings will get captured), strategical
242effects, connection moves, etc. A large set heuristics is necessary
243here, e.g. to avoid duplication of such values. This is explained in
244more detail in @ref{Valuation}.
245
246
247@node Detailed Sequence of Events
248@section Detailed Sequence of Events
249
250First comes the sequence of events when
251@code{examine_position()} is run from @code{genmove()}. This
252is for reference only.
253
254@format
255@code{purge_persistent_caches()}
256@code{make_worms()}:
257 @code{compute_effective_sizes()}
258 @code{compute_unconditional_status()}
259 @code{find_worm_attacks_and_defenses()}:
260 for each attackable worm:
261 set @code{worm.attack}
262 @code{change_attack()} to add the attack point
263 @code{find_attack_patterns()} to find a few more attacks
264 for each defensible worm:
265 set @code{worm.attack}
266 @code{change_defense()} to add the defense point
267 @code{find_defense_patterns()} to find a few more defense moves
268 find additional attacks and defenses by testing all
269 immediate liberties
270 find higher order liberties (for each worm)
271 find cutting stones (for each worm)
272 improve attacks and defenses: if capturing a string defends
273 another friendly string, or kills an unfriendly one, we
274 add points of defense or attack. Make repairs if adjacent
275 strings can both be attacked but not defended.
276 find worm lunches
277 find worm threats
278 identify inessential worms (such as nakade stones)
279@code{compute_worm_influence()}:
280 @code{find_influence_patterns()}
281 @code{value_influence()}
282 @code{segment_influence()}
283@code{make_dragons()}:
284 @code{find_cuts()}
285 @code{find_connections()}
286 @code{make_domains()} (determine eyeshapes)
287 @code{find_lunches()} (adjacent strings that can be captured)
288 @code{find_half_and_false_eyes()}
289 @code{eye_computations()}: Compute the value of each eye space.
290 Store its attack and defense point.
291 @code{analyze_false_eye_territory()}
292 for each dragon @code{compute_dragon_genus()}
293 for each dragon @code{compute_escape()} and set escape route data
294 @code{resegment_initial_influence()}
295 @code{compute_refined_dragon_weaknesses()} (called again after owl)
296 for each dragon @code{compute_crude_status()}
297 @code{find_neighbor_dragons()}
298 for each dragon compute surround status
299 for each weak dragon run @code{owl_attack()} and @code{owl_defend()}
300 to determine points of attack and defense
301 for each dragon compute dragon.status
302 for each thrashing dragon compute owl threats
303 for each dragon compute dragon.safety
304 @code{revise_inessentiality()}
305 @code{semeai()}:
306 for every semeai, run @code{owl_analyze_semeai()}
307 @code{find_moves_to_make_seki()}
308 @code{identify_thrashing_dragons()}
309 @code{compute_dragon_influence()}:
310 @code{compute_influence()}
311 @code{break_territories()} (@pxref{Break Ins})
312 @code{compute_refined_dragon_weaknesses()}
313@end format
314
315Now a summary of the sequence of events during the
316move generation and selection phases of @code{genmove()}, which
317take place after the information gathering phase has been completed:
318
319@format
320@code{estimate_score()}
321@code{choose_strategy()}
322@code{collect_move_reasons()}:
323 @code{worm_reasons()}: for each attack and defense point add a move reason
324 @code{semeai_reasons()}: for each dragon2.semeai point add a move reason
325 @code{owl_reasons()}: for each owl attack and defense point add a move reason
326 @code{break_in_reasons()}: for each breakin found add a move reason
327@code{fuseki()}
328@code{break_mirror_go()}
329@code{shapes()}: match patterns around the board (@pxref{Patterns Overview})
330@code{combinations()}: look for moves with a double meaning and other tricks
331 @code{find_double_threats()}
332 @code{atari_atari()}
333@code{review_move_reasons()}
334if ahead and there is a thrashing dragon, consider it
335 alive and reconsider the position
336@code{endgame_shapes()}
337@code{endgame()}
338if no move found yet, revisit any semeai, change status of dead opponent
339 to alive, then run @code{shapes()} and @code{endgame_shapes()} again
340if no move found yet, run @code{fill_liberty()}
341@end format
342
343@node Roadmap
344@section Roadmap
345
346The GNU Go engine is contained in two directories, @file{engine/} and
347@file{patterns/}. Code related to the user interface, reading and
348writing of Smart Game Format files, and testing are found in the
349directories @file{interface/}, @file{sgf/}, and @file{regression/}. Code
350borrowed from other GNU programs is contained in @file{utils/}. That
351directory also includes some code developed within GNU Go which is not
352go specific. Documentation is in @file{doc/}.
353
354In this document we will describe some of the individual files comprising
355the engine code in @file{engine/} and @file{patterns/}. In @file{interface/}
356we mention two files:
357
358@itemize
359@item @file{gmp.c}
360@quotation
361This is the Go Modem Protocol interface (courtesy of
362William Shubert and others). This takes care of all the
363details of exchanging setup and moves with Cgoban, or any
364other driving program recognizing the Go Modem Protocol.
365@end quotation
366@item @file{main.c}
367@quotation
368This contains @code{main()}. The @file{gnugo} target is
369thus built in the @file{interface/} directory.
370@end quotation
371@end itemize
372
373@subsection Files in @file{engine/}
374
375In @file{engine/} there are the following files:
376
377@itemize @bullet
378@item @file{aftermath.c}
379@quotation
380Contains algorithms which may be called at the end of the game to generate
381moves that will generate moves to settle the position, if necessary playing
382out a position to determine exactly the status of every group on the board,
383which GNU Go can get wrong, particularly if there is a seki. This module is
384the basis for the most accurate scoring algorithm available in GNU Go.
385@end quotation
386@item @file{board.c}
387@quotation
388@findex trymove
389@findex popgo
390@findex is_legal
391This file contains code for the maintenance of the board. For example
392it contains the important function @code{trymove()} which tries a move
393on the board, and @code{popgo()} which removes it by popping the move
394stack. At the same time vital information such as the number of
395liberties for each string and their location is updated incrementally.
396@end quotation
397@item @file{breakin.c}
398@quotation
399Code to detect moves which can break into supposed territory and moves
400to prevent this.
401@end quotation
402@item @file{cache.c} and @file{cache.h}
403@quotation
404As a means of speeding up reading, computed results are cached so that
405they can be quickly reused if the same position is encountered through
406e.g. another move ordering. This is implemented using a hash table.
407@end quotation
408@item @file{clock.c} and @file{clock.h}
409@quotation
410Clock code, including code allowing GNU Go to automatically
411adjust its level in order to avoid losing on time in tournaments.
412@end quotation
413@item @file{combination.c}
414@quotation
415When something can (only) be captured through a series of ataris or
416other threats we call this a combination attack. This file contains code
417to find such attacks and moves to prevent them.
418@end quotation
419@item @file{dragon.c}
420@quotation
421This contains @code{make_dragons()}. This function is executed before
422the move-generating modules @code{shapes()} @code{semeai()} and the
423other move generators but after @code{make_worms()}. It tries to connect
424worms into dragons and collect important information about them, such as
425how many liberties each has, whether (in GNU Go's opinion) the dragon
426can be captured, if it lives, etc.
427@end quotation
428@item @file{endgame.c}
429@quotation
430Code to find certain types of endgame moves.
431@end quotation
432@item @file{filllib.c}
433@quotation
434Code to force filling of dame (backfilling if necessary)
435at the end of the game.
436@end quotation
437@item @file{fuseki.c}
438@quotation
439Generates fuseki (opening) moves from a database. Also generates moves
440in empty corners.
441@end quotation
442@item @file{genmove.c}
443@quotation
444This file contains @code{genmove()} and its supporting
445routines, particularly @code{examine_position()}.
446@end quotation
447@item @file{globals.c}
448@quotation
449This contains the principal global variables used by GNU Go.
450@end quotation
451@item @file{gnugo.h}
452@quotation
453This file contains declarations forming the public interface to
454the engine.
455@end quotation
456@item @file{hash.c} and @file{hash.h}
457@quotation
458Hashing code implementing Zobrist hashing. (@pxref{Hashing}) The code in
459@file{hash.c} provides a way to hash board positions into compact descriptions
460which can be efficiently compared. The caching code in @file{cache.c}
461makes use of the board hashes when storing and retrieving read results.
462@end quotation
463@item @file{influence.c} and @file{influence.h}.
464@quotation
465This code determines which regions of the board are under the
466influence of either player.
467(@pxref{Influence})
468@end quotation
469@item @file{liberty.h}
470@quotation
471Header file for the engine. The name ``liberty'' connotes
472freedom (@pxref{Copying}).
473@end quotation
474@item @file{matchpat.c}
475@quotation
476This file contains the pattern matcher @code{matchpat()}, which looks for
477patterns at a particular board location. The actual patterns are in
478the @file{patterns/} directory. The function @code{matchpat()} is
479called by every module which does pattern matching, notably @code{shapes}.
480@end quotation
481@item @file{move_reasons.c} and @file{move_reasons.h}
482@quotation
483Code for keeping track of move reasons.
484@end quotation
485@item @file{movelist.c}
486@quotation
487Supporting code for lists of moves.
488@end quotation
489@item @file{optics.c}
490@quotation
491This file contains the code to recognize eye shapes,
492documented in @xref{Eyes}.
493@end quotation
494@item @file{oracle.c}
495@quotation
496Code to fork off a second GNU Go process which can be used to simulate
497reading with top level information (e.g. dragon partitioning) available.
498@end quotation
499@item @file{owl.c}
500@quotation
501This file does life and death reading. Move generation is pattern based
502and the code in @file{optics.c} is used to evaluate the eyespaces for
503vital moves and independent life. A dragon can also live by successfully
504escaping. Semeai reading along the same principles is also implemented
505in this file.
506@end quotation
507@item @file{persistent.c}
508@quotation
509Persistent cache which allows reuse of read results at a later move or
510with additional stones outside an active area, which are those
511intersections thought to affect the read result.
512@end quotation
513@item @file{printutils.c}
514@quotation
515Print utilities.
516@end quotation
517@item @file{readconnect.c} and @file{readconnect.h}
518@quotation
519This file contains code to determine whether two strings can be
520connected or disconnected.
521@end quotation
522@item @file{reading.c}
523@quotation
524This file contains code to determine whether any given
525string can be attacked or defended. @xref{Tactical Reading},
526for details.
527@end quotation
528@item @file{semeai.c}
529@quotation
530This file contains @code{semeai()}, the module which detects dragons
531in semeai. To determine the semeai results the semeai reading in
532@file{owl.c} is used.
533@end quotation
534@item @file{sgfdecide.c}
535@quotation
536Code to generate sgf traces for various types of reading.
537@end quotation
538@item @file{shapes.c}
539@quotation
540This file contains @code{shapes()}, the module called by @code{genmove()}
541which tries to find moves which match a pattern (@pxref{Patterns}).
542@end quotation
543@item @file{showbord.c}
544@quotation
545This file contains @code{showboard()}, which draws an ASCII
546representation of the board, depicting dragons (stones
547with same letter) and status (color). This was the
548primary interface in GNU Go 1.2, but is now a debugging
549aid.
550@end quotation
551@item @file{surround.c}
552@quotation
553Code to determine whether a dragon is surrounded and to find moves to
554surround with or break out with.
555@end quotation
556@item @file{utils.c}
557@quotation
558An assortment of utilities, described in greater detail below.
559@end quotation
560@item @file{value_moves.c}
561@quotation
562This file contains the code which assigns values to every move
563after all the move reasons are generated. It also tries to generate
564certain kinds of additional move reasons.
565@end quotation
566@item @file{worm.c}
567@quotation
568This file contains @code{make_worms()}, code which is run at the
569beginning of each move cycle, before the code in @file{dragon.c}, to
570determine the attributes of every string. These attributes are things
571like liberties, wether the string can be captured (and how), etc
572@end quotation
573@end itemize
574
575@subsection Files in @file{patterns/}
576
577The directory @file{patterns/} contains files related to pattern matching.
578Currently there are several types of patterns. A partial list:
579
580@itemize @bullet
581@item move generation patterns in @file{patterns.db} and @file{patterns2.db}
582@item move generation patterns in files @file{hoshi.db} etc. which are
583automatically build from the files @file{hoshi.sgf} etc. These comprise
584our small Joseki library.
585@item patterns in @file{owl_attackpats.db}, @file{owl_defendpats.db}
586and @file{owl_vital_apats.db}. These generate moves for the owl
587code (@pxref{The Owl Code}).
588@item Connection patterns in @file{conn.db} (@pxref{Connections Database})
589@item Influence patterns in @file{influence.db} and @file{barriers.db}
590(@pxref{Influence})
591@item eye patterns in @file{eyes.db} (@pxref{Eyes}).
592@end itemize
593
594The following list contains, in addition to distributed source files
595some intermediate automatically generated files such as @file{patterns.c}.
596These are C source files produced by "compiling" various pattern
597databases, or in some cases (such as @file{hoshi.db}) themselves
598automatically generated pattern databases produced by "compiling"
599joseki files in Smart Game Format.
600
601@itemize @bullet
602
603@item @file{conn.db}
604@quotation
605Database of connection patterns.
606@end quotation
607
608@item @file{conn.c}
609@quotation
610Automatically generated file, containing connection
611patterns in form of struct arrays, compiled by @command{mkpat}
612from @file{conn.db}.
613@end quotation
614
615@item @file{eyes.c}
616@quotation
617Automatically generated file, containing eyeshape
618patterns in form of struct arrays, compiled by @command{mkpat}
619from @file{eyes.db}.
620@end quotation
621
622@item @file{eyes.h}
623@quotation
624Header file for @file{eyes.c}.
625@end quotation
626
627@item @file{eyes.db}
628@quotation
629Database of eyeshape patterns. @xref{Eyes}, for
630details.
631@end quotation
632
633@item @file{helpers.c}
634@quotation
635These are helper functions to assist in evaluating
636moves by matchpat.
637@end quotation
638
639@item @file{hoshi.sgf}
640@quotation
641Smart Game Format file containing 4-4 point openings
642@end quotation
643
644@item @file{hoshi.db}
645@quotation
646Automatically generated database of 4-4 point opening
647patterns, make by compiling @file{hoshi.sgf}
648@end quotation
649
650@item @file{joseki.c}
651@quotation
652Joseki compiler, which takes a joseki file in
653Smart Game Format, and produces a pattern database.
654@end quotation
655
656@item @file{komoku.sgf}
657@quotation
658Smart Game Format file containing 3-4 point openings
659@end quotation
660
661@item @file{komoku.db}
662@quotation
663Automatically generated database of 3-4 point opening
664patterns, make by compiling @file{komoku.sgf}
665@end quotation
666
667@item @file{mkeyes.c}
668@quotation
669Pattern compiler for the eyeshape databases. This
670program takes @file{eyes.db} as input and produces @file{eyes.c}
671as output.
672@end quotation
673
674@item @file{mkpat.c}
675@quotation
676Pattern compiler for the move generation and connection
677databases. Takes the file @file{patterns.db} together with
678the autogenerated Joseki pattern files @file{hoshi.db}, @file{komoku.db},
679@file{sansan.db}, @file{mokuhadzushi.db}, @file{takamoku.db} and produces
680@file{patterns.c}, or takes @file{conn.db} and produces @file{conn.c}.
681@end quotation
682
683@item @file{mokuhazushi.sgf}
684@quotation
685Smart Game Format file containing 5-3 point openings
686@end quotation
687
688@item @file{mokuhazushi.db}
689@quotation
690Pattern database compiled from mokuhadzushi.sgf
691@end quotation
692
693@item @file{sansan.sgf}
694@quotation
695Smart Game Format file containing 3-3 point openings
696@end quotation
697
698@item @file{sansan.db}
699@quotation
700Pattern database compiled from @file{sansan.sgf}
701@end quotation
702
703@item @file{takamoku.sgf}
704@quotation
705Smart Game Format file containing 5-4 point openings
706@end quotation
707
708@item @file{takamoku.db}
709@quotation
710Pattern database compiled from takamoku.sgf.
711@end quotation
712
713@item @file{patterns.c}
714@quotation
715Pattern data, compiled from patterns.db by mkpat.
716@end quotation
717
718@item @file{patterns.h}
719@quotation
720Header file relating to the pattern databases.
721@end quotation
722
723@item @file{patterns.db} and @file{patterns2.db}
724@quotation
725These contain pattern databases in human readable form.
726@end quotation
727
728@end itemize
729
730
731@node Coding Styles
732@section Coding styles and conventions
733
734@subsection Coding Conventions
735
736Please follow the coding conventions at:
737@url{http://www.gnu.org/prep/standards_toc.html}
738
739Please preface every function with a brief description
740of its usage.
741
742Please help to keep this Texinfo documentation up-to-date.
743
744@subsection Tracing
745
746A function @code{gprintf()} is provided. It is a cut-down
747@code{printf}, supporting only @code{%c}, @code{%d},
748@code{%s}, and without field widths, etc. It does, however,
749add some useful facilities:
750
751@itemize @bullet
752@item @code{%m}
753@quotation
754Takes two parameters, and displays a formatted board co-ordinate.
755@end quotation
756@item indentation
757@quotation
758Trace messages are automatically indented to reflect
759the current stack depth, so it is clear during read-ahead
760when it puts a move down or takes one back.
761@end quotation
762@item "outdent"
763@quotation As a workaround, @code{%o} at the beginning of the
764format string suppresses the indentation.
765@end quotation
766@end itemize
767
768Normally @code{gprintf()} is wrapped in one of the following:
769
770@code{TRACE(fmt, ...)}:
771@quotation
772Print the message if the 'verbose' variable > 0.
773(verbose is set by @command{-t} on the command line)
774@end quotation
775
776@code{DEBUG(flags, fmt, ...)}:
777@quotation
778While @code{TRACE} is intended to afford an overview
779of what GNU Go is considering, @code{DEBUG} allows occasional
780in depth study of a module, usually needed when something
781goes wrong. @code{flags} is one of the @code{DEBUG_*} symbols in
782@file{engine/gnugo.h}. The @code{DEBUG} macro tests to
783see if that bit is set in the @code{debug} variable, and prints
784the message if it is. The debug variable is set using the
785@command{-d} command-line option.
786@end quotation
787
788The variable @code{verbose} controls the tracing. It
789can equal 0 (no trace), 1, 2, 3 or 4 for increasing
790levels of tracing. You can set the trace level at
791the command line by @option{-t} for @code{verbose=1},
792@option{-t -t} for @code{verbose=2}, etc. But in
793practice if you want more verbose tracing than level
7941 it is better to use GDB to reach the point where
795you want the tracing; you will often find that the
796variable @code{verbose} has been temporarily set to zero
797and you can use the GDB command @command{set var verbose=1}
798to turn the tracing back on.
799
800@subsection Assertions
801
802Related to tracing are assertions. Developers are strongly encouraged
803to pepper their code with assertions to ensure that data structures
804are as they expect. For example, the helper functions make assertions
805about the contents of the board in the vicinity of the move they
806are evaluating.
807
808@code{ASSERT()} is a wrapper around the standard C @code{assert()}
809function. In addition to the test, it takes an extra pair of parameters
810which are the co-ordinates of a "relevant" board position. If an
811assertion fails, the board position is included in the trace output, and
812@code{showboard()} and @code{popgo()} are called to unwind and display
813the stack.
814
815@subsection FIXME
816@cindex FIXME
817
818We have adopted the convention of putting the word FIXME
819in comments to denote known bugs, etc.
820
821@node Navigating the Source
822@section Navigating the Source
823
824If you are using Emacs, you may find it fast and convenient to use
825Emacs' built-in facility for navigating the source. Switch to the
826root directory @file{gnugo-3.6/} and execute the command:
827
828@example
829find . -print|grep "\.[ch]$" | xargs etags
830@end example
831
832This will build a file called @file{gnugo-3.6/TAGS}. Now to
833find any GNU Go function, type @command{M-.} and enter the
834command which you wish to find, or just @command{RET} if
835the cursor is at the name of the function sought.
836
837The first time you do this you will be prompted for the location
838of the TAGS table. Enter the path to @file{gnugo-3.6/TAGS}, and
839henceforth you will be able to find any function with a minimum
840of keystrokes.
841
842
843
844