Updated README: Equal sign not required with `--mode` flag.
[sgk-go] / doc / analyze.texi
CommitLineData
7eeb782e
AT
1In this chapter we will discuss methods of finding
2out how GNU Go understands a given position. These
3methods will be of interest to anyone working on the
4program, or simply curious about its workings.
5
6In practice, most tuning of GNU Go is done in conjunction
7with maintaining the @file{regression/} directory
8(@pxref{Regression}).
9
10We assume that you have a game GNU Go played saved
11as an sgf file, and you want to know why it made a
12certain move.
13
14@menu
15* Traces:: Analyzing traces in GNU Go 3.6
16* Output File:: The Output File
17* Decide string:: Checking the reading code
18* Decide dragon:: Checking the owl code
19* GTP and GDB techniques:: GTP and GDB techniques
20* view.pike:: Debugging on a Graphic Board
21* Scoring:: Finding out the winner of the game
22* Colored Display:: Colored Display
23@end menu
24
25@node Traces
26@section Interpreting Traces
27@cindex traces
28@cindex tuning GNU Go
29
30A quick way to find out roughly the reason for a move is to run
31
32@example
33gnugo -l @var{filename} -t -L @var{move number}
34@end example
35
36(You may also want to add @option{--quiet} to suppress the copyright
37message.) In GNU Go 3.6, the moves together with their reasons are
38listed, followed by a numerical analysis of the values given to each
39move.
40
41If you are tuning (@pxref{Tuning}) you may want to add the @option{-a}
42option. This causes GNU Go to report all patterns matched, even ones
43that cannot affect the outcome of the move. The reasons for doing
44this is that you may want to modify a pattern already matched
45instead of introducing a new one.
46
47If you use the @option{-w} option, GNU Go will report the statuses of
48worms and dragons around the board. This type of information is
49available by different methods, however (@pxref{view.pike},
50@pxref{Colored Display}).
51
52@node Output File
53@section The Output File
54@cindex output file
55
56If GNU Go is invoked with the option @option{-o filename} it will
57produce an output file. This option can be added at the command line
58in the Go Modem Protocol Setup Window of CGoban. The output file will
59show the locations of the moves considered and their weights. It is
60worth noting that by enlarging the CGoban window to its fullest size
61it can display 3 digit numbers. Dragons with status @code{DEAD} are
62labelled with an @samp{X}, and dragons with status @code{CRITICAL} are
63labelled with a @samp{!}.
64
65If you have a game file which is not commented this way, or
66which was produced by a non-current version of GNU Go you may
67ask GNU Go to produce a commented version by running:
68
69@example
70gnugo --quiet -l <old file> --replay <color> -o <new file>
71@end example
72
73@noindent
74Here <color> can be 'black,' 'white' or 'both'. The replay
75option will also help you to find out if your current version
76of GNU Go would play differently than the program that created
77the file.
78
79@node Decide string
80@section Checking the reading code
81@cindex decide-string
82
83The @option{--decide-string} option is used to check the tactical reading code
84(@pxref{Tactical Reading}). This option takes an argument, which is a location
85on the board in the usual algebraic notation (e.g.
86@option{--decide-string C17}). This will tell you whether the reading code (in
87@file{engine/reading.c}) believes the string can be captured, and if so,
88whether it believes it can be defended, which moves it finds to attack or
89defend the move, how many nodes it searched in coming to these
90conclusions. Note that when GNU Go runs normally (not with
91@option{--decide-string}) the points of attack and defense are
92computed when @code{make_worms()} runs and cached in
93@code{worm.attack} and @code{worm.defend}.
94
95If used with an output file (@option{-o @var{filename}})
96@option{--decide-string} will produce a variation tree showing
97all the variations which are considered. This is a useful way
98of debugging the reading code, and also of educating yourself
99with the way it works. The variation tree can be displayed
100graphically using CGoban.
101
102At each node, the comment contains some information. For example you
103may find a comment:
104
105@example
106
107attack4-B at D12 (variation 6, hash 51180fdf)
108break_chain D12: 0
109defend3 D12: 1 G12 (trivial extension)
110
111@end example
112
113This is to be interpreted as follows. The node in question
114was generated by the function @code{attack3()} in @file{engine/reading.c},
115which was called on the string at @code{D12}. The data in
116parentheses tell you the values of @code{count_variations} and
117@code{hashdata.hashval}.
118
119The second value (``hash'') you probably will not need to know
120unless you are debugging the hash code, and we will not discuss it.
121But the first value (``variation'') is useful when using the debugger
122@command{gdb}. You can first make an output file using
123the @option{-o} option, then walk through the reading with
124@command{gdb}, and to coordinate the SGF file with the debugger,
125display the value of @code{count_variations}. Specifically,
126from the debugger you can find out where you are as follows:
127
128@example
129(gdb) set dump_stack()
130B:D13 W:E12 B:E13 W:F12 B:F11 (variation 6)
131@end example
132
133If you place yourself right after the call to @code{trymove()}
134which generated the move in question, then the variation number
135in the SGF file should match the variation number displayed by
136@code{dump_stack()}, and the move in question will be the
137last move played (F11 in this example).
138
139This displays the sequence of moves leading up to the variation
140in question, and it also prints @code{count_variations-1}.
141
142The second two lines tell you that from this node, the function
143@code{break_chain()} was called at D12 and returned 0 meaning
144that no way was found of rescuing the string by attacking
145an element of the surrounding chain, and the function
146@code{defend3()} was called also at D12 and returned 1,
147meaning that the string can be defended, and that
148G12 is the move that defends it. If you have trouble
149finding the function calls which generate these comments,
150try setting @code{sgf_dumptree=1} and setting a breakpoint in
151@code{sgf_trace}.
152
153@node Decide dragon
154@section Checking the Owl Code
155@cindex decide-dragon
156
157You can similarly debug the Owl code using the option
158@option{--decide-dragon}. Usage is entirely similar to
159@option{--decide-string}, and it can be used similarly
160to produce variation trees. These should be typically
161much smaller than the variation trees produced by
162@option{--decide-string}.
163
164@node GTP and GDB techniques
165@section GTP and GDB techniques
166@cindex GDB
167@cindex GTP
168
169You can use the Go Text Protocol (@pxref{GTP}) to determine
170the statuses of dragons and other information needed for
171debugging. The GTP command @command{dragon_data P12} will list
172the dragon data of the dragon at @code{P12} and
173@command{worm_data} will list the worm data; other GTP
174commands may be useful as well.
175
176You can also conveniently get such information from GDB.
177A suggested @file{.gdbinit} file may be found in
178@xref{Debugging}. Assuming this file is loaded, you can
179list the dragon data with the command:
180
181@example
182(gdb) dragon P12
183@end example
184
185Similarly you can get the worm data with @command{worm P12}.
186
187@node view.pike
188@section Debugging on a Graphical Board
189@cindex debugging on a graphical board
190
191The quickest way to analyze most positions is to use the tool
192@file{view.pike} in the @file{regression} directory. It can be started
193with a testcase specified, e.g. @command{pike view.pike strategy:40} or
194at a move in an sgf file, e.g. @command{pike view.pike mistake.sgf:125}.
195When started it shows the position on a grapical board on which it also
196marks information like move values, dragon status, and so on. By
197clicking on the board further information about the valuation of moves,
198contents of various data structures, and other data can be made
199available.
200
201Specific information on how to use @file{view.pike} for influence tuning
202can be found in @xref{Influence Tuning}.
203
204@node Scoring
205@section Scoring the game
206@cindex scoring
207
208GNU Go can score the game. Normally GNU Go will report its opinion about
209the score at the end of the game, but if you want this information about
210a game stored in a file, use the @option{--score} option (@pxref{Invoking
211GNU Go}).
212
213@node Colored Display
214@section Colored Display
215@cindex colored display
216
217Various colored displays of the board may be obtained in a color
218@command{xterm} or @command{rxvt} window. Xterm will only work if xterm is
219compiled with color support. If the colors are not displayed on your xterm,
220try @command{rxvt}. You may also use the Linux console. The colored display
221will work best if the background color is black; if this is not the case you
222may want to edit your @file{.Xdefaults} file or add the options
223@option{-bg black -fg white} to @command{xterm} or @command{rxvt}.
224On Mac OS X put @command{setenv TERM xterm-color} in your @file{.tcshrc}
225file to enable color in the terminal.
226
227@subsection Dragon Display
228
229You can get a colored ASCII display of the board in which each dragon
230is assigned a different letter; and the different @code{matcher_status} values
231(@code{ALIVE}, @code{DEAD}, @code{UNKNOWN}, @code{CRITICAL}) have different
232colors. This is very handy for debugging. Actually two diagrams are generated.
233The reason for this is concerns the way the matcher status is computed.
234The dragon_status (@pxref{Dragons}) is computed first, then for some, but not
235all dragons, a more accurate owl status is computed. The matcher status is
236the owl status if available; otherwise it is the dragon_status. Both the
237dragon_status and the owl_status are displayed. The color scheme is as
238follows:
239
240@example
241green = alive
242cyan = dead
243red = critical
244yellow = unknown
245magenta = unchecked
246@end example
247
248To get the colored display, save a game in sgf format using CGoban, or using
249the @option{-o} option with GNU Go itself.
250
251Open an @command{xterm} or @command{rxvt} window.
252
253Execute @command{gnugo -l [filename] -L [movenum] -T} to get the colored
254display.
255
256Other useful colored displays may be obtained by using instead:
257
258@subsection Eye Space Display
259@cindex eye space display
260
261Instead of @option{-T}, try this with @option{-E}. This gives a colored
262display of the eyespaces, with marginal eye spaces marked @samp{!}
263(@pxref{Eyes}).
264
265