[Top] [Contents] [Index] [ ? ]

GNU Go Documentation

GNU GO

This manual documents GNU Go, a Go program and its sources. This is Edition 3.6 of the GNU Go Program Documentation

Copyright 1999, 2000, 2001, 2002, 2003, 2004 and 2005, The Free Software Foundation, Inc. Permission is granted to make and distribute verbatim or modified copies of this manual is given provided that the terms of the GNU Free Documentation License (see section A.2 GNU FREE DOCUMENTATION LICENSE) are respected.

Permission is granted to make and distribute verbatim or modified copies of the program GNU Go is given provided the terms of the GNU General Public License (see section A.1 GNU GENERAL PUBLIC LICENSE) are respected.

User's manual
1. Introduction  What is GNU Go ?
2. Installation  Installing GNU Go
3. Using GNU Go  
An introduction to the GNU Go engine
4. GNU Go engine overview  Overview of the GNU Go engine
5. Analyzing GNU Go's moves  
6. Move generation  How GNU Go generates moves
7. Worms and Dragons  Dragons and Worms
8. Eyes and Half Eyes  Eyes and half eyes
9. The Pattern Code  Pattern database
11. Tactical reading  Tactical and Connection Reading
12. Pattern Based Reading  Pattern Based Reading: Owl and Combinations
13. Influence Function  
14. Another approach to Moyos : Bouzy's 5/21 algorithm  Another approach to Moyos : Bouzy's algorithm
Infrastructure and Interfaces
15. The Board Library  The basic go board library.
16. Handling SGF trees in memory  
10. The DFA pattern matcher  The DFA Pattern Matcher
18. Utility Functions  `utils.c' and `printutils.c'
17. Application Programmers Interface to GNU Go  API to the GNU Go engine
19. The Go Text Protocol  
20. Regression testing  
Appendices
A. Copying  Software and Documentation Licenses
Indices
Concept Index  
Functions Index  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Introduction

This is GNU Go 3.6, a Go program. Development versions of GNU Go may be found at http://www.gnu.org/software/gnugo/devel.html. Contact us at gnugo@gnu.org if you are interested in helping.

1.1 About GNU Go and this Manual  
1.2 Copyrights  Copyright
1.3 Authors  The Authors of GNU Go
1.4 Thanks  Acknowledgements
1.5 The GNU Go Task List  The GNU Go Task list


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 About GNU Go and this Manual

The challenge of Computer Go is not to beat the computer, but to program the computer.

In Computer Chess, strong programs are capable of playing at the highest level, even challenging such a player as Garry Kasparov. No Go program even as strong as amateur shodan exists. The challenge is to write such a program.

To be sure, existing Go programs are strong enough to be interesting as opponents, and the hope exists that some day soon a truly strong program can be written.

GNU Go is getting stronger. GNU Go 3.6 plays at about the level of 9 kyu.

Until now, Go programs have always been distributed as binaries only. The algorithms in these proprietary programs are secret. No-one but the programmer can examine them to admire or criticise. As a consequence, anyone who wished to work on a Go program usually had to start from scratch. This may be one reason that Go programs have not reached a higher level of play.

Unlike most Go programs, GNU Go is Free Software. Its algorithms and source code are open and documented. They are free for any one to inspect or enhance. We hope this freedom will give GNU Go's descendents a certain competetive advantage.

Here is GNU Go's Manual. There are doubtless inaccuracies. The ultimate documentation is in the commented source code itself.

The first three chapters of this manual are for the general user. Chapter 3 is the User's Guide. The rest of the book is for programmers, or persons curious about how GNU Go works. Chapter 4 is a general overview of the engine. Chapter 5 introduces various tools for looking into the GNU Go engine and finding out why it makes a certain move, and Chapters 6--7 form a general programmer's reference to the GNU Go API. The remaining chapters are more detailed explorations of different aspects of GNU Go's internals.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Copyrights

Copyright 1999, 2000, 2001, 2002, 2003, 2004 and 2005 by the Free Software Foundation except as noted below.

All files are under the GNU General Public License (see section A.1 GNU GENERAL PUBLIC LICENSE), except `gmp.c', `gmp.h', `gtp.c', `gtp.h', the files `interface/html/*' and `win/makefile.win'.

The files `gtp.c' and `gtp.h' are copyright the Free Software Foundation. In the interests of promoting the Go Text Protocol these two files are licensed under a less restrictive license than the GPL and are free for unrestricted use (see section A.3 The Go Text Protocol License).

The two files `gmp.c' and `gmp.h' were placed in the public domain by William Shubert, their author, and are free for unrestricted use.

The files `interface/html/*' are not part of GNU Go but are a separate program and are included in the distribution for the convenience of anyone looking for a CGI interface to GNU Go. They were placed in the public domain by their author, Douglas Ridgway, and are free for unrestricted use.

The files `regression/games/golois/*sgf' are copyright Tristan Cazenave and are included with his permission.

The SGF files in `regression/games/handtalk/' are copyright Jessie Annala and are used with permission.

The SGF files in `regression/games/mertin13x13/' are copyright Stefan Mertin and are used with permission.

The remaining SGF files are either copyright by the FSF or are in the public domain.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Authors

GNU Go maintainers are Daniel Bump, Gunnar Farneback and Arend Bayer. GNU Go authors (in chronological order of contribution) are Man Li, Wayne Iba, Daniel Bump, David Denholm, Gunnar Farneb@"ack, Nils Lohner, Jerome Dumonteil, Tommy Thorn, Nicklas Ekstrand, Inge Wallin, Thomas Traber, Douglas Ridgway, Teun Burgers, Tanguy Urvoy, Thien-Thi Nguyen, Heikki Levanto, Mark Vytlacil, Adriaan van Kessel, Wolfgang Manner, Jens Yllman, Don Dailey, Måns Ullerstam, Arend Bayer, Trevor Morris, Evan Berggren Daniel, Fernando Portela, Paul Pogonyshev, S.P. Lee and Stephane Nicolet and Martin Holters.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.4 Thanks

We would like to thank Arthur Britto, David Doshay, Tim Hunt, Matthias Krings, Piotr Lakomy, Paul Leonard, Jean-Louis Martineau, Andreas Roever and Pierce Wetter for helpful correspondence.

Thanks to everyone who stepped on a bug (and sent us a report)!

Thanks to Gary Boos, Peter Gucwa, Martijn van der Kooij, Michael Margolis, Trevor Morris, Måns Ullerstam, Don Wagner and Yin Zheng for help with Visual C++.

Thanks to Alan Crossman, Stephan Somogyi, Pierce Wetter and Mathias Wagner for help with Macintosh. And thanks to Marco Scheurer and Shigeru Mabuchi for helping us find various problems.

Thanks to Jessie Annala for the Handtalk games.

Special thanks to Ebba Berggren for creating our logo, based on a design by Tanguy Urvoy and comments by Alan Crossman. The old GNU Go logo was adapted from Jamal Hannah's typing GNU: http://www.gnu.org/graphics/atypinggnu.html. Both logos can be found in `doc/newlogo.*' and `doc/oldlogo.*'.

We would like to thank Stuart Cracraft, Richard Stallman and Man Lung Li for their interest in making this program a part of GNU, William Shubert for writing CGoban and gmp.c, Rene Grothmann for Jago and Erik van Riper and his collaborators for NNGS.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5 The GNU Go Task List

You can help make GNU Go the best Go program.

This is a task-list for anyone who is interested in helping with GNU Go. If you want to work on such a project you should correspond with us until we reach a common vision of how the feature will work!

A note about copyright. The Free Software Foundation has the copyright to GNU Go. For this reason, before any code can be accepted as a part of the official release of GNU Go, the Free Software Foundation will want you to sign a copyright assignment.

Of course you could work on a forked version without signing such a disclaimer. You can also distribute such a forked version of the program so long as you also distribute the source code to your modifications under the GPL (see section A.1 GNU GENERAL PUBLIC LICENSE). But if you want your changes to the program to be incorporated into the version we distribute we need you to assign the copyright.

Please contact the GNU Go maintainers, Daniel Bump (bump@sporadic.stanford.edu) and Gunnar Farneb@"ack (gunnar@lysator.liu.se), to get more information and the papers to sign.

Below is a list of things YOU could work on. We are already working on some of these tasks, but don't let that stop you. Please contact us or the person assigned to task for further discussion.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.1 General


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.2 Smaller projects

These issues are of tactical nature, i.e. they concern some specific feature or the infrastructure of the engine. Some of these are quiet small, maybe doable in a day for an experienced GNU Go programmer. They might also be useful project to start with for a new project member. Some of them are bigger and demand a deeper knowledge of the engine internals. The issues are presented here in an approximate order of perceived difficulty.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.3 Long term issues

These issues are strategic in nature. They will help us to improve the playing strength of the program and/or enhance certain aspects of it.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5.4 Ideas

These are some ideas that have been floated on the mailing list. Some of them are down-to-earth, and some are just blue sky ramblings. They are presented here for inspiration.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. Installation

You can get the most recent version of GNU Go ftp.gnu.org or a mirror (see http://www.gnu.org/order/ftp.html for a list). You can read about newer versions and get other information at http://www.gnu.org/software/gnugo/.

2.1 GNU/Linux and Unix  GNU Linux and Unix Installation
2.2 Configure Options  
2.3 Compiling GNU Go on Microsoft platforms  Windows Installation
2.4 Macintosh  Macintosh Installation


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 GNU/Linux and Unix

Untar the sources, change to the directory gnugo-3.6. Now do:

 
   ./configure [OPTIONS]
   make

Several configure options will be explained in the next section. You do not need to set these unless you are dissatisfied with GNU Go's performance or wish to vary the experimental options.

As an example,

 
   ./configure --enable-level=9 --enable-cosmic-gnugo

will make a binary in which the default level is 9, and the experimental "cosmic"' option is enabled. A list of all configure options can be obtained by running ./configure --help. Further information about the experimental options can be found in the next section (see section 2.2 Configure Options).

After running configure and make, you have now made a binary called `interface/gnugo'. Now (running as root) type

 
   make install

to install `gnugo' in `/usr/local/bin'.

There are different methods of using GNU Go. You may run it from the command line by just typing:

 
   gnugo

but it is nicer to run it using CGoban 1 (under X-Windows), Jago (on any platform with a Java runtime environment) or other client programs offering a GUI.

You can get the most recent version of CGoban 1 from http://sourceforge.net/projects/cgoban1/. The earlier version 1.12 is available from http://www.igoweb.org/~wms/comp/cgoban/index.html. The CGoban version number MUST be 1.9.1 at least or it won't work. CGoban 2 will not work.

See section 3.2 Running GNU Go via CGoban, for instructions on how to run GNU Go from Cgoban, or See section 3.3 Other Clients, for Jago or other clients.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 Configure Options

There are three options which you should consider configuring, particularly if you are dissatisfied with GNU Go's performance.

2.2.1 Ram Cache  
2.2.2 Default Level  
2.2.3 Other Options  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.1 Ram Cache

By default, GNU Go makes a cache of 8 Megabytes in RAM for its internal use. The cache is used to store intermediate results during its analysis of the position.

Increasing the cache size will often give a modest speed improvement. If your system has lots of RAM, consider increasing the cache size. But if the cache is too large, swapping will occur, causing hard drive accesses and degrading performance. If your hard drive seems to be running excessively your cache may be too large. On GNU/Linux systems, you may detect swapping using the program 'top'. Use the 'f' command to toggle SWAP display.

You may override the size of the default cache at compile time by running one of:

 
   ./configure --enable-cache-size=n

to set the cache size to n megabytes. For example

 
   ./configure --enable-cache-size=32

creates a cache of size 32 megabytes. If you omit this, your default cache size will be 8 MB. You must recompile and reinstall GNU Go after reconfiguring it by running make and make install.

You may override the compile-time defaults by running `gnugo' with the option `--cache-size n', where n is the size in megabytes of the cache you want, and `--level' where n is the level desired. We will discuss setting these parameters next in detail.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.2 Default Level

GNU Go can play at different levels. Up to level 10 is supported. At level 10 GNU Go is much more accurate but takes an average of about 1.6 times longer to play than at level 8.

The level can be set at run time using the `--level' option. If you don't set this, the default level will be used. You can set the default level with the configure option `--enable-level=n'. For example

 
./configure --enable-level=9

sets the default level to 9. If you omit this parameter, the compiler sets the default level to 10. We recommend using level 10 unless you find it too slow. If you decide you want to change the default you may rerun configure and recompile the program.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.3 Other Options

Anything new in the engine is generally tested as an experimental option which can be turned on or off at compile time or run time. Some "experimental" options such as the break-in code are no longer experimental but are enabled by default.

This section can be skipped unless you are interested in the experimental options.

Moreover, some configure options were removed from the stable release. For example it is known that the owl extension code can cause crashes, so the configure option --enable-experimental-owl-ext was disabled for 3.6.

The term "default" must be clarified, since there are really two sets of defaults at hand, runtime defaults specified in `config.h' and compile time default values for the runtime defaults, contained in `configure' (which is created by editing `configure.in' then running autoconf. For example we find in `config.h'

 
/* Center oriented influence. Disabled by default. */
#define COSMIC_GNUGO 0

/* Break-in module. Enabled by default. */
#define USE_BREAK_IN 1

This means that the experimental cosmic option, which causes GNU Go to play a center-oriented game (and makes the engine weaker) is disabled by default, but that the break-in module is used. These are defaults which are used when GNU Go is run without command line options. They can be overridden with the run time options:

 
gnugo --cosmic-gnugo --without-break-in

Alternatively you can configure GNU Go as follows:

 
./configure --enable-cosmic-gnugo --disable-experimental-break-in

then recompile GNU Go. This changes the defaults in `config.h', so that you do not have to pass any command line options to GNU Go at run time to get the experimental owl extension turned on and the experimental break-in code turned off.

If you want to find out what experimental options were compiled into your GNU Go binary you can run gnugo --options to find out. Here is a list of experimental options in GNU Go.

Other options are not experimental, and can be changed as configure or runtime options.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3 Compiling GNU Go on Microsoft platforms

GNU Go is being developed on Unix variants. GNU Go is easy to build and install on those platforms. GNU Go 3.6 has support for building on MS-DOS, Windows 3.x, Windows NT/2000 and Windows 95/98.

There are two approaches to building GNU Go on Microsoft platforms.

  1. The first approach is to install a Unix-like environment based on ports of GCC to Microsoft platforms. This approach is fully supported by the GNU Go developers and works well. Several high quality free Unix-environments for Microsoft platforms are available.

    One benefit of this approach is that it is easier to participate in GNU Go's development. These unix environments come for instance with the `diff' and `patch' programs necessary to generate and apply patches.

    Another benefit of the unix environments is that development versions (which may be stronger than the latest stable version) can be built too. The supporting files for VC are not always actively worked on and consequently are often out of sync for development versions, so that VC will not build cleanly.

  2. The second approach is to use compilers such as Visual C developed specially for the Microsoft platform. GNU Go 2.6 and later support Visual C. Presently we support Visual C through the project files which are supplied with the distribution.

The rest of this section gives more details on the various ways to compile GNU go for Microsoft platforms.

2.3.1 Windows 95/98, MS-DOS and Windows 3.x using DJGPP  
2.3.2 Windows NT, 2000, XP, 95/98/ME using Cygwin  Windows NT, 95/98 using Cygwin
2.3.3 Windows NT, 2000, XP, 95/98/ME using MinGW32  Windows NT, 95/98 using MINGW32
2.3.4 Windows NT, Windows 95/98 using Visual C and project files  Visual C++ using Project Files


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1 Windows 95/98, MS-DOS and Windows 3.x using DJGPP

On these platforms DJGPP can be used. GNU Go installation has been tested in a DOS-Box with long filenames on Windows 95/98. GNU Go compiles out-of-the box with the DJGPP port of GCC using the standard Unix build and install procedure.

Some URLs for DJGPP:

DJGPP home page: http://www.delorie.com/djgpp/

DJGPP ftp archive on simtel:

ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2/

ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/

Once you have a working DJGPP environment and you have downloaded the GNU Go source available as gnugo-3.6.tar.gz you can build the executable as follows:

 
       tar zxvf gnugo-3.6.tar.gz
       cd gnugo-3.6
       ./configure
       make

Optionally you can download glib for DJGPP to get a working version of snprintf.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.2 Windows NT, 2000, XP, 95/98/ME using Cygwin

Cygwin is a full fledged and rapidly maturing unix environment on top of windows. Cygwin installs very easily with the interactive setup program available from the cygwin homepage at http://sources.redhat.com/cygwin/. In fact precompiled versions of stable GNU go releases as well as of the cgoban X11 GUI can be downloaded through Cygwin's setup. Cygwin's setup also provides precompiled packages of most of the unix tools necessary to participate in development.

If you want to build GNU Go yourself make sure to download the ncurses packages prior to building GNU go. GNU Go compiles out-of-the box using the standard Unix build procedure on the Cygwin environment. After installation of cygwin and fetching `gnugo-3.6.tar.gz' you can type:

 
  tar zxvf gnugo-3.6.tar.gz
  cd gnugo-3.6
  ./configure
  make

The generated executable is not a stand-alone executable: it needs cygwin1.dll that comes with the Cygwin environment. cygwin1.dll contains the emulation layer for Unix.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.3 Windows NT, 2000, XP, 95/98/ME using MinGW32

The Cygwin environment also comes with MinGW32. The mingw32 platform generates an executable that relies only on Microsoft DLLs. This executable is thus completely comparable to a Visual C executable and easier to distribute than the Cygwin executable. To build on cygwin an executable suitable for the win32 platform type the following at your cygwin prompt:

 
  tar zxvf gnugo-3.6.tar.gz
  cd gnugo-3.6
  env CC='gcc -mno-cygwin' ./configure
  make

The generated executable can be reduced in size significantly by using the upx compression program that is available through Cygwin's setup program.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.4 Windows NT, Windows 95/98 using Visual C and project files

We assume that you do not want to change any configure options. If you do, you should edit the file `config.vc'. Note that when configure is run, this file is overwritten with the contents of `config.vcin', so you may also want to edit `config.vcin', though the instructions below do not have you running configure.

  1. Open the VC++ 6 workspace file gnugo.dsw
  2. Set the gnugo project as the active project (right-click on it, and select "Set as Active Project". Select 'Build' from the main menu, then select 'Build gnugo.exe', this will make all of the runtime subprojects.

Notes:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.5 Running GNU Go on Windows NT and Windows 95/98

GNU Go does not come with its own graphical user interface. The Java client jago can be used.

To run Jago you need a Java Runtime Environment (JRE). This can be obtained from http://www.javasoft.com/. This is the runtime part of the Java Development Kit (JDK) and consists of the Java virtual machine, Java platform core classes, and supporting files. The Java virtual machine that comes with I.E. 5.0 works also.

Jago: http://www.rene-grothmann.de/jago/

  1. Invoke GNU Go with gnugo --quiet --mode gmp
  2. Run gnugo --help from a cygwin or DOS window for a list of options
  3. optionally specify --level <level> to make the game faster

Jago works well with both the Cygwin and MinGW32 executables. The DJGPP executable also works, but has some problems in the interaction with jago after the game has been finished and scored.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.4 Macintosh

If you have Mac OS X you can build GNU Go using Apple's compiler, which is derived from GCC.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Using GNU Go

3.1 Getting Documentation  
3.2 Running GNU Go via CGoban  Running GNU Go with CGoban
3.3 Other Clients  
3.4 Ascii Interface  The Ascii Interface
3.5 GNU Go mode in Emacs  
3.6 The Go Modem Protocol and Go Text Protocol  
3.7 Computer Go Tournaments  Computer Tournaments
3.8 Smart Game Format  The Smart Game Format
3.9 Invoking GNU Go: Command line options  Command line options


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 Getting Documentation

You can obtain a printed copy of the manual by running make gnugo.ps in the `doc/'directory, then printing the resulting postscript file. The manual contains a great deal of information about the algorithms of GNU Go.

On platforms supporting info documentation, you can usually install the manual by executing `make install' (running as root) from the `doc/' directory. The info documentation can be read conveniently from within Emacs by executing the command Control-h i.

Documentation in `doc/' consists of a man page `gnugo.6', the info files `gnugo.info', `gnugo.info-1', ... and the Texinfo files from which the info files are built. The Texinfo documentation contains this User's Guide and extensive information about the algorithms of GNU Go, for developers.

If you want a typeset copy of the Texinfo documentation, you can make gnugo.dvi, make gnugo.ps, or make gnugo.pdf in the `doc/' directory. (make gnugo.pdf only works after you have converted all .eps-files in the doc/ directory to .pdf files, e.g. with the utility epstopdf.)

You can make an HTML version with the command makeinfo --html gnugo.texi. If you have texi2html, better HTML documentation may be obtained by make gnugo.html in the `doc/' directory.

User documentation can be obtained by running gnugo --help or man gnugo from any terminal, or from the Texinfo documentation.

Documentation for developers is in the Texinfo documentation, and in comments throughout the source. Contact us at gnugo@gnu.org if you are interested in helping to develop this program.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Running GNU Go via CGoban

There are two different programs called CGoban, both written by William Shubert. In this documentation, CGoban means CGoban 1.x, the older program. You should get a copy with version number 1.12 or higher.

CGoban is an extremely nice way to run GNU Go. CGoban provides a beautiful graphic user interface under X-Windows.

Start CGoban. When the CGoban Control panel comes up, select "Go Modem". You will get the Go Modem Protocol Setup. Choose one (or both) of the players to be "Program," and fill out the box with the path to `gnugo'. After clicking OK, you get the Game Setup window. Choose "Rules Set" to be Japanese (otherwise handicaps won't work). Set the board size and handicap if you want.

If you want to play with a komi, you should bear in mind that the GMP does not have any provision for communicating the komi. Because of this misfeature, unless you set the komi at the command line GNU Go will have to guess it. It assumes the komi is 5.5 for even games, 0.5 for handicap games. If this is not what you want, you can specify the komi at the command line with the `--komi' option, in the Go Modem Protocol Setup window. You have to set the komi again in the Game Setup window, which comes up next.

Click OK and you are ready to go.

In the Go Modem Protocol Setup window, when you specify the path to GNU Go, you can give it command line options, such as `--quiet' to suppress most messages. Since the Go Modem Protocol preempts standard I/O other messages are sent to stderr, even if they are not error messages. These will appear in the terminal from which you started CGoban.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 Other Clients

In addition to CGoban (see section 3.2 Running GNU Go via CGoban) there are a number of other good clients that are capable of running GNU Go. Here are the ones that we are aware of that are Free Software. This list is part of a larger list of free Go programs that is maintained at http://www.gnu.org/software/gnugo/free_go_software.html.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 Ascii Interface

Even if you do not have CGoban installed you can play with GNU Go using its default Ascii interface. Simply type gnugo at the command line, and GNU Go will draw a board. Typing help will give a list of options. At the end of the game, pass twice, and GNU Go will prompt you through the counting. You and GNU Go must agree on the dead groups--you can toggle the status of groups to be removed, and when you are done, GNU Go will report the score.

You can save the game at any point using the save filename command. You can reload the game from the resulting SGF file with the command gnugo -l filename --mode ascii. Reloading games is not supported when playing with CGoban. However you can use CGoban to save a file, then reload it in ascii mode.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5 GNU Go mode in Emacs

You can run GNU Go from Emacs. This has the advantage that you place the stones using the cursor arrow keys or with the mouse, and (provided you have Emacs version 21 or later) you can have a nice graphical display of the board within emacs.

Load the file `interface/gnugo.el' and (if you want the graphical board) `interface/gnugo-xpms.el'. You may do this using the Emacs M-x load-file command.

In detail: Emacs uses Control and Meta keys. The "Meta" key is the Alt key on the PC keyboard. The Control and Meta keys are denoted C- and M-. Thus the M-x is obtained by holding the Alt key and typing `x'. In Emacs, this prompts you for another command. You can then type load-file, hit the Enter key, then type the path to `gnugo.el' and hit Enter again. Then repeat the process for `gnugo-xpms.el'.

To have the files `gnugo.el' and `gnugo-xpms.el' loaded automatically each time you run emacs, copy the files into your `site-lisp' directory (often `/usr/share/emacs/site-lisp') and add lines

 
(autoload 'gnugo "gnugo" "GNU Go" t)
(autoload 'gnugo-xpms "gnugo-xpms" "GNU Go" t)

in your `.emacs' file.

The `.xpm' bitmaps for the default size Go stones are 30 pixels. For a larger board, alternative 36 pixel stones may be found in `gnugo-big-xpms.el'.

You may start GNU Go by M-x gnugo. You will be prompted for command line options (see section 3.9 Invoking GNU Go: Command line options). Using these, you may set the handicap, board size, color and komi. For example if you want to play white and give a nine-stone handicap, use the options `--handicap 9 --color white'.

By default, Emacs gives you a graphical Go board. You can toggle an alternative ascii board (for example, if you want to paste a diagram into an email) with gnugo-toggle-image-display, which is bound to `i'. If you want a grid, `g' toggles the grid display on or off. The grid is not displayed by default.

You play a move either by moving to the location with the arrow keys, then hitting the SPACE key, or by clicking on an empty location with the mouse. You can save or load a game, and undo moves.

You can get help at any time by typing `?'. This will give a description of the default keybindings. If you want to find out what a particular function does, you can use `C-h f <function-name>' to get documentation on it. For example, after examining the default keybindings with `?' we learn that `v' is bound to gnugo-view-regression. To find out more information about this function we type `C-h f gnugo-view-regression' to view the help string for the function.

You may save the game you are playing as an sgf file with gnugo-write-sgf-file, which is bound to `s'. You may also restore a saved game with gnugo-read-sgf-file, bound to `l'. When the sgf file is loaded, it is assumed to be your move, since typically the game is saved on your move. You may resume play by entering a move.

At the end of the game, after both players pass, GNU Go will run gnugo-venerate to render all dead stones as ghostly shades. You can then type `F' to run gnugo-display-final-score, which will tell you the score. (You may get a score estimate at any time before the end of the game with gnugo-estimate-score, bound to `!'.

You may undo your move with gnugo-undo-two-moves, which is bound to `u'. This takes back your move, and also the last computer move, so it goes back to the position two moves ago. If you undo one or many moves, you may redo them with gnugo-redo-two-moves, which is bound to `r'.

Although if you are playing a game it is most natural to undo or redo two moves at a time, since this does not change the color of the player to move, you may also undo or redo a single move with gnugo-undo and gnugo-redo, bound to `b' and `f'. This is convenient for scrolling forward or backward in a game to review the moves. Note that if you undo once, then play a move (by clicking on the board, or by hitting the space or enter key), you have changed the color of the player to move. GNU Go will begin to generate moves as soon as you play.

You may also use gnugo-jump-to-move, bound to `j' to jump to a particular move in the game. You will be prompted for the game move. After you type the number of the move, Emacs will undo back to that move number. You may then redo or further undo using `f' and `f'. You may also jump to the beginning or end of the game with `<' and `>'.

Another way to undo back to a given move is to move the cursor to a stone (which must be one of your own), then execute gnugo-magic-undo, bound to `U'.

As we have noted, GNU Go normally answers each move that you play by generating a move of its own. If you want to suppress GNU Go's automatic generation of moves, you may toggle an `editing mode' with gnugo-toggle-edit-mode. In the editing mode, GNU Go does not automatically answer each move that you play. For example, you can use the editing mode to write an sgf file from scratch. If you are playing a game, you can turn off GNU Go's automatic responses, play a few moves in editing mode to see what the board position will look like, then back up to the last move, toggle the editing mode off, then resume the game.

You may view a GNU Go regression test with gnugo-view-regression, which will prompt you for the name of a test. You may type (for example) strategy:6. The first time you do this you will be prompted for the path to the `regression/' directory. (Once Emacs knows this path, you will not be prompted again.) This command takes a while to execute since GNU Go will run the regression. When it is completed, Emacs will display the board position (with the grid) and a message below the board such as:

 
 loadsgf games/incident104.sgf 63
 strategy:6 reg_genmove white
 #? [E10]*
 =6 J13
This gives the actual test followed by the move that GNU Go generates when running the test.

You may also ask GNU Go to identify a dragon on the board. Click on one stone to move the cursor to that location. Then type `d'. The dragon in question will then be marked flashing. You may also type `D', which will report the dragon data. You may run other gtp commands with gnugo-command, which is bound to `:'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6 The Go Modem Protocol and Go Text Protocol

The Go Modem Protocol (GMP) was developed by Bruce Wilcox with input from David Fotland, Anders Kierulf and others, according to the history in http://www.britgo.org/tech/gmp.html.

Any Go program should support this protocol since it is a standard. Since CGoban supports this protocol, the user interface for any Go program can be done entirely through CGoban. The programmer can concentrate on the real issues without worrying about drawing stones, resizing the board and other distracting issues.

GNU Go 3.0 introduced a new protocol, the Go Text Protocol (see section 19. The Go Text Protocol) which we hope can serve the functions currently used by the GMP. The GTP is becoming increasingly adopted by other programs as a method of interprocess communication, both by computer programs and by clients. Still the GMP is widely used in tournaments.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7 Computer Go Tournaments

Computer Tournaments currently use the Go Modem Protocol. The current method followed in such tournaments is to connect the serial ports of the two computers by a "null modem" cable. If you are running GNU/Linux it is convenient to use CGoban. If your program is black, set it up in the Go Modem Protocol Setup window as usual. For White, select "Device" and set the device to `/dev/cua0' if your serial port is COM1 and `/dev/cua1' if the port is COM2.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8 Smart Game Format

The Smart Game Format (SGF), is the standard format for storing Go games. GNU Go supports both reading and writing SGF files. The SGF specification (FF[4]) is at: http://www.red-bean.com/sgf/


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9 Invoking GNU Go: Command line options


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.1 Some basic options


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.2 Other general options


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.3 Other options affecting strength and speed

This single parameter `--level' is the best way of choosing whether to play stronger or faster. It controls a host of other parameters which may themselves be set individually at the command line. The default values of these parameters may be found by running gnugo --help.

Unless you are working on the program you probably don't need these options. Instead, just adjust the single variable `--level'. The remaining options are of use to developers tuning the program for performance and accuracy. For completeness, here they are.

The preceeding options are documented with the reading code (see section 11.1 Reading Basics).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.4 Ascii mode options


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.5 Development options


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9.6 Experimental options

Most of these are available as configure options and are described in 2.2.3 Other Options.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. GNU Go engine overview

This chapter is an overview of the GNU Go internals. Further documentation of how any one module or routine works may be found in later chapters or comments in the source files.

GNU Go starts by trying to understand the current board position as good as possible. Using the information found in this first phase, and using additional move generators, a list of candidate moves is generated. Finally, each of the candidate moves is valued according to its territorial value (including captures or life-and-death effects), and possible strategical effects (such as strengthening a weak group).

Note that while GNU Go does, of course, do a lot of reading to analyze possible captures, life and death of groups etc., it does not (yet) have a fullboard lookahead.

4.1 Gathering Information  
4.2 Move Generators  Selecting Candidate Moves
4.3 Move Valuation  Selecting the best Move
4.4 Detailed Sequence of Events  Outline of genmove().
4.5 Roadmap  Description of the different files.
4.6 Coding styles and conventions  Coding conventions.
4.7 Navigating the Source  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Gathering Information

This is by far the most important phase in the move generation. Misunderstanding life-and-death situations can cause gross mistakes. Wrong territory estimates will lead to inaccurate move valuations. Bad judgement of weaknesses of groups make strategic mistakes likely.

This information gathering is done by the function examine_position(). It first calls make_worms().

Its first steps are very simple: it identifies sets of directly connected stones, called worms, and notes their sizes and their number of liberties.

Soon after comes the most important step of the worm analysis: the tactical reading code (see section 11. Tactical reading) is called for every worm. It tries to read out which worms can be captured directly, giving up as soon as a worm can reach 5 liberties. If a worm can be captured, the engine of course looks for moves defending against this capture. Also, a lot of effort is made to find virtually all moves that achieve the capture or defense of a worm.

After knowing which worms are tactically stable, we can make a first picture of the balance of power across the board: the 13. Influence Function code is called for the first time.

This is to aid the next step, the analysis of dragons. By a dragon we mean a group of stones that cannot be disconnected.

Naturally the first step in the responsible function make_dragons() is to identify these dragons, i.e. determine which worms cannot be disconnected from each other. This is partly done by patterns, but in most cases the specialized readconnect code is called. This module does a minimax search to determine whether two given worms can be connected with, resp. disconnected from each other.

Then we compute various measures to determine how strong or weak any given dragon is:

For those dragons that are considered weak, a life and death analysis is made (see section 12.1 The Owl Code). If two dragons next to each other are found that are both not alive, we try to resolve this situation with the semeai module.

For a more detailed reference of the worm and dragon analysis (and explanations of the data structures used to store the information), see See section 7. Worms and Dragons.

The influence code is then called second time to make a detailed analysis of likely territory. Of course, the life-and-death status of dragons are now taken into account.

The territorial results of the influence module get corrected by the break-in module. This specifically tries to analyze where an opponent could break into an alleged territory, with sequences that would be too difficult to see for the influence code.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Move Generators

Once we have found out all about the position it is time to generate the best move. Moves are proposed by a number of different modules called move generators. The move generators themselves do not set the values of the moves, but enumerate justifications for them, called move reasons. The valuation of the moves comes last, after all moves and their reasons have been generated.

For a list and explanation of move reasons used in GNU Go, and how they are evaluated, see See section 6. Move generation.

There are a couple of move generators that only extract data found in the previous phase, examining the position:

The following move generators do additional work:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 Move Valuation

After the move generation modules have run, each proposed candidate move goes through a detailed valuation by the function review_move_reasons. This invokes some analysis to try to turn up other move reasons that may have been missed.

The most important value of a move is its territorial effect. see section 13.4 Influence and Territory explains in detail how this is determined.

This value is modified for all move reasons that cannot be expressed directly in terms of territory, such as combination attacks (where it is not clear which of several strings will get captured), strategical effects, connection moves, etc. A large set heuristics is necessary here, e.g. to avoid duplication of such values. This is explained in more detail in 6.4 Valuation of suggested moves.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 Detailed Sequence of Events

First comes the sequence of events when examine_position() is run from genmove(). This is for reference only.

 
purge_persistent_caches()
make_worms():
  compute_effective_sizes()
  compute_unconditional_status()
  find_worm_attacks_and_defenses():      
    for each attackable worm:
      set worm.attack
      change_attack() to add the attack point
    find_attack_patterns() to find a few more attacks
    for each defensible worm:
      set worm.attack
      change_defense() to add the defense point
    find_defense_patterns() to find a few more defense moves
    find additional attacks and defenses by testing all
      immediate liberties
  find higher order liberties (for each worm)
  find cutting stones (for each worm)
  improve attacks and defenses: if capturing a string defends
    another friendly string, or kills an unfriendly one, we
    add points of defense or attack. Make repairs if adjacent 
    strings can both be attacked but not defended.
  find worm lunches
  find worm threats
  identify inessential worms (such as nakade stones)
compute_worm_influence():
  find_influence_patterns()
  value_influence()
  segment_influence()
make_dragons():
  find_cuts()
  find_connections()
  make_domains() (determine eyeshapes)
  find_lunches() (adjacent strings that can be captured)
  find_half_and_false_eyes()
  eye_computations(): Compute the value of each eye space. 
    Store its attack and defense point.
  analyze_false_eye_territory()
  for each dragon compute_dragon_genus()
  for each dragon compute_escape() and set escape route data
  resegment_initial_influence()
  compute_refined_dragon_weaknesses() (called again after owl)
  for each dragon compute_crude_status()
  find_neighbor_dragons()
  for each dragon compute surround status
  for each weak dragon run owl_attack() and owl_defend() 
    to determine points of attack and defense
  for each dragon compute dragon.status
  for each thrashing dragon compute owl threats
  for each dragon compute dragon.safety
  revise_inessentiality()
  semeai():
    for every semeai, run owl_analyze_semeai()
    find_moves_to_make_seki()
  identify_thrashing_dragons()
  compute_dragon_influence():
    compute_influence()
    break_territories() (see section 13.10 Break Ins)
  compute_refined_dragon_weaknesses()

Now a summary of the sequence of events during the move generation and selection phases of genmove(), which take place after the information gathering phase has been completed:

 
estimate_score()
choose_strategy()
collect_move_reasons():
  worm_reasons(): for each attack and defense point add a move reason
  semeai_reasons(): for each dragon2.semeai point add a move reason
  owl_reasons(): for each owl attack and defense point add a move reason
  break_in_reasons(): for each breakin found add a move reason
fuseki()
break_mirror_go()
shapes(): match patterns around the board (see section 9.1 Overview)
combinations(): look for moves with a double meaning and other tricks
  find_double_threats()
  atari_atari()
review_move_reasons()
if ahead and there is a thrashing dragon, consider it 
  alive and reconsider the position
endgame_shapes()
endgame()
if no move found yet, revisit any semeai, change status of dead opponent
  to alive, then run shapes() and endgame_shapes() again
if no move found yet, run fill_liberty()


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 Roadmap

The GNU Go engine is contained in two directories, `engine/' and `patterns/'. Code related to the user interface, reading and writing of Smart Game Format files, and testing are found in the directories `interface/', `sgf/', and `regression/'. Code borrowed from other GNU programs is contained in `utils/'. That directory also includes some code developed within GNU Go which is not go specific. Documentation is in `doc/'.

In this document we will describe some of the individual files comprising the engine code in `engine/' and `patterns/'. In `interface/' we mention two files:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.1 Files in `engine/'

In `engine/' there are the following files:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.2 Files in `patterns/'

The directory `patterns/' contains files related to pattern matching. Currently there are several types of patterns. A partial list:

The following list contains, in addition to distributed source files some intermediate automatically generated files such as `patterns.c'. These are C source files produced by "compiling" various pattern databases, or in some cases (such as `hoshi.db') themselves automatically generated pattern databases produced by "compiling" joseki files in Smart Game Format.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6 Coding styles and conventions


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6.1 Coding Conventions

Please follow the coding conventions at: http://www.gnu.org/prep/standards_toc.html

Please preface every function with a brief description of its usage.

Please help to keep this Texinfo documentation up-to-date.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6.2 Tracing

A function gprintf() is provided. It is a cut-down printf, supporting only %c, %d, %s, and without field widths, etc. It does, however, add some useful facilities:

Normally gprintf() is wrapped in one of the following:

TRACE(fmt, ...):

Print the message if the 'verbose' variable > 0. (verbose is set by -t on the command line)

DEBUG(flags, fmt, ...):

While TRACE is intended to afford an overview of what GNU Go is considering, DEBUG allows occasional in depth study of a module, usually needed when something goes wrong. flags is one of the DEBUG_* symbols in `engine/gnugo.h'. The DEBUG macro tests to see if that bit is set in the debug variable, and prints the message if it is. The debug variable is set using the -d command-line option.

The variable verbose controls the tracing. It can equal 0 (no trace), 1, 2, 3 or 4 for increasing levels of tracing. You can set the trace level at the command line by `-t' for verbose=1, `-t -t' for verbose=2, etc. But in practice if you want more verbose tracing than level 1 it is better to use GDB to reach the point where you want the tracing; you will often find that the variable verbose has been temporarily set to zero and you can use the GDB command set var verbose=1 to turn the tracing back on.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6.3 Assertions

Related to tracing are assertions. Developers are strongly encouraged to pepper their code with assertions to ensure that data structures are as they expect. For example, the helper functions make assertions about the contents of the board in the vicinity of the move they are evaluating.

ASSERT() is a wrapper around the standard C assert() function. In addition to the test, it takes an extra pair of parameters which are the co-ordinates of a "relevant" board position. If an assertion fails, the board position is included in the trace output, and showboard() and popgo() are called to unwind and display the stack.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6.4 FIXME

We have adopted the convention of putting the word FIXME in comments to denote known bugs, etc.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.7 Navigating the Source

If you are using Emacs, you may find it fast and convenient to use Emacs' built-in facility for navigating the source. Switch to the root directory `gnugo-3.6/' and execute the command:

 
find . -print|grep "\.[ch]$" | xargs etags

This will build a file called `gnugo-3.6/TAGS'. Now to find any GNU Go function, type M-. and enter the command which you wish to find, or just RET if the cursor is at the name of the function sought.

The first time you do this you will be prompted for the location of the TAGS table. Enter the path to `gnugo-3.6/TAGS', and henceforth you will be able to find any function with a minimum of keystrokes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5. Analyzing GNU Go's moves

In this chapter we will discuss methods of finding out how GNU Go understands a given position. These methods will be of interest to anyone working on the program, or simply curious about its workings.

In practice, most tuning of GNU Go is done in conjunction with maintaining the `regression/' directory (see section 20. Regression testing).

We assume that you have a game GNU Go played saved as an sgf file, and you want to know why it made a certain move.

5.1 Interpreting Traces  Analyzing traces in GNU Go 3.6
5.2 The Output File  
5.3 Checking the reading code  
5.4 Checking the Owl Code  Checking the owl code
5.5 GTP and GDB techniques  
5.6 Debugging on a Graphical Board  Debugging on a Graphic Board
5.7 Scoring the game  Finding out the winner of the game
5.8 Colored Display  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.1 Interpreting Traces

A quick way to find out roughly the reason for a move is to run

 
gnugo -l filename -t -L move number

(You may also want to add `--quiet' to suppress the copyright message.) In GNU Go 3.6, the moves together with their reasons are listed, followed by a numerical analysis of the values given to each move.

If you are tuning (see section 9.11 Tuning the Pattern databases) you may want to add the `-a' option. This causes GNU Go to report all patterns matched, even ones that cannot affect the outcome of the move. The reasons for doing this is that you may want to modify a pattern already matched instead of introducing a new one.

If you use the `-w' option, GNU Go will report the statuses of worms and dragons around the board. This type of information is available by different methods, however (see section 5.6 Debugging on a Graphical Board, see section 5.8 Colored Display).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.2 The Output File

If GNU Go is invoked with the option `-o filename' it will produce an output file. This option can be added at the command line in the Go Modem Protocol Setup Window of CGoban. The output file will show the locations of the moves considered and their weights. It is worth noting that by enlarging the CGoban window to its fullest size it can display 3 digit numbers. Dragons with status DEAD are labelled with an `X', and dragons with status CRITICAL are labelled with a `!'.

If you have a game file which is not commented this way, or which was produced by a non-current version of GNU Go you may ask GNU Go to produce a commented version by running:

 
gnugo --quiet -l <old file> --replay <color> -o <new file>

Here <color> can be 'black,' 'white' or 'both'. The replay option will also help you to find out if your current version of GNU Go would play differently than the program that created the file.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3 Checking the reading code

The `--decide-string' option is used to check the tactical reading code (see section 11. Tactical reading). This option takes an argument, which is a location on the board in the usual algebraic notation (e.g. `--decide-string C17'). This will tell you whether the reading code (in `engine/reading.c') believes the string can be captured, and if so, whether it believes it can be defended, which moves it finds to attack or defend the move, how many nodes it searched in coming to these conclusions. Note that when GNU Go runs normally (not with `--decide-string') the points of attack and defense are computed when make_worms() runs and cached in worm.attack and worm.defend.

If used with an output file (`-o filename') `--decide-string' will produce a variation tree showing all the variations which are considered. This is a useful way of debugging the reading code, and also of educating yourself with the way it works. The variation tree can be displayed graphically using CGoban.

At each node, the comment contains some information. For example you may find a comment:

 
attack4-B at D12 (variation 6, hash 51180fdf)
break_chain D12: 0
defend3 D12: 1 G12 (trivial extension)

This is to be interpreted as follows. The node in question was generated by the function attack3() in `engine/reading.c', which was called on the string at D12. The data in parentheses tell you the values of count_variations and hashdata.hashval.

The second value ("hash") you probably will not need to know unless you are debugging the hash code, and we will not discuss it. But the first value ("variation") is useful when using the debugger gdb. You can first make an output file using the `-o' option, then walk through the reading with gdb, and to coordinate the SGF file with the debugger, display the value of count_variations. Specifically, from the debugger you can find out where you are as follows:

 
(gdb) set dump_stack()
B:D13 W:E12 B:E13 W:F12 B:F11  (variation 6)

If you place yourself right after the call to trymove() which generated the move in question, then the variation number in the SGF file should match the variation number displayed by dump_stack(), and the move in question will be the last move played (F11 in this example).

This displays the sequence of moves leading up to the variation in question, and it also prints count_variations-1.

The second two lines tell you that from this node, the function break_chain() was called at D12 and returned 0 meaning that no way was found of rescuing the string by attacking an element of the surrounding chain, and the function defend3() was called also at D12 and returned 1, meaning that the string can be defended, and that G12 is the move that defends it. If you have trouble finding the function calls which generate these comments, try setting sgf_dumptree=1 and setting a breakpoint in sgf_trace.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.4 Checking the Owl Code

You can similarly debug the Owl code using the option `--decide-dragon'. Usage is entirely similar to `--decide-string', and it can be used similarly to produce variation trees. These should be typically much smaller than the variation trees produced by `--decide-string'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.5 GTP and GDB techniques

You can use the Go Text Protocol (see section 19. The Go Text Protocol) to determine the statuses of dragons and other information needed for debugging. The GTP command dragon_data P12 will list the dragon data of the dragon at P12 and worm_data will list the worm data; other GTP commands may be useful as well.

You can also conveniently get such information from GDB. A suggested `.gdbinit' file may be found in See section 11.9 Debugging the reading code. Assuming this file is loaded, you can list the dragon data with the command:

 
(gdb) dragon P12

Similarly you can get the worm data with worm P12.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.6 Debugging on a Graphical Board

The quickest way to analyze most positions is to use the tool `view.pike' in the `regression' directory. It can be started with a testcase specified, e.g. pike view.pike strategy:40 or at a move in an sgf file, e.g. pike view.pike mistake.sgf:125. When started it shows the position on a grapical board on which it also marks information like move values, dragon status, and so on. By clicking on the board further information about the valuation of moves, contents of various data structures, and other data can be made available.

Specific information on how to use `view.pike' for influence tuning can be found in See section 13.14 Influence Tuning with view.pike.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.7 Scoring the game

GNU Go can score the game. Normally GNU Go will report its opinion about the score at the end of the game, but if you want this information about a game stored in a file, use the `--score' option (see section 3.9 Invoking GNU Go: Command line options).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.8 Colored Display

Various colored displays of the board may be obtained in a color xterm or rxvt window. Xterm will only work if xterm is compiled with color support. If the colors are not displayed on your xterm, try rxvt. You may also use the Linux console. The colored display will work best if the background color is black; if this is not the case you may want to edit your `.Xdefaults' file or add the options `-bg black -fg white' to xterm or rxvt. On Mac OS X put setenv TERM xterm-color in your `.tcshrc' file to enable color in the terminal.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.8.1 Dragon Display

You can get a colored ASCII display of the board in which each dragon is assigned a different letter; and the different matcher_status values (ALIVE, DEAD, UNKNOWN, CRITICAL) have different colors. This is very handy for debugging. Actually two diagrams are generated. The reason for this is concerns the way the matcher status is computed. The dragon_status (see section 7.5 Dragons) is computed first, then for some, but not all dragons, a more accurate owl status is computed. The matcher status is the owl status if available; otherwise it is the dragon_status. Both the dragon_status and the owl_status are displayed. The color scheme is as follows:

 
green = alive
cyan = dead
red = critical
yellow = unknown
magenta = unchecked

To get the colored display, save a game in sgf format using CGoban, or using the `-o' option with GNU Go itself.

Open an xterm or rxvt window.

Execute gnugo -l [filename] -L [movenum] -T to get the colored display.

Other useful colored displays may be obtained by using instead:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.8.2 Eye Space Display

Instead of `-T', try this with `-E'. This gives a colored display of the eyespaces, with marginal eye spaces marked `!' (see section 8. Eyes and Half Eyes).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.8.3 Moyo Display

The option `-m level' can give colored displays of the various quantities which are computed in `engine/moyo.c'.

GNU Go contains two distinct implementations of the concepts of Territory, Moyo and Area (see section 13.2 Territory, Moyo and Area). Primarily GNU Go computes Territory, Moyo and Area using the influence code, and reports them with the functions whose_territory(), whose_moyo() and whose_area(). To get a colored display of the influence regions found by this module, use `-m 0x18' to see the initial influence, and e.g. `-m 0x10 --debug-influence D5' to see the influence after having made the move D5. There are various other options available for numerical displays influence; for a detailed description see 13.13 Colored display and debugging of influence.

The regions found by Bouzy's algorithm (see section 14. Another approach to Moyos : Bouzy's 5/21 algorithm) are used only in the function estimate_score(). These can be displayed with the following options:

 
`-m level'
 use or (hexadecimal)   cumulative values for printing these reports :
    1       0x01         ascii printing of territorial evaluation (5/21)
    2       0x02         ascii printing of moyo evaluation (5/10)
    4       0x04         ascii printing of area (4/0)

The `-m' options can be combined by adding the levels.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Move generation

6.1 Introduction  
6.2 Generation of move reasons  
6.3 Detailed Descriptions of various Move Reasons  Detailed Descriptions of Move Reasons
6.4 Valuation of suggested moves  Valuating the moves
6.5 End Game  Endgame move generation


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.1 Introduction

GNU Go 3.0 introduced a move generation scheme substantially different from earlier versions. In particular, it was different from the method of move generation in GNU Go 2.6.

In the old scheme, various move generators suggested different moves with attached values. The highest such value then decided the move. There were two important drawbacks with this scheme:

The basic idea of the new move generation scheme is that the various move generators suggest reasons for moves, e.g. that a move captures something or connects two strings, and so on. When all reasons for the different moves have been found, the valuation starts. The primary advantages are


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.2 Generation of move reasons

Each move generator suggests a number of moves. It justifies each move suggestion with one or move move reasons. These move reasons are collected at each intersection where the moves are suggested for later valuation. Here is a partial list of of move reasons considered by GNU Go. (The complete list may be found in `move_reasons.h'.)

ATTACK_MOVE
DEFEND_MOVE
Attack or defend a worm.
ATTACK_THREAT_MOVE
DEFEND_THREAT_MOVE
Threaten to attack or defend a worm.
EITHER_MOVE
A move that either achieves one goal or another (at the moment this only used for attacks on worms).
ALL_MOVE
At the moment this is used for a move that defends two worms threatened by a double attack.
CONNECT_MOVE
CUT_MOVE
Connect or cut two worms.
ANTISUJI_MOVE
Declare an antisuji or forbidden move.
SEMEAI_MOVE
SEMEAI_THREAT
Win or threaten to win a semeai.
EXPAND_TERRITORY_MOVE
EXPAND_MOYO_MOVE
Move expanding our territory/moyo. These reasons are at the moment treated identically.
VITAL_EYE_MOVE
A vital point for life and death.
STRATEGIC_ATTACK_MOVE
STRATEGIC_DEFEND_MOVE
Moves added by 'a' and 'd' class patterns (see section 9.2 Pattern Attributes) which (perhaps intangibly) attack or defend a dragon.
OWL_ATTACK_MOVE
OWL_DEFEND_MOVE
An owl attack or defense move.
OWL_ATTACK_THREAT
OWL_DEFEND_THREAT
A threat to owl attack or defend a group.
OWL_PREVENT_THREAT
A move to remove an owl threat.
UNCERTAIN_OWL_ATTACK
UNCERTAIN_OWL_DEFENSE
An uncertain owl attack or defense. This means that the owl code could not decide the outcome, because the owl node limit was reached.
MY_ATARI_ATARI_MOVE
A move that starts a chain of ataris, eventually leading to a capture.
YOUR_ATARI_ATARI_MOVE
A move that if played by the opponent starts a chain of ataris for the opponent, leading to capture, which is also a safe move for us. Preemptively playing such a move almost always defends the threat.

The attack and defend move types can have a suffix to denote moves whose result depends on a ko, e.g. OWL_ATTACK_MOVE_GOOD_KO. Here ..._GOOD_KO and ..._BAD_KO correspond to KO_A and KO_B as explained in 11.4 Ko Handling. See `engine/move_reasons.h' for the full of move reasons.

NOTE: Some of these are reasons for not playing a move.

More detailed discussion of these move reasons will be found in the next section.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3 Detailed Descriptions of various Move Reasons

6.3.1 Attacking and defending moves  Worm Attack and Defense
6.3.2 Threats to Attack or Defend  Worm Threats
6.3.3 Multiple attack or defense moves  Combined Attacks and Defenses
6.3.4 Cutting and connecting moves  Cutting and Connecting moves
6.3.5 Semeai winning moves  
6.3.6 Making or destroying eyes  Vital eye moves
6.3.7 Antisuji moves  Never play these!
6.3.8 Territorial moves  Block or expand territory
6.3.9 Attacking and Defending Dragons  Owl Attack and Defense
6.3.10 Combination Attacks  Coordinated threats such as double ataris


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.1 Attacking and defending moves

A move which tactically captures a worm is called an attack move and a move which saves a worm from being tactically captured is called a defense move. It is understood that a defense move can only exist if the worm can be captured, and that a worm without defense only is attacked by moves that decrease the liberty count or perform necessary backfilling.

It is important that all moves which attack or defend a certain string are found, so that the move generation can make an informed choice about how to perform a capture, or find moves which capture and/or defend several worms.

Attacking and defending moves are first found in make_worms while it evaluates the tactical status of all worms, although this step only gives one attack and defense (if any) move per worm. Immediately after, still in make_worms, all liberties of the attacked worms are tested for additional attack and defense moves. More indirect moves are found by find_attack_patterns and find_defense_patterns, which match the A (attack) and D (defense) class patterns in `patterns/attack.db' and `patterns/defense.db' As a final step, all moves which fill some purpose at all are tested whether they additionally attacks or defends some worm. (Only unstable worms are analyzed.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.2 Threats to Attack or Defend

A threat to attack a worm, but where the worm can be defended is used as a secondary move reason. This move reason can enhance the value of a move so that it becomes sente. A threatening move without any other justification can also be used as a ko threat. The same is true for a move that threatens defense of a worm, but where the worm can still be captured if the attacker doesn't tenuki.

Threats found by the owl code are called owl threats and they have their own owl reasons.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.3 Multiple attack or defense moves

Sometimes a move attacks at least one of a number of worms or simultaneously defends all of several worms. These moves are noted by their own move reasons.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.4 Cutting and connecting moves

Moves which connect two distinct dragons are called connecting moves. Moves which prevent such connections are called cutting moves. Cutting and connecting moves are primarily found by pattern matching, the C and B class patterns.

A second source of cutting and connecting moves comes from the attack and defense of cutting stones. A move which attacks a worm automatically counts as a connecting move if there are multiple dragons adjacent to the attacked worm. Similarly a defending move counts as a cutting move. The action taken when a pattern of this type is found is to induce a connect or cut move reason.

When a cut or connect move reason is registered, the involved dragons are of course stored. Thus the same move may cut and/or connect several pairs of dragons.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.5 Semeai winning moves

A move which is necessary to win a capturing race is called a semeai move. These are similar to attacking moves, except that they involve the simultaneous attack of one worm and the defense of another. As for attack and defense moves, it's important that all moves which win a semeai are found, so an informed choice can be made between them.

Semeai move reasons should be set by the semeai module. However this has not been implemented yet. One might also wish to list moves which increase the lead in a semeai race (removes ko threats) for use as secondary move reasons. Analogously if we are behind in the race.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.6 Making or destroying eyes

A move which makes a difference in the number of eyes produced from an eye space is called an eye move. It's not necessary that the eye is critical for the life and death of the dragon in question, although it will be valued substantially higher if this is the case. As usual it's important to find all moves that change the eye count.

(This is part of what eye_finder was doing. Currently it only finds one vital point for each unstable eye space.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.7 Antisuji moves

Moves which are locally inferior or for some other reason must not be played are called antisuji moves. These moves are generated by pattern matching. Care must be taken with this move reason as the move under no circumstances will be played.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.8 Territorial moves

Any move that increases territory gets a move reason. This is the expand territory move reason. That move reason is added by the `e' patterns in `patterns/patterns.db'. Similarly the `E' patterns attempt to generate or mitigate a moyo, which is a region of influence not yet secure territory, yet valuable. Such a pattern sets the "expand moyo" move reason.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.9 Attacking and Defending Dragons

Just as the tactical reading code tries to determine when a worm can be attacked or defended, the owl code tries to determine when a dragon can get two eyes and live. The function owl_reasons() generates the corresponding move reasons.

The owl attack and owl defense move reasons are self explanatory.

The owl attack threat reason is generated if owl attack on an opponent's dragon fails but the owl code determines that the dragon can be killed with two consecutive moves. The killing moves are stored in dragon[pos].owl_attack_point and dragon[pos].owl_second_attack_point.

Similarly if a friendly dragon is dead but two moves can revive it, an owl defense threat move reason is generated.

The prevent threat reasons are similar but with the colors reversed: if the opponent has an attack threat move then a move which removes the threat gets a prevent threat move reason.

The owl uncertain move reasons are generated when the owl code runs out of nodes. In order to prevent the owl code from running too long, a cap is put on the number of nodes one owl read can generate. If this is exceeded, the reading is cut short and the result is cached as usual, but marked uncertain. In this case an owl uncertain move reason may be generated. For example, if the owl code finds the dragon alive but is unsure, a move to defend may still be generated.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.3.10 Combination Attacks

The function atari_atari tries to find a sequence of ataris culminating in an unexpected change of status of any opponent string, from ALIVE to CRITICAL. Once such a sequence of ataris is found, it tries to shorten it by rejecting irrelevant moves.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4 Valuation of suggested moves

At the end of the move generation process, the function value_move_reasons() tries to assign values to the moves for the purpose of selecting the best move. The single purpose of the move valuation is to try to rank the moves so that the best move gets the highest score. In principle these values could be arbitrary, but in order to make it easier to evaluate how well the valuation performs, not to mention simplify the tuning, we try to assign values which are consistent with the usual methods of counting used by human Go players, as explained for example in The Endgame by Ogawa and Davies.

Moves are valued with respect to four different criteria. These are

All of these are floats and should be measured in terms of actual points.

The territorial value is the total change of expected territory caused by this move. This includes changes in the status of groups if the move is an attack or a defense move.

Beginning with GNU Go 3.0, the influence function plays an important role in estimating territory (see section 13.4 Influence and Territory). It is used to make a guess at each intersection how likely it is that it will become black or white territory. The territorial value sums up the changes in these valuations.

Strategical value is a measure of the effect the move has on the safety of all groups on the board. Typically cutting and connecting moves have their main value here. Also edge extensions, enclosing moves and moves towards the center have high strategical value. The strategical value should be the sum of a fraction of the territorial value of the involved dragons. The fraction is determined by the change in safety of the dragon.

Shape value is a purely local shape analysis. An important role of this measure is to offset mistakes made by the estimation of territorial values. In open positions it's often worth sacrificing a few points of (apparent) immediate profit to make good shape. Shape value is implemented by pattern matching, the Shape patterns.

Secondary value is given for move reasons which by themselves are not sufficient to play the move. One example is to reduce the number of eyes for a dragon that has several or to attack a defenseless worm.

When all these values have been computed, they are summed, possibly weighted (secondary value should definitely have a small weight), into a final move value. This value is used to decide the move.

6.4.1 Territorial Value  How much territory does a move gain
6.4.2 Strategical Value  Strategical gains from a move
6.4.3 Shape Factor  Local shape
6.4.4 Minimum Value  Minimum value
6.4.5 Secondary Value  Other, more indirect, gains from a move
6.4.6 Threats and Followup Value  Valuation of attack and defense threats


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4.1 Territorial Value

The algorithm for computing territorial value is in the function estimate_territorial_value. As the name suggests, it seeks to estimate the change in territory.

It considers all groups that are changed from alive to death or vice-versa due to this move. Also, it makes an assumption whether the move should be considered safe. If so, the influence module is called: The function influence_delta_territory estimates the territorial effect of both the stone played and of the changes of group status'.

The result returned by the influence module is subject to a number of corrections. This is because some move reasons cannot be evaluated by a single call to the influence function, such as moves depending on a ko.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4.2 Strategical Value

Strategical defense or attack reasons are assigned to any move which matches a pattern of type `a' or `d'. These are moves which in some (often intangible) way tend to help strengthen or weaken a dragon. Of course strengthening a dragon which is already alive should not be given much value, but when the move reason is generated it is not necessary to check its status or safety. This is done later, during the valuation phase.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4.3 Shape Factor

In the value field of a pattern (see section 9.3 Pattern Attributes) one may specify a shape value.

This is used to compute the shape factor, which multiplies the score of a move. We take the largest positive contribution to shape and add 1 for each additional positive contribution found. Then we take the largest negative contribution to shape, and add 1 for each additional negative contribution. The resulting number is raised to the power 1.05 to obtain the shape factor.

The rationale behind this complicated scheme is that every shape point is very significant. If two shape contributions with values (say) 5 and 3 are found, the second contribution should be devalued to 1. Otherwise the engine is too difficult to tune since finding multiple contributions to shape can cause significant overvaluing of a move.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4.4 Minimum Value

A pattern may assign a minimum (and sometimes also a maximum) value. For example the Joseki patterns have values which are prescribed in this way, or ones with a value field. One prefers not to use this approach but in practice it is sometimes needed.

In the fuseki, there are often several moves with identical minimum value. GNU Go chooses randomly between such moves, which ensures some indeterminacy of GNU Go's play. Later in the game, GNU Go's genuine valuation of such a move is used as a secondary criterion.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4.5 Secondary Value

Secondary move reasons are weighed very slightly. Such a move can tip the scales if all other factors are equal.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4.6 Threats and Followup Value

Followup value refers to value which may acrue if we get two moves in a row in a local area. It is assigned for moves that threaten to attack or defend a worm or dragon. Also, since GNU Go 3.2 the influence module makes an assessment of the possible purely territorial followup moves. In cases where these two heuristics are not sufficient we add patterns with a followup_value autohelper macro.

Usually, the followup value gives only a small contribution; e.g. if it the followup value is very large, then GNU Go treats the move as sente by doubling its value. However, if the largest move on the board is a ko which we cannot legally take, then such a move becomes attractive as a ko threat and the full followup value is taken into account.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.5 End Game

Endgame moves are generated just like any other move by GNU Go. In fact, the concept of endgame does not exist explicitly, but if the largest move initially found is worth 6 points or less, an extra set of patterns in `endgame.db' is matched and the move valuation is redone.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7. Worms and Dragons

7.1 Worms  
7.2 Amalgamation  How two Worms are amalgamated.
7.3 Connection  Connections.
7.4 Half Eyes and False Eyes  
7.5 Dragons  Union of WORMS.
7.6 Colored Dragon Display  Colored display of DRAGONS.

Before considering its move, GNU Go collects some data in several arrays. Two of these arrays, called worm and dragon, are discussed in this document. Others are discussed in See section 8. Eyes and Half Eyes.

This information is intended to help evaluate the connectedness, eye shape, escape potential and life status of each group.

Later routines called by genmove() will then have access to this information. This document attempts to explain the philosophy and algorithms of this preliminary analysis, which is carried out by the two routines make_worm() and make_dragon() in `dragon.c'.

A worm is a maximal set of stones on the board which are connected along the horizontal and vertical lines, and are of the same color. We often say string instead of worm.

A dragon is a union of strings of the same color which will be treated as a unit. The dragons are generated anew at each move. If two strings are in the dragon, it is the computer's working hypothesis that they will live or die together and are effectively connected.

The purpose of the dragon code is to allow the computer to formulate meaningful statements about life and death. To give one example, consider the following situation:

 
      OOOOO
     OOXXXOO
     OX...XO
     OXXXXXO
      OOOOO

The X's here should be considered a single group with one three-space eye, but they consist of two separate strings. Thus we must amalgamate these two strings into a single dragon. Then the assertion makes sense, that playing at the center will kill or save the dragon, and is a vital point for both players. It would be difficult to formulate this statement if the X's are not perceived as a unit.

The present implementation of the dragon code involves simplifying assumptions which can be refined in later implementations.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.1 Worms

The array struct worm_data worm[MAX_BOARD] collects information about the worms. We will give definitions of the various fields. Each field has constant value at each vertex of the worm. We will define each field.

 
struct worm_data {
  int color;
  int size;
  float effective_size;
  int origin;
  int liberties;
  int liberties2;
  int liberties3;
  int liberties4;
  int lunch;
  int cutstone;
  int cutstone2;
  int genus;
  int inessential;
  int invincible;
  int unconditional_status;
  int attack_points[MAX_TACTICAL_POINTS];
  int attack_codes[MAX_TACTICAL_POINTS];
  int defense_points[MAX_TACTICAL_POINTS];
  int defend_codes[MAX_TACTICAL_POINTS];
  int attack_threat_points[MAX_TACTICAL_POINTS];
  int attack_threat_codes[MAX_TACTICAL_POINTS]; 
  int defense_threat_points[MAX_TACTICAL_POINTS];
  int defense_threat_codes[MAX_TACTICAL_POINTS];
};

We have two distinct notions of cutting stone, which we keep track of in the separate fields worm.cutstone and worm.cutstone2. We use currently use both concepts in parallel.

The function makeworms() will generate data for all worms.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2 Amalgamation

A dragon, we have said, is a group of stones which are treated as a unit. It is a working hypothesis that these stones will live or die together. Thus the program will not expect to disconnect an opponent's strings if they have been amalgamated into a single dragon.

The function make_dragons() will amalgamate worms into dragons by maintaining separate arrays worm[] and dragon[] containing similar data. Each dragon is a union of worms. Just as the data maintained in worm[] is constant on each worm, the data in dragon[] is constant on each dragon.

Amalgamation of worms in GNU Go proceeds as follows. First we amalgamate all boundary components of an eyeshape. Thus in the following example:

 
.OOOO.       The four X strings are amalgamated into a 
OOXXO.       single dragon because they are the boundary
OX..XO       components of a blackbordered cave. The
OX..XO       cave could contain an inessential string
OOXXO.       with no effect on this amalgamation.
XXX...       

The code for this type of amalgamation is in the routine dragon_eye(), discussed further in EYES.

Next, we amalgamate strings which seem uncuttable. We amalgamate dragons which either share two or more common liberties, or share one liberty into the which the opponent cannot play without being captured. (ignores ko rule).

 
   X.    X.X     XXXX.XXX         X.O
   .X    X.X     X......X         X.X
                 XXXXXX.X         OXX

A database of connection patterns may be found in `patterns/conn.db'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.3 Connection

The fields black_eye.cut and white_eye.cut are set where the opponent can cut, and this is done by the B (break) class patterns in `conn.db'. There are two important uses for this field, which can be accessed by the autohelper functions xcut() and ocut(). The first use is to stop amalgamation in positions like

 
..X..
OO*OO
X.O.X
..O..

where X can play at * to cut off either branch. What happens here is that first connection pattern CB1 finds the double cut and marks * as a cutting point. Later the C (connection) class patterns in conn.db are searched to find secure connections over which to amalgamate dragons. Normally a diagonal connection would be deemed secure and amalgamated by connection pattern CC101, but there is a constraint requiring that neither of the empty intersections is a cutting point.

A weakness with this scheme is that X can only cut one connection, not both, so we should be allowed to amalgamate over one of the connections. This is performed by connection pattern CC401, which with the help of amalgamate_most_valuable_helper() decides which connection to prefer.

The other use is to simplify making alternative connection patterns to the solid connection. Positions where the diag_miai helper thinks a connection is necessary are marked as cutting points by connection pattern 12. Thus we can write a connection pattern like CC6:

 
?xxx?     straight extension to connect
XOO*?
O...?

:8,C,NULL

?xxx?
XOOb?
Oa..?

;xcut(a) && odefend_against(b,a)

where we verify that a move at * would stop the enemy from safely playing at the cutting point, thus defending against the cut.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.4 Half Eyes and False Eyes

A half eye is a place where, if the defender plays first, an eye will materialize, but where if the attacker plays first, no eye will materialize. A false eye is a vertex which is surrounded by a dragon yet is not an eye. Here is a half eye:

 
XXXXX
OO..X
O.O.X
OOXXX

Here is a false eye:

 
XXXXX
XOO.X
O.O.X
OOXXX

The "topological" algorithm for determining half and false eyes is described elsewhere (see section 8.8 Topology of Half Eyes and False Eyes).

The half eye data is collected in the dragon array. Before this is done, however, an auxiliary array called half_eye_data is filled with information. The field type is 0, or else HALF_EYE or FALSE_EYE depending on which type is found; the fields attack_point[] point to up to 4 points to attack the half eye, and similarly defense_point[] gives points to defend the half eye.

 
struct half_eye_data half_eye[MAX_BOARD];

struct half_eye_data {
  float value;          /* Topological eye value */
  int type;             /* HALF_EYE or FALSE_EYE */
  int num_attacks;      /* Number of attacking points */
  int attack_point[4];  /* The moves to attack a topological halfeye */
  int num_defends;      /* Number of defending points */
  int defense_point[4]; /* The moves to defend a topological halfeye */
};

The array struct half_eye_data half_eye[MAX_BOARD] contains information about half and false eyes. If the type is HALF_EYE then up to four moves are recorded which can either attack or defend the eye. In rare cases the attack points could be different from the defense points.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.5 Dragons

The array struct dragon_data dragon[MAX_BOARD] collects information about the dragons. We will give definitions of the various fields. Each field has constant value at each vertex of the dragon. (Fields will be discussed below.)

 
struct dragon_data {
  int color;    /* its color                               */
  int id;       /* the index into the dragon2 array        */
  int origin;   /* the origin of the dragon. Two vertices  */
                /* are in the same dragon iff they have    */
                /* same origin.                            */
  int size;     /* size of the dragon                      */
  float effective_size; /* stones and surrounding spaces   */
  int crude_status;     /* (ALIVE, DEAD, UNKNOWN, CRITICAL)*/
  int status;           /* best trusted status             */
};

extern struct dragon_data dragon[BOARDMAX];

Other fields attached to the dragon are contained in the dragon_data2 struct array. (Fields will be discussed below.)

 
struct dragon_data2 {
  int origin;
  int adjacent[MAX_NEIGHBOR_DRAGONS];
  int neighbors;
  int hostile_neighbors;
  int moyo_size;
  float moyo_territorial_value;
  int safety;
  float weakness;
  float weakness_pre_owl;
  int escape_route;
  struct eyevalue genus;
  int heye;
  int lunch;
  int surround_status;
  int surround_size;
  int semeais;
  int semeai_margin_of_safety;
  int semeai_defense_point;
  int semeai_defense_certain;  
  int semeai_attack_point;
  int semeai_attack_certain;
  int owl_threat_status;
  int owl_status;
  int owl_attack_point;
  int owl_attack_code;
  int owl_attack_certain;
  int owl_second_attack_point;
  int owl_defense_point;
  int owl_defense_code;
  int owl_defense_certain;
  int owl_second_defense_point;
  int owl_attack_kworm;
  int owl_defense_kworm;
};

extern struct dragon_data2 *dragon2;

The difference between the two arrays is that the dragon array is indexed by the board, and there is a copy of the dragon data at every stone in the dragon, while there is only one copy of the dragon2 data. The dragons are numbered, and the id field of the dragon is a key into the dragon2 array. Two macros DRAGON and DRAGON2 are provided for gaining access to the two arrays.

 
#define DRAGON2(pos) dragon2[dragon[pos].id]
#define DRAGON(d) dragon[dragon2[d].origin]

Thus if you know the position pos of a stone in the dragon you can access the dragon array directly, for example accessing the origin with dragon[pos].origin. However if you need a field from the dragon2 array, you can access it using the DRAGON2 macro, for example you can access its neighor dragons by

 
for (k = 0; k < DRAGON2(pos).neighbors; k++) {
  int d = DRAGON2(pos).adjacent[k];
  int apos = dragon2[d].origin;
  do_something(apos);
}

Similarly if you know the dragon number (which is dragon[pos].id) then you can access the dragon2 array directly, or you can access the dragon array using the DRAGON macro.

Here are the definitions of each field in the dragon arrray.

Here are definitions of the fields in the dragon2 array.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.6 Colored Dragon Display

You can get a colored ASCII display of the board in which each dragon is assigned a different letter; and the different values of dragon.status values (ALIVE, DEAD, UNKNOWN, CRITICAL) have different colors. This is very handy for debugging. A second diagram shows the values of owl.status. If this is UNCHECKED the dragon is displayed in White.

Save a game in sgf format using CGoban, or using the `-o' option with GNU Go itself.

Open an xterm or rxvt window. You may also use the Linux console. Using the console, you may need to use "SHIFT-PAGE UP" to see the first diagram. Xterm will only work if it is compiled with color support--if you do not see the colors try rxvt. Make the background color black and the foreground color white.

Execute:

gnugo -l [filename] -L [movenum] -T to get the colored display.

The color scheme: Green = ALIVE; Yellow = UNKNOWN; Cyan = DEAD and Red = CRITICAL. Worms which have been amalgamated into the same dragon are labelled with the same letter.

Other useful colored displays may be obtained by using instead:

The colored displays are documented elsewhere (see section 5.8 Colored Display).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8. Eyes and Half Eyes

The purpose of this Chapter is to describe the algorithm used in GNU Go to determine eyes.

8.1 Local games  
8.2 Eye spaces  Eye space
8.3 The eyespace as local game  Eye space as local game
8.4 An example  
8.5 Graphs  Underlying graphs
8.6 Eye shape analysis  Pattern matching
8.7 Eye Local Game Values  Pattern matching
8.8 Topology of Half Eyes and False Eyes  False eyes and half eyes
8.9 Eye Topology with Ko  False eyes and half eyes with ko
8.10 False Margins  False margins
8.11 Functions in `optics.c'  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.1 Local games

The fundamental paradigm of combinatorial game theory is that games can be added and in fact form a group. If `G' and `H' are games, then `G+H' is a game in which each player on his turn has the option of playing in either move. We say that the game `G+H' is the sum of the local games `G' and `H'.

Each connected eyespace of a dragon affords a local game which yields a local game tree. The score of this local game is the number of eyes it yields. Usually if the players take turns and make optimal moves, the end scores will differ by 0 or 1. In this case, the local game may be represented by a single number, which is an integer or half integer. Thus if `n(O)' is the score if `O' moves first, both players alternate (no passes) and make alternate moves, and similarly `n(X)', the game can be represented by `{n(O)|n(X)}'. Thus {1|1} is an eye, {2|1} is an eye plus a half eye, etc.

The exceptional game {2|0} can occur, though rarely. We call an eyespace yielding this local game a CHIMERA. The dragon is alive if any of the local games ends up with a score of 2 or more, so {2|1} is not different from {3|1}. Thus {3|1} is NOT a chimera.

Here is an example of a chimera:

 
XXXXX
XOOOX
XO.OOX
XX..OX
XXOOXX
XXXXX


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.2 Eye spaces

In order that each eyespace be assignable to a dragon, it is necessary that all the dragons surrounding it be amalgamated (see section 7.2 Amalgamation). This is the function of dragon_eye().

An EYE SPACE for a black dragon is a collection of vertices adjacent to a dragon which may not yet be completely closed off, but which can potentially become eyespace. If an open eye space is sufficiently large, it will yield two eyes. Vertices at the edge of the eye space (adjacent to empty vertices outside the eye space) are called MARGINAL.

Here is an example from a game:

 
 |. X . X X . . X O X O 
 |X . . . . . X X O O O
 |O X X X X . . X O O O
 |O O O O X . O X O O O
 |. . . . O O O O X X O
 |X O . X X X . . X O O
 |X O O O O O O O X X O
 |. X X O . O X O . . X
 |X . . X . X X X X X X
 |O X X O X . X O O X O

Here the `O' dragon which is surrounded in the center has open eye space. In the middle of this open eye space are three dead `X' stones. This space is large enough that O cannot be killed. We can abstract the properties of this eye shape as follows. Marking certain vertices as follows:

 
 |- X - X X - - X O X O 
 |X - - - - - X X O O O
 |O X X X X - - X O O O
 |O O O O X - O X O O O
 |! . . . O O O O X X O
 |X O . X X X . ! X O O
 |X O O O O O O O X X O
 |- X X O - O X O - - X
 |X - - X - X X X X X X
 |O X X O X - X O O X O

the shape in question has the form:

 
!...
  .XXX.!

The marginal vertices are marked with an exclamation point (`!'). The captured `X' stones inside the eyespace are naturally marked `X'.

The precise algorithm by which the eye spaces are determined is somewhat complex. Documentation of this algorithm is in the comments in the source to the function make_domains() in `optics.c'.

The eyespaces can be conveniently displayed using a colored ascii diagram by running gnugo -E.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.3 The eyespace as local game

In the abstraction, an eyespace consists of a set of vertices labelled:

 
!  .  X

Tables of many eyespaces are found in the database `patterns/eyes.db'. Each of these may be thought of as a local game. The result of this game is listed after the eyespace in the form :max,min, where max is the number of eyes the pattern yields if `O' moves first, while min is the number of eyes the pattern yields if `X' moves first. The player who owns the eye space is denoted `O' throughout this discussion. Since three eyes are no better than two, there is no attempt to decide whether the space yields two eyes or three, so max never exceeds 2. Patterns with min>1 are omitted from the table.

For example, we have:

 
Pattern 548

 x
xX.!

:0111

Here notation is as above, except that `x' means `X' or EMPTY. The result of the pattern is not different if `X' has stones at these vertices or not.

We may abstract the local game as follows. The two players `O' and `X' take turns moving, or either may pass.

RULE 1: `O' for his move may remove any vertex marked `!' or marked `.'.

RULE 2: `X' for his move may replace a `.' by an `X'.

RULE 3: `X' may remove a `!'. In this case, each `.' adjacent to the `!' which is removed becomes a `!' . If an `X' adjoins the `!' which is removed, then that `X' and any which are connected to it are also removed. Any `.' which are adjacent to the removed `X''s then become `.'.

Thus if `O' moves first he can transform the eyeshape in the above example to:

 
 ...            or      !...
  .XXX.!                  .XXX.

However if `X' moves he may remove the `!' and the `.'s adjacent to the `!' become `!' themselves. Thus if `X' moves first he may transform the eyeshape to:

 
 !..           or    !..
  .XXX.!              .XXX!

NOTE: A nuance which is that after the `X:1', `O:2' exchange below, `O' is threatening to capture three X stones, hence has a half eye to the left of 2. This is subtle, and there are other such subtleties which our abstraction will not capture. Some of these at least can be dealt with by a refinements of the scheme, but we will content ourselves for the time being with a simplified model.

 
 |- X - X X - - X O X O 
 |X - - - - - X X O O O
 |O X X X X - - X O O O
 |O O O O X - O X O O O
 |1 2 . . O O O O X X O
 |X O . X X X . 3 X O O
 |X O O O O O O O X X O
 |- X X O - O X O - - X
 |X - - X - X X X X X X
 |O X X O X - X O O X O

We will not attempt to characterize the terminal states of the local game (some of which could be seki) or the scoring.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.4 An example

Here is a local game which yields exactly one eye, no matter who moves first:

 
!
...
...!

Here are some variations, assuming `O' moves first.

 
!        (start position)
...
...!


...      (after `O''s move)
...!


... 
..!


... 
..


.X.       (nakade)
..

Here is another variation:

 
!         (start)
...
...!


!         (after `O''s move)
. .
...!


!         (after `X''s move)
. .
..X!


. .
..X!


. !
.!


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.5 Graphs

It is a useful observation that the local game associated with an eyespace depends only on the underlying graph, which as a set consists of the set of vertices, in which two elements are connected by an edge if and only if they are adjacent on the Go board. For example the two eye shapes:

 
..
 ..

and

....

though distinct in shape have isomorphic graphs, and consequently they are isomorphic as local games. This reduces the number of eyeshapes in the database `patterns/eyes.db'.

A further simplification is obtained through our treatment of half eyes and false eyes. Such patterns are identified by the topological analysis (see section 8.8 Topology of Half Eyes and False Eyes).

A half eye is isomorphic to the pattern (!.) . To see this, consider the following two eye shapes:

 
XOOOOOO
X.....O
XOOOOOO

and:

XXOOOOO
XOa...O
XbOOOOO
XXXXXXX

These are equivalent eyeshapes, with isomorphic local games {2|1}. The first has shape:

 
!....

The second eyeshape has a half eye at `a' which is taken when `O' or `X' plays at `b'. This is found by the topological criterion (see section 8.8 Topology of Half Eyes and False Eyes).

The graph of the eye_shape, ostensibly `....' is modified by replacing the left `.' by `!.' during graph matching.

A false eye is isomorphic to the pattern (!) . To see this, consider the following eye shape:

 
XXXOOOOOO
X.Oa....O
XXXOOOOOO

This is equivalent to the two previous eyeshapes, with an isomorphic local game {2|1}.

This eyeshape has a false eye at `a'. This is also found by the topological criterion.

The graph of the eye_shape, ostensibly `.....' is modified by replacing the left `.' by `!'. This is made directly in the eye data, not only during graph matching.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.6 Eye shape analysis

The patterns in `patterns/eyes.db' are compiled into graphs represented essentially by arrays in `patterns/eyes.c'.

Each actual eye space as it occurs on the board is also compiled into a graph. Half eyes are handled as follows. Referring to the example

 
XXOOOOO
XOa...O
XbOOOOO
XXXXXX

repeated from the preceding discussion, the vertex at `b' is added to the eyespace as a marginal vertex. The adjacency condition in the graph is a macro (in `optics.c'): two vertices are adjacent if they are physically adjacent, or if one is a half eye and the other is its key point.

In recognize_eyes(), each such graph arising from an actual eyespace is matched against the graphs in `eyes.c'. If a match is found, the result of the local game is known. If a graph cannot be matched, its local game is assumed to be {2|2}.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.7 Eye Local Game Values

The game values in `eyes.db' are given in a simplified scheme which is flexible enough to represent most possibilities in a useful way.

The colon line below the pattern gives the eye value of the matched eye shape. This consists of four digits, each of which is the number of eyes obtained during the following conditions:

  1. The attacker moves first and is allowed yet another move because the defender plays tenuki.
  2. The attacker moves first and the defender responds locally.
  3. The defender moves first and the attacker responds locally.
  4. The defender moves first and is allowed yet another move because the attacker plays tenuki.

The first case does not necessarily mean that the attacker is allowed two consecutive moves. This is explained with an example later.

Also, since two eyes suffice to live, all higher numbers also count as two.

The following 15 cases are of interest:

The 3/4, 5/4, and 1* eye values are the same as in Howard Landman's paper Eyespace Values in Go. Attack and defense points are only marked in the patterns when they have definite effects on the eye value, i.e. pure threats are not marked.

Examples of all different cases can be found among the patterns in this file. Some of them might be slightly counterintuitive, so we explain one important case here. Consider

 
Pattern 6141

 X
XX.@x

:1122

which e.g. matches in this position:

 
.OOOXXX
OOXOXOO
OXXba.O
OOOOOOO

Now it may look like `X' could take away both eyes by playing `a' followed by `b', giving 0122 as eye value. This is where the subtlety of the definition of the first digit in the eye value comes into play. It does not say that the attacker is allowed two consecutive moves but only that he is allowed to play "another move". The crucial property of this shape is that when `X' plays at a to destroy (at least) one eye, `O' can answer at `b', giving:

 
.OOOXXX
OO.OXOO
O.cOX.O
OOOOOOO

Now `X' has to continue at `c' in order to keep `O' at one eye. After this `O' plays tenuki and `X' cannot destroy the remaining eye by another move. Thus the eye value is indeed 1122.

As a final note, some of the eye values indicating a threat depend on suicide to be allowed, e.g.

 
Pattern 301
 
X.X

:1222

We always assume suicide to be allowed in this database. It is easy enough to sort out such moves at a higher level when suicide is disallowed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.8 Topology of Half Eyes and False Eyes

A HALF EYE is a pattern where an eye may or may not materialize, depending on who moves first. Here is a half eye for O:

 
   OOXX
   O.O.
   OO.X

A FALSE EYE is an eye vertex which cannot become a proper eye. Here are two examples of false eyes for O:

 
   OOX         OOX
   O.O         O.OO
   XOO         OOX

We describe now the topological algorithm used to find half eyes and false eyes. In this section we ignore the possibility of ko.

False eyes and half eyes can locally be characterized by the status of the diagonal intersections from an eye space. For each diagonal intersection, which is not within the eye space, there are three distinct possibilities:

We give the first possibility a value of two, the second a value of one, and the last a value of zero. Summing the values for the diagonal intersections, we have the following criteria:

If the eye space is on the edge, the numbers above should be decreased by 2. An alternative approach is to award diagonal points which are outside the board a value of 1. To obtain an exact equivalence we must however give value 0 to the points diagonally off the corners, i.e. the points with both coordinates out of bounds.

The algorithm to find all topologically false eyes and half eyes is:

For all eye space points with at most one neighbor in the eye space, evaluate the status of the diagonal intersections according to the criteria above and classify the point from the sum of the values.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.9 Eye Topology with Ko

This section extends the topological eye analysis to handle ko. We distinguish between a ko in favor of `O' and one in favor of `X':

 
.?O?   good for O
OO.O
O.O?
XOX.
.X..

.?O?   good for X
OO.O
OXO?
X.X.
.X..

Preliminarily we give the former the symbolic diagonal value a and the latter the diagonal value b. We should clearly have 0 < a < 1 < b < 2. Letting e be the topological eye value (still the sum of the four diagonal values), we want to have the following properties:

 
e <= 2     - proper eye
2 < e < 3  - worse than proper eye, better than half eye
e = 3      - half eye
3 < e < 4  - worse than half eye, better than false eye
e >= 4     - false eye

In order to determine the appropriate values of a and b we analyze the typical cases of ko contingent topological eyes:

 
      .X..      (slightly) better than proper eye
(a)   ..OO          e < 2
      OO.O
      O.OO      e = 1 + a
      XOX.
      .X..


      .X..      better than half eye, worse than proper eye
(a')  ..OO      2 < e < 3
      OO.O
      OXOO      e = 1 + b
      X.X.
      .X..

      
      .X..      better than half eye, worse than proper eye
(b)   .XOO      2 < e < 3
      OO.O
      O.OO      e = 2 + a
      XOX.
      .X..

      
      .X..      better than false eye, worse than half eye
(b')  .XOO      3 < e < 4
      OO.O
      OXOO      e = 2 + b
      X.X.
      .X..

      
      .X..
      XOX.      (slightly) better than proper eye
(c)   O.OO          e < 2
      OO.O
      O.OO      e = 2a
      XOX.
      .X..

      
      .X..
      XOX.      proper eye, some aji
(c')  O.OO      e ~ 2
      OO.O
      OXOO      e = a + b
      X.X.
      .X..

      
      .X..
      X.X.      better than half eye, worse than proper eye
(c'') OXOO      2 < e < 3
      OO.O
      OXOO      e = 2b
      X.X.
      .X..

      
      .X...
      XOX..     better than half eye, worse than proper eye
(d)   O.O.X     2 < e < 3
      OO.O.
      O.OO.     e = 1 + 2a
      XOX..
      .X...

      
      .X...
      XOX..     half eye, some aji
(d')  O.O.X     e ~ 3
      OO.O.
      OXOO.     e = 1 + a + b
      X.X..
      .X...

      
      .X...
      X.X..     better than false eye, worse than half eye
(d'') OXO.X     3 < e < 4
      OO.O.
      OXOO.     e = 1 + 2b
      X.X..
      .X...

      
      .X...
      XOX..     better than false eye, worse than half eye
(e)   O.OXX     3 < e < 4
      OO.O.
      O.OO.     e =  2 + 2a
      XOX..
      .X...

      
      .X...
      XOX..     false eye, some aji
(e')  O.OXX     e ~ 4
      OO.O.
      OXOO.     e = 2 + a + b
      X.X..
      .X...

      
      .X...
      X.X..     (slightly) worse than false eye
(e'') OXOXX     4 < e
      OO.O.
      OXOO.     e = 2 + 2b
      X.X..
      .X...

It may seem obvious that we should use

 
(i)   a=1/2, b=3/2
but this turns out to have some drawbacks. These can be solved by using either of
 
(ii)  a=2/3, b=4/3
(iii) a=3/4, b=5/4
(iv)  a=4/5, b=6/5

Summarizing the analysis above we have the following table for the four different choices of a and b.

 
case    symbolic        a=1/2   a=2/3   a=3/4   a=4/5   desired
        value           b=3/2   b=4/3   b=5/4   b=6/5   interval
(a)     1+a             1.5     1.67    1.75    1.8         e < 2
(a')    1+b             2.5     2.33    2.25    2.2     2 < e < 3
(b)     2+a             2.5     2.67    2.75    2.8     2 < e < 3
(b')    2+b             3.5     3.33    3.25    3.2     3 < e < 4
(c)     2a              1       1.33    1.5     1.6         e < 2
(c')    a+b             2       2       2       2           e ~ 2
(c'')   2b              3       2.67    2.5     2.4     2 < e < 3
(d)     1+2a            2       2.33    2.5     2.6     2 < e < 3
(d')    1+a+b           3       3       3       3           e ~ 3
(d'')   1+2b            4       3.67    3.5     3.4     3 < e < 4
(e)     2+2a            3       3.33    3.5     3.6     3 < e < 4
(e')    2+a+b           4       4       4       4           e ~ 4
(e'')   2+2b            5       4.67    4.5     4.4     4 < e

We can notice that (i) fails for the cases (c"), (d), (d"), and (e). The other three choices get all values in the correct intervals. The main distinction between them is the relative ordering of (c") and (d) (or analogously (d") and (e)). If we do a more detailed analysis of these we can see that in both cases `O' can secure the eye unconditionally if he moves first while `X' can falsify it with ko if he moves first. The difference is that in (c"), `X' has to make the first ko threat, while in (d), O has to make the first ko threat. Thus (c") is better for O and ought to have a smaller topological eye value than (d). This gives an indication that (iv) is the better choice.

We can notice that any value of a, b satisfying a+b=2 and 3/4<a<1 would have the same qualities as choice (iv) according to the analysis above. One interesting choice is a=7/8, b=9/8 since these allow exact computations with floating point values having a binary mantissa. The latter property is shared by a=3/4 and a=1/2.

When there are three kos around the same eyespace, things become more complex. This case is, however, rare enough that we ignore it.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.10 False Margins

The following situation is rare but special enough to warrant separate attention:

 
   OOOOXX
   OXaX..
   ------

Here `a' may be characterized by the fact that it is adjacent to O's eyespace, and it is also adjacent to an X group which cannot be attacked, but that an X move at 'a' results in a string with only one liberty. We call this a false margin.

For the purpose of the eye code, O's eyespace should be parsed as (X), not (X!).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.11 Functions in `optics.c'

The public function make_domains() calls the function make_primary_domains() which is static in `optics.c'. It's purpose is to compute the domains of influence of each color, used in determining eye shapes. Note: the term influence as used here is distinct from the influence in influence.c.

For this algorithm the strings which are not lively are invisible. Ignoring these, the algorithm assigns friendly influence to

  1. every vertex which is occupied by a (lively) friendly stone,
  2. every empty vertex adjoining a (lively) friendly stone,
  3. every empty vertex for which two adjoining vertices (not on the first line) in the (usually 8) surrounding ones have friendly influence, with two CAVEATS explained below.

Thus in the following diagram, `e' would be assigned friendly influence if `a' and `b' have friendly influence, or `a' and `d'. It is not sufficent for `b' and `d' to have friendly influence, because they are not adjoining.

 
       uabc
        def
        ghi

The constraint that the two adjoining vertices not lie on the first line prevents influence from leaking under a stone on the third line.

The first CAVEAT alluded to above is that even if `a' and `b' have friendly influence, this does not cause `e' to have friendly influence if there is a lively opponent stone at `d'. This constraint prevents influence from leaking past knight's move extensions.

The second CAVEAT is that even if `a' and `b' have friendly influence this does not cause `e' to have influence if there are lively opponent stones at `u' and at `c'. This prevents influence from leaking past nikken tobis (two space jumps).

The corner vertices are handled slightly different.

 
   +---
   |ab
   |cd

We get friendly influence at `a' if we have friendly influence at `b' or `c' and no lively unfriendly stone at `b', `c' or `d'.

Here are the public functions in `optics.c', except some simple access functions used by autohelpers. The statically declared functions are documented in the source code.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9. The Pattern Code

9.1 Overview  Overview of the pattern database.
9.2 Pattern Attributes  The classification field
9.3 Pattern Attributes  The value field
9.4 Helper Functions  
9.5 Autohelpers and Constraints  Automatic generation of helper functions.
9.6 Autohelper Actions  
9.7 Autohelper Functions  
9.8 Attack and Defense Database  The Attack and defense moves database.
9.9 The Connections Database  The connection database.
9.10 Connections Functions  Functions in `connections.c'
9.11 Tuning the Pattern databases  Tuning the pattern database.
9.12 Implementation  
9.13 Symmetry and transformations  
9.14 Implementation Details  Details of implementation.
9.15 The "Grid" Optimization  The "grid" optimization.
9.16 The Joseki Compiler  The joseki compiler.
9.17 Ladders in Joseki  Example: ladders in joseki.
9.18 Corner Matcher  A special matcher for joseki patterns.
9.19 Emacs Mode for Editing Patterns  Emacs major mode for pattern files.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.1 Overview

Several pattern databases are in the patterns directory. This chapter primarily discusses the patterns in `patterns.db', `patterns2.db', and the pattern files `hoshi.db' etc. which are compiled from the SGF files `hoshi.sgf' (see section 9.16 The Joseki Compiler). There is no essential difference between these files, except that the ones in `patterns.db' and `patterns2.db' are hand written. They are concatenated before being compiled by mkpat into `patterns.c'. The purpose of the separate file `patterns2.db' is that it is handy to move patterns into a new directory in the course of organizing them. The patterns in `patterns.db' are more disorganized, and are slowly being moved to `patterns2.db'.

During the execution of genmove(), the patterns are matched in `shapes.c' in order to find move reasons.

The same basic pattern format is used by `attack.db', `defense.db', `conn.db', `apats.db' and `dpats.db'. However these patterns are used for different purposes. These databases are discussed in other parts of this documentation. The patterns in `eyes.db' are entirely different and are documented elsewhere (see section 8. Eyes and Half Eyes).

The patterns described in the databases are ascii representations, of the form:

Pattern EB112

 
  ?X?.?       jump under
  O.*oo
  O....
  o....
  -----
  
  :8,ed,NULL

Here `O' marks a friendly stone, `X' marks an enemy stone, `.' marks an empty vertex, `*' marks O's next move, `o' marks a square either containing `O' or empty but not `X'. (The symbol `x', which does not appear in this pattern, means `X' or `.'.) Finally `?' Indicates a location where we don't care what is there, except that it cannot be off the edge of the board.

The line of `-''s along the bottom in this example is the edge of the board itself--this is an edge pattern. Corners can also be indicated. Elements are not generated for `?' markers, but they are not completely ignored - see below. The line beginning `:' describes various attributes of the pattern, such as its symmetry and its class. Optionally, a function called a "helper" can be provided to assist the matcher in deciding whether to accept move. Most patterns do not require a helper, and this field is filled with NULL.

The matcher in `matchpat.c' searches the board for places where this layout appears on the board, and the callback function shapes_callback() in `shapes.c' registers the appropriate move reasons.

After the pattern, there is some supplementary information in the format:

 
  :trfno, classification, [values], helper_function

Here trfno represents the number of transformations of the pattern to consider, usually `8' (no symmetry, for historical reasons), or one of `|', `\', `/', `-', `+', `X', where the line represents the axis of symmetry. (E.g. `|' means symmetrical about a vertical axis.)

The above pattern could equally well be written on the left edge:

 
  |oOO?
  |...X
  |..*?
  |..o.
  |..o?

  :8,ed,NULL

The program mkpat is capable of parsing patterns written this way, or for that matter, on the top or right edges, or in any of the four corners. As a matter of convention all the edge patterns in `patterns.db' are written on the bottom edge or in the lower left corners. In the `patterns/' directory there is a program called transpat which can rotate or otherwise transpose patterns. This program is not built by default--if you think you need it, make transpat in the `patterns/' directory and consult the usage remarks at the beginning of `patterns/transpat.c'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.2 Pattern Attributes

The attribute field in the `:' line of a pattern consists of a sequence of zero or more of the following characters, each with a different meaning. The attributes may be roughly classified as constraints, which determine whether or not the pattern is matched, and actions, which describe what is to be done when the pattern is matched, typically to add a move reason.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.2.1 Constraint Pattern Attributes


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.2.2 Action Attributes

A commonly used class is OX (which rejects pattern if either side has dead stones). The string `-' may be used as a placeholder. (In fact any characters other than the above and `,' are ignored.)

The types `o' and `O' could conceivably appear in a class, meaning it applies only to UNKNOWN. `X' and `x' could similarly be used together. All classes can be combined arbitrarily.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.3 Pattern Attributes

The second and following fields in the `:' line of a pattern are optional and of the form value1(x),value2(y),.... The available set of values are as follows.

The meaning of these values is documented in See section 6. Move generation.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.4 Helper Functions

Helper functions can be provided to assist the matcher in deciding whether to accept a pattern, register move reasons, and setting various move values. The helper is supplied with the compiled pattern entry in the table, and the (absolute) position on the board of the `*' point.

One difficulty is that the helper must be able to cope with all the possible transformations of the pattern. To help with this, the OFFSET macro is used to transform relative pattern coordinates to absolute board locations.

The actual helper functions are in `helpers.c'. They are declared in `patterns.h'.

As an example to show how to write a helper function, we consider a hypothetical helper called wedge_helper. Such a helper used to exist, but has been replaced by a constraint. Due to its simplicity it's still a good example. The helper begins with a comment:

 
/*

?O.           ?Ob
.X*           aX*
?O.           ?Oc

:8,C,wedge_helper
*/

The image on the left is the actual pattern. On the right we've taken this image and added letters to label apos, bpos, and cpos. The position of *, the point where GNU Go will move if the pattern is adopted, is passed through the parameter move.

 
int 
wedge_helper(ARGS)
{
  int apos, bpos, cpos;
  int other = OTHER_COLOR(color);
  int success = 0;
  
  apos = OFFSET(0, -2);
  bpos = OFFSET(-1, 0);
  cpos = OFFSET(1, 0);

  if (TRYMOVE(move, color)) {
    if (TRYMOVE(apos, other)) {
      if (board[apos] == EMPTY || attack(apos, NULL))
        success = 1;
      else if (TRYMOVE(bpos, color)) {
        if (!safe_move(cpos, other))
          success = 1;
        popgo();
      }
      popgo();
    }
    popgo();
  }
  
  return success;
}

The OFFSET lines tell GNU Go the positions of the three stones at `a', `b', and `c'. To decide whether the pattern guarantees a connection, we do some reading. First we use the TRYMOVE macro to place an `O' at `move' and let `X' draw back to `a'. Then we ask whether `O' can capture these stones by calling attack(). The test if there is a stone at `a' before calling attack() is in this position not really necessary but it's good practice to do so, because if the attacked stone should happen to already have been captured while placing stones, GNU Go would crash with an assertion failure.

If this attack fails we let `O' connect at `b' and use the safe_move() function to examine whether a cut by `X' at `c' could be immediately captured. Before we return the result we need to remove the stones we placed from the reading stack. This is done with the function popgo().


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.5 Autohelpers and Constraints

In addition to the hand-written helper functions in `helpers.c', GNU Go can automatically generate helper functions from a diagram with labels and an expression describing a constraint. The constraint diagram, specifying the labels, is placed below the `:' line and the constraint expression is placed below the diagram on line starting with a `;'. Constraints can only be used to accept or reject a pattern. If the constraint evaluates to zero (false) the pattern is rejected, otherwise it's accepted (still conditioned on passing all other tests of course). To give a simple example we consider a connection pattern.

 
Pattern Conn311

O*.
?XO

:8,C,NULL

O*a
?BO

;oplay_attack_either(*,a,a,B)

Here we have given the label `a' to the empty spot to the right of the considered move and the label `B' to the `X' stone in the pattern. In addition to these, `*' can also be used as a label. A label may be any lowercase or uppercase ascii letter except OoXxt. By convention we use uppercase letters for `X' stones and lowercase for `O' stones and empty intersections. When labeling a stone that's part of a larger string in the pattern, all stones of the string should be marked with the label. (These conventions are not enforced by the pattern compiler, but to make the database consistent and easy to read they should be followed.)

The labels can now be used in the constraint expression. In this example we have a reading constraint which should be interpreted as "Play an `O' stone at `*' followed by an `X' stone at `a'. Accept the pattern if `O' now can capture either at `a' or at `B' (or both strings)."

The functions that are available for use in the constraints are listed in the section `Autohelpers Functions' below. Technically the constraint expression is transformed by mkpat into an automatically generated helper function in `patterns.c'. The functions in the constraint are replaced by C expressions, often functions calls. In principle any valid C code can be used in the constraints, but there is in practice no reason to use anything more than boolean and arithmetic operators in addition to the autohelper functions. Constraints can span multiple lines, which are then concatenated.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.6 Autohelper Actions

As a complement to the constraints, which only can accept or reject a pattern, one can also specify an action to perform when the pattern has passed all tests and finally has been accepted.

Example:

 
Pattern EJ4

...*.     continuation
.OOX.
..XOX
.....
-----

:8,Ed,NULL

...*.     never play a here
.OOX.
.aXOX
.....
-----

>antisuji(a)

The line starting with `>' is the action line. In this case it tells the move generation that the move at a should not be considered, whatever move reasons are found by other patterns. The action line uses the labels from the constraint diagram. Both constraint and action can be used in the same pattern. If the action only needs to refer to `*', no constraint diagram is required. Like constraints, actions can span multiple lines.

Here is a partial list of the autohelper macros which are typically called from action lines. This list is not complete. If you cannot find an autohelper macro in an action line in this list, consult `mkpat.c' to find out what function in the engine is actually called. If no macro exists which does what you want, you can add macros by editing the list in `mkpat.c'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.7 Autohelper Functions

The autohelper functions are translated into C code by the program in `mkpat.c'. To see exactly how the functions are implemented, consult the autohelper function definitions in that file. Autohelper functions can be used in both constraint and action lines.

 
lib(x)
lib2(x)
lib3(x)
lib4(x)

Number of first, second, third, and fourth order liberties of a worm respectively. See section 7. Worms and Dragons, the documentation on worms for definitions.

 
xlib(x)
olib(x)

The number of liberties that an enemy or own stone, respectively, would obtain if played at the empty intersection `x'.

 
xcut(x)
ocut(x)

Calls cut_possible (see section 18.1 General Utilities) to determine whether `X' or `O' can cut at the empty intersection `x'.

 
ko(x)

True if `x' is either a stone or an empty point involved in a ko position.

 
status(x)

The matcher status of a dragon. status(x) returns an integer that can have the values ALIVE, UNKNOWN, CRITICAL, or DEAD (see section 7. Worms and Dragons).

 
alive(x)
unknown(x)
critical(x)
dead(x)

Each function true if the dragon has the corresponding matcher status and false otherwise (see section 7. Worms and Dragons).

 
status(x)

Returns the status of the dragon at `x' (see section 7. Worms and Dragons).

 
genus(x)

The number of eyes of a dragon. It is only meaningful to compare this value against 0, 1, or 2.

 
xarea(x)
oarea(x)
xmoyo(x)
omoyo(x)
xterri(x)
oterri(x)

These functions call whose_territory(), whose_moyo() and whose_area() (see section 13.2 Territory, Moyo and Area). For example xarea(x) evaluates to true if `x' is either a living enemy stone or an empty point within the opponent's "area". The function oarea(x) is analogous but with respect to our stones and area. The main difference between area, moyo, and terri is that area is a very far reaching kind of influence, moyo gives a more realistic estimate of what may turn in to territory, and terri gives the points that already are believed to be secure territory.

 
weak(x)

True for a dragon that is perceived as weak.

 
attack(x)
defend(x)

Results of tactical reading. attack(x) is true if the worm can be captured, defend(x) is true if there also is a defending move. Please notice that defend(x) will return false if there is no attack on the worm.

 
safe_xmove(x)
safe_omove(x)

True if an enemy or friendly stone, respectively, can safely be played at `x'. By safe it is understood that the move is legal and that it cannot be captured right away.

 
legal_xmove(x)
legal_omove(x)

True if an enemy or friendly stone, respectively, can legally be played at x.

 
o_somewhere(x,y,z, ...)
x_somewhere(x,y,z, ...)

True if O (respectively X) has a stone at one of the labelled vertices. In the diagram, these vertices should be marked with a `?'.

 
odefend_against(x,y)
xdefend_against(x,y)

True if an own stone at `x' would stop the enemy from safely playing at `y', and conversely for the second function.

 
does_defend(x,y)
does_attack(x,y)

True if a move at `x' defends/attacks the worm at `y'. For defense a move of the same color as `y' is tried and for attack a move of the opposite color.

 
xplay_defend(a,b,c,...,z)
oplay_defend(a,b,c,...,z)
xplay_attack(a,b,c,...,z)
oplay_attack(a,b,c,...,z)

These functions make it possible to do more complex reading experiments in the constraints. All of them work so that first the sequence of moves `a',`b',`c',... is played through with alternating colors, starting with `X' or `O' as indicated by the name. Then it is tested whether the worm at `z' can be attacked or defended, respectively. It doesn't matter who would be in turn to move, a worm of either color may be attacked or defended. For attacks the opposite color of the string being attacked starts moving and for defense the same color starts. The defend functions return true if the worm cannot be attacked in the position or if it can be attacked but also defended. The attack functions return true if there is a way to capture the worm, whether or not it can also be defended. If there is no stone present at `z' after the moves have been played, it is assumed that an attack has already been successful or a defense has already failed. If some of the moves should happen to be illegal, typically because it would have been suicide, the following moves are played as if nothing has happened and the attack or defense is tested as usual. It is assumed that this convention will give the relevant result without requiring a lot of special cases.

The special label `?' can be used to represent a tenuki. Thus oplay_defend(a,?,b,c) tries moves by `O' at `a' and `b', as if `X' plays the second move in another part of the board, then asks if `c' can be defended. The tenuki cannot be the first move of the sequence, nor does it need to be: instead of oplay_defend(?,a,b,c) you can use xplay_defend(a,b,c).

 
xplay_defend_both(a,b,c,...,y,z)
oplay_defend_both(a,b,c,...,y,z)
xplay_attack_either(a,b,c,...,y,z)
oplay_attack_either(a,b,c,...,y,z)

These functions are similar to the previous ones. The difference is that the last *two* arguments denote worms to be attacked or defended simultaneously. Obviously `y' and `z' must have the same color. If either location is empty, it is assumed that an attack has been successful or a defense has failed. The typical use for these functions is in cutting patterns, where it usually suffices to capture either cutstone.

The function xplay_defend_both plays alternate moves beginning with an `X' at `a'. Then it passes the last two arguments to defend_both in `engine/utils.c'. This function checks to determine whether the two strings can be simultaneously defended.

The function xplay_attack_either plays alternate moves beginning with an `X' move at `a'. Then it passes the last two arguments to attack_either in `engine/utils.c'. This function looks for a move which captures at least one of the two strings. In its current implementation attack_either only looks for uncoordinated attacks and would thus miss a double atari.

 
xplay_connect(a,b,c,...,y,z)
oplay_connect(a,b,c,...,y,z)
xplay_disconnect(a,b,c,...,y,z)
oplay_disconnect(a,b,c,...,y,z)

The function xplay_connect(a,b,c,...,y,z) begins with an `X' move at `a', then an `O' move at `b', and so forth, then finally calls string_connect() to determine whether `x' and `y' can be connected. The other functions are similar (see section 11.10 Connection Reading).

 
xplay_break_through(a,b,c,...,x,y,z)
oplay_break_through(a,b,c,...,x,y,z)

These functions are used to set up a position like

 
.O.    .y.
OXO    xXz

and `X' aims at capturing at least one of `x', `y', and `z'. If this succeeds `1' is returned. If it doesn't, `X' tries instead to cut through on either side and if this succeeds, `2' is returned. Of course the same shape with opposite colors can also be used.

Important notice: `x', `y', and `z' must be given in the order they have in the diagram above, or any reflection and/or rotation of it.

 
seki_helper(x)

Checks whether the string at `x' can attack any surrounding string. If so, return false as the move to create a seki (probably) wouldn't work.

 
threaten_to_save(x)

Calls add_followup_value to add as a move reason a conservative estimate of the value of saving the string `x' by capturing one opponent stone.

 
area_stone(x)

Returns the number of stones in the area around `x'.

 
area_space(x)

Returns the amount of space in the area around `x'.

 
eye(x)
proper_eye(x)
marginal_eye(x)

True if `x' is an eye space for either color, a non-marginal eye space for either color, or a marginal eye space for either color, respectively.

 
antisuji(x)

Tell the move generation that `x' is a substandard move that never should be played.

 
same_dragon(x,y)
same_worm(x,y)

Return true if `x' and `y' are the same dragon or worm respectively.

 
dragonsize(x)
wormsize(x)

Number of stones in the indicated dragon or worm.

 
add_connect_move(x,y)
add_cut_move(x,y)
add_attack_either_move(x,y)
add_defend_both_move(x,y)

Explicitly notify the move generation about move reasons for the move in the pattern.

 
halfeye(x)

Returns true if the empty intersection at `x' is a half eye.

 
remove_attack(x)

Inform the tactical reading that a supposed attack does in fact not work.

 
potential_cutstone(x)

True if cutstone2 field from worm data is larger than one. This indicates that saving the worm would introduce at least two new cutting points.

 
not_lunch(x,y)

Prevents the misreporting of `x' as lunch for `y'. For example, the following pattern tells GNU Go that even though the stone at `a' can be captured, it should not be considered "lunch" for the dragon at `b', because capturing it does not produce an eye:

 
XO|          ba|
O*|          O*|
oo|          oo|
?o|          ?o|

> not_lunch(a,b)

 
vital_chain(x)

Calls vital_chain to determine whether capturing the stone at `x' will result in one eye for an adjacent dragon. The current implementation just checks that the stone is not a singleton on the first line.

 
amalgamate(x,y)

Amalgamate (join) the dragons at `x' and `y' (see section 7. Worms and Dragons).

 
amalgamate_most_valuable(x,y,z)

Called when `x', `y', `z' point to three (preferably distinct) dragons, in situations such as this:

 
.O.X
X*OX
.O.X

In this situation, the opponent can play at `*', preventing the three dragons from becoming connected. However `O' can decide which cut to allow. The helper amalgamates the dragon at `y' with either `x' or `z', whichever is largest.

 
make_proper_eye(x)

This autohelper should be called when `x' is an eyespace which is misidentified as marginal. It is reclassified as a proper eyespace (see section 8.2 Eye spaces).

 
remove_halfeye(x)

Remove a half eye from the eyespace. This helper should not be run after make_dragons is finished, since by that time the eyespaces have already been analyzed.

 
remove_eyepoint(x)

Remove an eye point. This function can only be used before the segmentation into eyespaces.

 
owl_topological_eye(x,y)

Here `x' is an empty intersection which may be an eye or half eye for some dragon, and `y' is a stone of the dragon, used only to determine the color of the eyespace in question. Returns the sum of the values of the diagonal intersections, relative to `x', as explained in See section 8.8 Topology of Half Eyes and False Eyes, equal to 4 or more if the eye at `x' is false, 3 if it is a half eye, and 2 if it is a true eye.

 
owl_escape_value(x)

Returns the escape value at `x'. This is only useful in owl attack and defense patterns.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.8 Attack and Defense Database

The patterns in `attack.db' and `defense.db' are used to assist the tactical reading in finding moves that attacks or defends worms. The matching is performed during make_worms(), at the time when the tactical status of all worms is decided. None of the classes described above are useful in these databases, instead we have two other classes.

`D'
For each `O' worm in the pattern that can be tactically captured (worm[m][n].attack_code != 0), the move at `*' is tried. If it is found to defend the stone, this is registered as a reason for the move `*' and the defense point of the worm is set to `*'.
`A'
For each `X' worm in the pattern, it's tested whether the move at `*' captures the worm. If that is the case, this is registered as a reason for the move at `*'. The attack point of the worm is set to `*' and if it wasn't attacked before, a defense is searched for.

Furthermore, `A' patterns can only be used in `attack.db' and `D' patterns only in `defense.db'. Unclassified patterns may appear in these databases, but then they must work through actions to be effective.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.9 The Connections Database

The patterns in `conn.db' are used for helping make_dragons() amalgamate worms into dragons and to some extent for modifying eye spaces. The patterns in this database use the classifications `B', `C', and `e'. `B' patterns are used for finding cutting points, where amalgamation should not be performed, `C' patterns are used for finding existing connections, over which amalgamation is to be done, and `e' patterns are used for modifying eye spaces and reevaluating lunches. There are also some patterns without classification, which use action lines to have an impact. These are matched together with the `C' patterns. Further details and examples can be found in See section 7. Worms and Dragons.

We will illustrate these databases by example. In this situation:

 
XOO
O.O
...
`X' cannot play safely at the cutting point, so the `O' dragons are to be amalgamated. Two patterns are matched here:

 
Pattern CC204

O
.
O

:+,C

O
A
O

;!safe_xmove(A) && !ko(A) && !xcut(A)

Pattern CC205

XO
O.

:\,C

AO
OB

;attack(A) || (!safe_xmove(B) && !ko(B) && !xcut(B))

The constraints are mostly clear. For example the second pattern should not be matched if the `X' stone cannot be attacked and `X' can play safely at `B', or if `B' is a ko. The constraint !xcut(B) means that connection has not previously been inhibited by find_cuts. For example consider this situation:

 
OOXX
O.OX
X..O
X.OO
The previous pattern is matched here twice, yet `X' can push in and break one of the connections. To fix this, we include a pattern:

 
Pattern CB11

?OX?
O!OX
?*!O
??O?

:8,B

?OA?
OaOB
?*bO
??O?

; !attack(A) && !attack(B) && !xplay_attack(*,a,b,*) && !xplay_attack(*,b,a,*)

After this pattern is found, the xcut autohelper macro will return true at any of the points `*', `a' and `b'. Thus the patterns CB204 and CB205 will not be matched, and the dragons will not be amalgamated.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.10 Connections Functions

Here are the public functions in `connections.c'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.11 Tuning the Pattern databases

Since the pattern databases, together with the valuation of move reasons, decide GNU Go's personality, much time can be devoted to "tuning" them. Here are some suggestions.

If you want to experiment with modifying the pattern database, invoke with the `-a' option. This will cause every pattern to be evaluated, even when some of them may be skipped due to various optimizations.

You can obtain a Smart Game Format (SGF) record of your game in at least two different ways. One is to use CGoban to record the game. You can also have GNU Go record the game in Smart Game Format, using the `-o' option. It is best to combine this with `-a'. Do not try to read the SGF file until the game is finished and you have closed the game window. This does not mean that you have to play the game out to its conclusion. You may close the CGoban window on the game and GNU Go will close the SGF file so that you can read it.

If you record a game in SGF form using the `-o' option, GNU Go will add labels to the board to show all the moves it considered, with their values. This is an extremely useful feature, since one can see at a glance whether the right moves with appropriate weights are being proposed by the move generation.

First, due to a bug of unknown nature, it occasionally happens that GNU Go will not receive the SIGTERM signal from CGoban that it needs to know that the game is over. When this happens, the SGF file ends without a closing parenthesis, and CGoban will not open the file. You can fix the file by typing:

 
 echo ")" >>[filename]  

at the command line to add this closing parenthesis. Or you could add the ) using an editor.

Move values exceeding 99 (these should be rare) can be displayed by CGoban but you may have to resize the window in order to see all three digits. Grab the lower right margin of the CGoban window and pull it until the window is large. All three digits should be visible.

If you are playing a game without the `-o' option and you wish to analyze a move, you may still use CGoban's "Save Game" button to get an SGF file. It will not have the values of the moves labelled, of course.

Once you have a game saved in SGF format, you can analyze any particular move by running:

 
  gnugo -l [filename] -L [move number] -t -a -w

to see why GNU Go made that move, and if you make changes to the pattern database and recompile the program, you may ask GNU Go to repeat the move to see how the behavior changes. If you're using emacs, it's a good idea to run GNU Go in a shell in a buffer (M-x shell) since this gives good navigation and search facilities.

Instead of a move number, you can also give a board coordinate to `-L' in order to stop at the first move played at this location. If you omit the `-L' option, the move after those in the file will be considered.

If a bad move is proposed, this can have several reasons. To begin with, each move should be valued in terms of actual points on the board, as accurately as can be expected by the program. If it's not, something is wrong. This may have two reasons. One possibility is that there are reasons missing for the move or that bogus reasons have been found. The other possibility is that the move reasons have been misevaluated by the move valuation functions. Tuning of patterns is with a few exceptions a question of fixing the first kind of problems.

If there are bogus move reasons found, search through the trace output for the pattern that is responsible. (Some move reasons, e.g. most tactical attack and defense, do not originate from patterns. If no pattern produced the bogus move reason, it is not a tuning problem.) Probably this pattern was too general or had a faulty constraint. Try to make it more specific or correct bugs if there were any. If the pattern and the constraint looks right, verify that the tactical reading evaluates the constraint correctly. If not, this is either a reading bug or a case where the reading is too complicated for GNU Go.

If a connecting move reason is found, but the strings are already effectively connected, there may be missing patterns in `conn.db'. Similarly, worms may be incorrectly amalgamated due to some too general or faulty pattern in `conn.db'. To get trace output from the matching of patterns in `conn.db' you need to add a second `-t' option.

If a move reason is missing, there may be a hole in the database. It could also be caused by some existing pattern being needlessly specific, having a faulty constraint, or being rejected due to a reading mistake. Unless you are familiar with the pattern databases, it may be hard to verify that there really is a pattern missing. Look around the databases to try to get a feeling for how they are organized. (This is admittedly a weak point of the pattern databases, but the goal is to make them more organized with time.) If you decide that a new pattern is needed, try to make it as general as possible, without allowing incorrect matches, by using proper classification from among snOoXx and constraints. The reading functions can be put to good use. The reason for making the patterns as general as they can be is that we need a smaller number of them then, which makes the database much easier to maintain. Of course, if you need too complicated constraints, it's usually better to split the pattern.

If a move has the correct set of reasons but still is misevaluated, this is usually not a tuning problem. There are, however, some possibilities to work around these mistakes with the use of patterns. In particular, if the territorial value is off because delta_terri() give strange results, the (min)terri and maxterri values can be set by patterns as a workaround. This is typically done by the endgame patterns, where we can know the (minimum) value fairly well from the pattern. If it should be needed, (min)value and maxvalue can be used similarly. These possibilities should be used conservatively though, since such patterns are likely to become obsolete when better (or at least different) functions for e.g. territory estimation are being developed.

In order to choose between moves with the same move reasons, e.g. moves that connect two dragons in different ways, patterns with a nonzero shape value should be used. These should give positive shape values for moves that give good shape or good aji and negative values for bad shape and bad aji. Notice that these values are additive, so it's important that the matches are unique.

Sente moves are indicated by the use of the pattern followup value. This can usually not be estimated very accurately, but a good rule is to be rather conservative. As usual it should be measured in terms of actual points on the board. These values are also additive so the same care must be taken to avoid unintended multiple matches.

You can also get a visual display of the dragons using the `-T' option. The default GNU Go configuration tries to build a version with color support using either curses or the ansi escape sequences. You are more likely to find color support in rxvt than xterm, at least on many systems, so we recommend running:

 
  gnugo -l [filename] -L [move number] -T

in an rxvt window. If you do not see a color display, and if your host is a GNU/Linux machine, try this again in the Linux console.

Worms belonging to the same dragon are labelled with the same letters. The colors indicate the value of the field dragon.safety, which is set in `moyo.c'.

 
Green:  GNU Go thinks the dragon is alive
Yellow: Status unknown
Blue:   GNU Go thinks the dragon is dead
Red:    Status critical (1.5 eyes) or weak by the algorithm
        in `moyo.c'

If you want to get the same game over and over again, you can eliminate the randomness in GNU Go's play by providing a fixed random seed with the `-r' option.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.12 Implementation

The pattern code in GNU Go is fairly straightforward conceptually, but because the matcher consumes a significant part of the time in choosing a move, the code is optimized for speed. Because of this there are implementation details which obscure things slightly.

In GNU Go, the ascii `.db' files are precompiled into tables (see `patterns.h') by a standalone program `mkpat.c', and the resulting `.c' files are compiled and linked into the main GNU Go executable.

Each pattern is compiled to a header, and a sequence of elements, which are (notionally) checked sequentially at every position and orientation of the board. These elements are relative to the pattern 'anchor' (or origin). One `X' or `O' stone is (arbitrarily) chosen to represent the origin of the pattern. (We cannot dictate one or the other since some patterns contain only one colour or the other.) All the elements are in co-ordinates relative to this position. So a pattern matches "at" board position (m,n,o) if the the pattern anchor stone is on (m,n), and the other elements match the board when the pattern is transformed by transformation number `o'. (See below for the details of the transformations, though these should not be necessary)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.13 Symmetry and transformations

In general, each pattern must be tried in each of 8 different permutations, to reflect the symmetry of the board. But some patterns have symmetries which mean that it is unnecessary (and therefore inefficient) to try all eight. The first character after the `:' can be one of `8',`|',`\',`/', `X', `-', `+', representing the axes of symmetry. It can also be `O', representing symmetry under 180 degrees rotation.

 
transformation   I    -    |     .     \    l    r     /
                ABC  GHI  CBA   IHG   ADG  CFI  GDA   IFC
                DEF  DEF  FED   FED   BEH  BEH  HEB   HEB
                GHI  ABC  IHG   CBA   CFI  ADG  IFC   GDA

                 a    b    c     d     e    f    g     h

Then if the pattern has the following symmetries, the following are true:

 
|  c=a, d=b, g=e, h=f
-  b=a, c=d, e=f, g=h
\  e=a, g=b, f=c, h=d
/  h=a, f=b, g=c, e=d
O  a=d, b=c, e=h, f=g
X  a=d=e=h, b=c=f=g
+  a=b=c=d, e=f=g=h

We can choose to use transformations a,d,f,g as the unique transformations for patterns with either `|', `-', `\', or `/' symmetry.

Thus we choose to order the transformations a,g,d,f,h,b,e,c and choose first 2 for `X' and `+', the first 4 for `|', `-', `/', and `\', the middle 4 for `O', and all 8 for non-symmetrical patterns.

Each of the reflection operations (e-h) is equivalent to reflection about one arbitrary axis followed by one of the rotations (a-d). We can choose to reflect about the axis of symmetry (which causes no net change) and can therefore conclude that each of e-h is equivalent to the reflection (no-op) followed by a-d. This argument therefore extends to include `-' and `/' as well as `|' and `\'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.14 Implementation Details

  1. An entry in the pattern header states whether the anchor is an `X' or an `O'. This helps performance, since all transformations can be rejected at once if the anchor stone does not match. (Ideally, we could just define that the anchor is always `O' or always `X', but some patterns contain no `O' and some contain no `X'.)

  2. The pattern header contains the size of the pattern (ie the co-ordinates of the top left and bottom right elements) relative to the anchor. This allows the pattern can be rejected quickly if there is not room for the pattern to fit around the anchor stone in a given orientation (ie it is too near the edge of the board). The bounding box information must first be transformed like the elements before it can be tested, and after transforming, we need to work out where the top-left and bottom-right corners are.

  3. The edge constraints are implemented by notionally padding the pattern with rows or columns of `?' until it is exactly 19 (or whatever the current board size is) elements wide or high. Then the pattern is quickly rejected by (ii) above if it is not at the edge. So the example pattern above is compiled as if it was written

     
    "example"
    .OO????????????????
    *XX????????????????
    o??????????????????
    :8,80
    
    

  4. The elements in a pattern are sorted so that non-space elements are checked before space elements. It is hoped that, for most of the game, more squares are empty, and so the pattern can be more quickly rejected doing it this way.

  5. The actual tests are performed using an 'and-compare' sequence. Each board position is a 2-bit quantity. %00 for empty, %01 for `O', %10 for `X'. We can test for an exact match by and-ing with %11 (no-op), then comparing with 0, 1 or 2. The test for `o' is the same as a test for 'not-X', ie not %10. So and with %01 should give 0 if it matches. Similarly `x' is a test that bit 0 is not set.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.15 The "Grid" Optimization

The comparisons between pattern and board are performed as 2-bit bitwise operations. Therefore they can be performed in parallel, 16-at-a-time on a 32-bit machine.

Suppose the board is layed out as follows :

 
 .X.O....OO
 XXXXO.....
 .X..OOOOOO
 X.X.......
 ....X...O.

which is internally stored internally in a 2d array (binary)

 
 00 10 00 01 00 00 00 00 01 01
 10 10 10 10 01 00 00 00 00 00
 00 10 00 00 01 01 01 01 01 01
 10 00 10 00 00 00 00 00 00 00
 00 00 00 00 10 00 00 00 01 00

we can compile this to a composite array in which each element stores the state of a 4x4 grid of squares :

 
 ????????  ????????  ???????? ...
 ??001000  00100001  10000100
 ??101010  10101010  10101001
 ??001000  00100000  10000001

 ??001000  00100001  ...
 ??101010  10101010
 ??001000  00100000
 ??001000  10001000 

...

 ??100010  ...
 ??000000
 ????????
 ????????

Where '??' is off the board.

We can store these 32-bit composites in a 2d merged-board array, substituting the illegal value %11 for '??'.

Similarly, for each pattern, mkpat produces appropriate 32-bit and-value masks for the pattern elements near the anchor. It is a simple matter to test the pattern with a similar test to (5) above, but for 32-bits at a time.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.16 The Joseki Compiler

GNU Go includes a joseki compiler in `patterns/joseki.c'. This processes an SGF file (with variations) and produces a sequence of patterns which can then be fed back into mkpat. The joseki database is currently in files in `patterns/' called `hoshi.sgf', `komoku.sgf', `sansan.sgf', `mokuhazushi.sgf' and `takamoku.sgf'. This division can be revised whenever need arises.

The SGF files are transformed into the pattern database `.db' format by the program in `joseki.c'. These files are in turn transformed into C code by the program in `mkpat.c' and the C files are compiled and linked into the GNU Go binary.

Not every node in the SGF file contributes a pattern. The nodes which contribute patterns have the joseki in the upper right corner, with the boundary marked with a square mark and other information to determine the resulting pattern marked in the comments.

The intention is that the move valuation should be able to choose between the available variations by normal valuation. When this fails the primary workaround is to use shape values to increase or decrease the value. It is also possible to add antisuji variations to forbid popular suboptimal moves. As usual constraints can be used, e.g. to condition a variation on a working ladder.

The joseki format has the following components for each SGF node:

Example: If the comment in the SGF file looks like

 
F
:C,shape(3)
;xplay_attack(A,B,C,D,*)

the generated pattern will have a colon line

 
:8,sjC,shape(3)

and a constraint

 
;xplay_attack(A,B,C,D,*)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.17 Ladders in Joseki

As an example of how to use autohelpers with the Joseki compiler, we consider an example where a Joseki is bad if a ladder fails. Assume we have the taisha and are considering connecting on the outside with the pattern

 
--------+
........|
........|
...XX...|
...OXO..|
...*O...|
....X...|
........|
........|

But this is bad unless we have a ladder in our favor. To check this we add a constraint which may look like

 
--------+
........|
........|
...XX...|
...OXO..|
...*OAC.|
....DB..|
........|
........|

;oplay_attack(*,A,B,C,D)

In order to accept the pattern we require that the constraint on the semicolon line evaluates to true. This particular constraint has the interpretation "Play with alternating colors, starting with `O', on the intersections `*', `A', `B', and `C'. Then check whether the stone at `D' can be captured." I.e. play to this position

 
--------+
........|
........|
...XX...|
...OXO..|
...OOXX.|
....XO..|
........|
........|

and call attack() to see whether the lower `X' stone can be captured. This is not limited to ladders, but in this particular case the reading will of course involve a ladder.

The constraint diagram above with letters is how it looks in the `.db' file. The joseki compiler knows how to create these from labels in the SGF node. `Cgoban' has an option to create one letter labels, but this ought to be a common feature for SGF editors.

Thus in order to implement this example in SGF, one would add labels to the four intersections and a comment:

 
;oplay_attack(*,A,B,C,D)

The appropriate constraint (autohelper macro) will then be added to the Joseki `.db' file.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.18 Corner Matcher

GNU Go uses a special matcher for joseki patterns. It has certain constraints on the patterns it can match, but is much faster and takes far less space to store patterns than the standard matcher.

Patterns used with corner matcher have to qualify the following conditions:

Corner matcher was specifically designed for joseki patterns and they of course satisfy all the conditions above. With some modifications corner matcher could be used for fuseki patterns as well, but fullboard matcher does its work just fine.

The main idea of the matcher is very same to the one of DFA matcher (see section 10.3 Pattern matching with DFA): check all available patterns at once, not a single pattern at a time. A modified version of DFA matcher could be used for joseki pattern matching, but its database would be very large. Corner matcher capitalizes on the fact that there are relatively few stones in each such pattern.

Corner pattern database is organized into a tree. Nodes of the tree are called "variations". Variations represent certain sets of stones in a corner of the board. Root variation corresponds to an empty corner and a step down the tree is equivalent to adding a stone to the corner. Each variation has several properties:

By corner area we define a rectangle which corners are the current corner of the board and the position of the stone (inclusive). For instance, if the current board corner is A19 then corner area of a stone at C18 consists of A18, A19, B18, B19, C18 and C19.

Variation which is a direct child of the root variation matches if there is any stone at the variation position and the stone is alone in its corner area.

Variation at a deeper level of the tree matches if there is a stone of specified color in variation position and the number of stones in its corner area is equal to the number specified in variation structure.

When a certain variation matches, all its children has to be checked recursively for a match.

All leaf variations and some inner ones have patterns attached to them. For a pattern to match, it is required that its parent variation matches. In addition, it is checked that pattern is being matched for the appropriate color (using its variation "stone color" field) and that the number of stones in the area where the pattern is being matched is indeed equal to the number of stones in the pattern. The "stone position" property of the pattern variation determines the move suggested by the pattern.

Consider this joseki pattern which has four stones:

 
------+
......|
......|
.O*...|
.XXO..|
......|
......|

To encode it for the corner matcher, we have to use five variations, each next being a child of previous:

Tree level Position Color Number of stones
1 R16 "same" 1
2 P17 "same" 1
3 Q16 "other" 2
4 P16 "other" 4
5 Q17 "same" 1

The fifth variation should have an attached pattern. Note that the stone color for the fifth variation is "same" because the first matched stone for this pattern is `O' which stands for the stones of the player to whom moves are being suggested with `*'.

The tree consists of all variations for all patterns combined together. Variations for each patterns are sorted to allow very quick tree branch rejection and at the same time keep the database small enough. More details can be found in comments in file `mkpat.c'

Corner matcher resides in `matchpat.c' in two functions: corner_matchpat() and do_corner_matchpat(). The former computes num_stones[] array which holds number of stones in corner areas of different intersections of the board for all possible transformations. corner_matchpat() also matches top-level variations. do_corner_matchpat() is responsible for recursive matching on the variation tree and calling callback function upon pattern match.

Tree-like database for corner matcher is generated by mkpat program. Database generator consists of several functions, most important are: corner_best_element(), corner_variation_new(), corner_follow_variation() and corner_add_pattern().


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.19 Emacs Mode for Editing Patterns

If you use GNU Emacs (XEmacs might work too), you can try a special mode for editing GNU Go pattern databases. The mode resides in `patterns/gnugo-db.el'.

Copy the file to `emacs/site-lisp' directory. You can then load the mode with (require 'gnugo-db). It makes sense to put this line into your configuration file (`~/.emacs'). You can either use gnugo-db-mode command to switch to pattern editing mode, or use the following code snippet to make Emacs do this automatically upon opening a file with `.db' suffix:

 
	(setq auto-mode-alist
	      (append
	       auto-mode-alist
	       '(("\\.db\\'" . gnugo-db-mode))))

Pattern editing mode provides the following features:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10. The DFA pattern matcher

In this chapter, we describe the principles of the GNU Go DFA pattern matcher. The aim of this system is to permit a fast pattern matching when it becomes time critical like in owl module (12.1 The Owl Code). Since GNU Go 3.2, this is enabled by default. You can still get back the traditional pattern matcher by running configure --disable-dfa and then recompiling GNU Go.

Otherwise, a finite state machine called a Deterministic Finite State Automaton (10.2 What is a DFA) will be built off line from the pattern database. This is used at runtime to speedup pattern matching (10.3 Pattern matching with DFA and 10.5 Incremental Algorithm). The runtime speedup is at the cost of an increase in memory use and compile time.

10.1 Introduction to the DFA  Scanning the board along a path
10.2 What is a DFA  A recall of language theory.
10.3 Pattern matching with DFA  How to retrieve go patterns with a DFA?
10.4 Building the DFA  Playing with explosives.
10.5 Incremental Algorithm  The joy of determinism.
10.6 Some DFA Optimizations  Some possible optimizations.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.1 Introduction to the DFA

The general idea is as follows:

For each intersection of the board, its neighbourhood is scanned following a predefined path. The actual path used does not matter very much; GNU Go uses a spiral as shown below.

 
  +---B--------------+
  | C 4 A . . . . . .|
  D 5 1 3 9 . . . . .|
  E 6 2 8 . . X . . .|
  | F 7 . . . . . . .|
  | . +-> . . . . . .|
  | . . . . . . . . .|
  | . O . . . X . . .|
  | . . . . . . . . .|
  | . . . . . . . . .|
  +------------------+
path

In each step of the path, the pattern matcher jumps into a state determined by what it has found on the board so far. If we have successfully matched one or several patterns in this step, this state immediately tells us so (in its attribute). But the state also implicitly encodes which further patterns can still get matched: The information stored in the state contains in which state to jump next, depending on whether we find a black, white or empty intersection (or an intersection out of board) in the next step of the path. The state will also immediately tell us if we cannot find any further pattern (by telling us to jump into the error state).

These sloppy explanations may become clearer with the definitions in the next section (10.2 What is a DFA).

Reading the board following a predefined path reduces the two dimentional pattern matching to a linear text searching problem. For example, this pattern

 
?X?
.O?
?OO

scanned following the path

 
 B
C4A
5139
628
 7

gives the string "OO?X.?*O*?*?" where "?" means 'don't care' and "*" means 'don't care, can even be out of board'.

So we can forget that we are dealing with two dimensional patterns and consider linear patterns.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.2 What is a DFA

The acronym DFA means Deterministic Finite state Automaton (See http://www.eti.pg.gda.pl/~jandac/thesis/node12.html or Hopcroft & Ullman "Introduction to Language Theory" for more details). DFA are common tools in compilers design (Read Aho, Ravi Sethi, Ullman "COMPILERS: Principles, Techniques and Tools" for a complete introduction), a lot of powerfull text searching algorithm like Knuth-Morris-Pratt or Boyer-Moore algorithms are based on DFA's (See http://www-igm.univ-mlv.fr/~lecroq/string/ for a bibliography of pattern matching algorithms).

Basically, a DFA is a set of states connected by labeled transitions. The labels are the values read on the board, in GNU Go these values are EMPTY, WHITE, BLACK or OUT_BOARD, denoted respectively by '.','O','X' and '#'.

The best way to represent a DFA is to draw its transition graph: the pattern "????..X" is recognized by the following DFA:

 
   .,X,O     .,X,O    .,X,O    .,X,O     .      .      X
[1]------>[2]----->[3]----->[4]----->[5]--->[6]--->[7]--->[8 OK!]
Start

dfa

This means that starting from state [1], if you read '.','X' or 'O' on the board, go to state [2] and so on until you reach state [5]. From state [5], if you read '.', go to state [6] otherwise go to error state [0]. And so on until you reach state [8]. As soon as you reach state [8], you recognize Pattern "????..X"

Adding a pattern like "XXo" ('o' is a wildcard for not 'X') will transform directly the automaton by synchronization product (10.4 Building the DFA). Consider the following DFA:

 
Start .,O   .,X,O    .,O,X   .,X,O      .      .       X
[1]---->[2]----->[3]----->[4]------>[5]--->[6]---->[7]--->[8 OK!]
 |                ^        ^         ^
 |            .,O |        |         |
 |            ----         |         |
 |           |          X  |         |
 |           |          ---    .,X,O |
 |           |         |             |
 |     X     |   X     | O,.         |
  --------->[9]------>[A]--->[B OK!]-

dfa2

By adding a special error state and completing each state by a transition to error state when there is none, we transform easily a DFA in a Complete Deterministic Finite state Automaton (CDFA). The synchronization product (10.4 Building the DFA) is only possible on CDFA's.

 
Start .,O   .,X,O    .,O,X   .,X,O      .      .       X
[1]---->[2]----->[3]----->[4]------>[5]--->[6]---->[7]--->[8 OK!]
 |                ^        ^         ^      |       |      |
 |            .,O |        |         |      |       |      |
 |            ----         |         |      |       |      |
 |           |          X  |         |      |X,O    | .,O  |X,.,O
 |           |          ---    .,X,O |      |       |      |
 |           |         |             |      |       |      |
 |     X     |   X     | O,.         |     \ /     \ /    \ /
  --------->[9]------>[A]--->[B OK!]-      [0  Error state !]
cdfa

The graph of a CDFA is coded by an array of states: The 0 state is the "error" state and the start state is 1.

 
----------------------------------------------------
 state  |   .    |   O    |   X    |   #    |  att
----------------------------------------------------
      1 |      2 |      2 |      9 |      0 |
      2 |      3 |      3 |      3 |      0 |
      3 |      4 |      4 |      4 |      0 |
      5 |      6 |      0 |      0 |      0 |
      6 |      7 |      0 |      0 |      0 |
      7 |      0 |      0 |      8 |      0 |
      8 |      0 |      0 |      0 |      0 | Found pattern "????..X"
      9 |      3 |      3 |      A |      0 |
      A |      B |      B |      4 |      0 |
      B |      5 |      5 |      5 |      0 | Found pattern "XXo"
----------------------------------------------------

To each state we associate an often empty list of attributes which is the list of pattern indexes recognized when this state is reached. In '`dfa.h'' this is basically represented by two stuctures:

 

/* dfa state */
typedef struct state
{
  int next[4]; /* transitions for EMPTY, BLACK, WHITE and OUT_BOARD */
  attrib_t *att;
}
state_t;

/* dfa */
typedef struct dfa
{
  attrib_t *indexes; /* Array of pattern indexes */
  int maxIndexes;

  state_t *states; /* Array of states */
  int maxStates;
}
dfa_t;


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.3 Pattern matching with DFA

Recognizing with a DFA is very simple and thus very fast (See 'scan_for_pattern()' in the '`engine/matchpat.c'' file).

Starting from the start state, we only need to read the board following the spiral path, jump from states to states following the transitions labelled by the values read on the board and collect the patterns indexes on the way. If we reach the error state (zero), it means that no more patterns will be matched. The worst case complexity of this algorithm is o(m) where m is the size of the biggest pattern.

Here is an example of scan:

First we build a minimal DFA recognizing these patterns: "X..X", "X???", "X.OX" and "X?oX". Note that wildcards like '?','o', or 'x' give multiple out-transitions.

 
----------------------------------------------------
 state  |   .    |   O    |   X    |   #    |  att
----------------------------------------------------
      1 |      0 |      0 |      2 |      0 |
      2 |      3 |     10 |     10 |      0 |
      3 |      4 |      7 |      9 |      0 |
      4 |      5 |      5 |      6 |      0 |
      5 |      0 |      0 |      0 |      0 |    2
      6 |      0 |      0 |      0 |      0 |    4    2    1
      7 |      5 |      5 |      8 |      0 |
      8 |      0 |      0 |      0 |      0 |    4    2    3
      9 |      5 |      5 |      5 |      0 |
     10 |     11 |     11 |      9 |      0 |
     11 |      5 |      5 |     12 |      0 |
     12 |      0 |      0 |      0 |      0 |    4    2
----------------------------------------------------

We perform the scan of the string "X..XXO...." starting from state 1:

Current state: 1, substring to scan : X..XXO....

We read an 'X' value, so from state 1 we must go to state 2.

Current state: 2, substring to scan : ..XXO....

We read a '.' value, so from state 2 we must go to state 3 and so on ...

 
Current state:     3, substring to scan : .XXO....
Current state:     4, substring to scan : XXO....
Current state:     6, substring to scan : XO....
Found pattern 4
Found pattern 2
Found pattern 1                 

After reaching state 6 where we match patterns 1,2 and 4, there is no out-transitions so we stop the matching. To keep the same match order as in the standard algorithm, the patterns indexes are collected in an array and sorted by indexes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.4 Building the DFA

The most flavouring point is the building of the minimal DFA recognizing a given set of patterns. To perform the insertion of a new pattern into an already existing DFA one must completly rebuild the DFA: the principle is to build the minimal CDFA recognizing the new pattern to replace the original CDFA with its synchronised product by the new one.

We first give a formal definition: Let L be the left CDFA and R be the right one. Let B be the synchronised product of L by R. Its states are the couples (l,r) where l is a state of L and r is a state of R. The state (0,0) is the error state of B and the state (1,1) is its initial state. To each couple (l,r) we associate the union of patterns recognized in both l and r. The transitions set of B is the set of transitions (l1,r1)---a--->(l2,r2) for each symbol 'a' such that both l1--a--->l2 in L and r1--a--->r2 in R.

The maximal number of states of B is the product of the number of states of L and R but almost all this states are non reachable from the initial state (1,1).

The algorithm used in function 'sync_product()' builds the minimal product DFA only by keeping the reachable states. It recursively scans the product CDFA by following simultaneously the transitions of L and R. A hast table (gtest) is used to check if a state (l,r) has already been reached, the reachable states are remapped on a new DFA. The CDFA thus obtained is minimal and recognizes the union of the two patterns sets.

For example these two CDFA's:

sync-prod1

Give by synchronization product the following one:

sync-prod2

It is possible to construct a special pattern database that generates an "explosive" automaton: the size of the DFA is in the worst case exponential in the number of patterns it recognizes. But it doesn't occur in pratical situations: the DFA size tends to be stable. By stable we mean that if we add a pattern which greatly increases the size of the DFA it also increases the chance that the next added pattern does not increase its size at all. Nevertheless there are many ways to reduce the size of the DFA. Good compression methods are explained in Aho, Ravi Sethi, Ullman "COMPILERS: Principles, Techniques and Tools" chapter Optimization of DFA-based pattern matchers.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.5 Incremental Algorithm

The incremental version of the DFA pattern matcher is not yet implemented in GNU Go but we explain here how it will work. By definition of a deterministic automaton, scanning the same string will reach the same states every time.

Each reached state during pattern matching is stored in a stack top_stack[i][j] and state_stack[i][j][stack_idx] We use one stack by intersection (i,j). A precomputed reverse path list allows to know for each couple of board intersections (x,y) its position reverse(x,y) in the spiral scan path starting from (0,0).

When a new stone is put on the board at (lx,ly), the only work of the pattern matcher is:

 

 for(each stone on the board at (i,j))
    if(reverse(lx-i,ly-j) < top_stack[i][j])
      {
         begin the dfa scan from the state
         state_stack[i][j][reverse(lx-i,ly-j)];
      }

In most situations reverse(lx-i,ly-j) will be inferior to top_stack[i][j]. This should speedup a lot pattern matching.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.6 Some DFA Optimizations

The DFA is constructed to minimize jumps in memory making some assumptions about the frequencies of the values: the EMPTY value is supposed to appear often on the board, so the the '.' transition are almost always successors in memory. The OUT_BOARD are supposed to be rare, so '#' transitions will almost always imply a big jump.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11. Tactical reading

The process of visualizing potential moves done by you and your opponent to learn the result of different moves is called "reading". GNU Go does three distinct types of reading: tactical reading which typically is concerned with the life and death of individual strings, Owl reading which is concerned with the life and death of dragons, and connection reading. In this Chapter, we document the tactical reading code, which is in `engine/reading.c'.

11.1 Reading Basics  
11.2 Hashing of Positions  Hashing of positions
11.3 Persistent Reading Cache  
11.4 Ko Handling  Ko handling
11.5 A Ko Example  
11.6 Another Ko Example  
11.7 Alternate Komaster Schemes  
11.8 Superstrings  
11.9 Debugging the reading code  
11.10 Connection Reading  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.1 Reading Basics

What we call Tactical Reading is the analysis whether there is a direct capture of a single string, or whether there is a move to prevent such a direct capture.

If the reading module finds out that the string can get captured, this answer should (usually) be trusted. However, if it says it can be defended, this does not say as much. It is often the case that such a string has no chance to make a life, but that it cannot be captured within the horizon (and the cutoff heuristics) of the tactical reading.

The tactical reading is done by the functions in `engine/reading.c'. It is a minimax search that declares win for the attacker once he can physically take the string off board, whereas the defense is considered successful when the string has sufficiently many liberties. A string with five liberties is always considered alive. At higher depth within the search tree even fewer liberties cause GNU Go to give up the attack, See depthparams.

The reading code makes use of a stack onto which board positions can be pushed. The parameter stackp is zero if GNU Go is examining the true board position; if it is higher than zero, then GNU Go is examining a hypothetical position obtained by playing several moves.

The most important public reading functions are attack and find_defense. These are wrappers for functions do_attack and do_find_defense which are declared statically in `reading.c'. The functions do_attack and do_find_defense call each other recursively.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.1.1 Organization of the reading code

The function do_attack and do_find_defense are wrappers themselves and call attack1, attack2, attack3 or attack4 resp. defend1, defend1, defend1 or defend1 depending on the number of liberties.

These are fine-tuned to generate and try out the moves in an efficient order. They generate a few moves themselves (mostly direct liberties of the string), and then call helper functions called ..._moves which suggest less obvious moves. Which of these functions get called depends on the number of liberties and of the current search depth.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.1.2 Return Codes

The return codes of the reading (and owl) functions and owl can be 0, KO_B, KO_A or WIN. Each reading function determines whether a particular player (assumed to have the move) can solve a specific problem, typically attacking or defending a string.

A return code of WIN means success, 0 failure, while KO_A and KO_B are success conditioned on ko. A function returns KO_A if the position results in ko and that the player to move will get the first ko capture (so the opponent has to make the first ko threat). A return code of KO_B means that the player to move will have to make the first ko threat.

If GNU Go is compiled with the configure option `--enable-experimental-owl-ext' then the owl functions also have possible return codes of GAIN and LOSS. A code of GAIN means that the attack (or defense) does not succeed, but that in the process of trying to attack or defend, an opponent's worm is captured. A code of LOSS means that the attack or defense succeeds, but that another friendly worm dies during the attack or defense.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.1.3 Reading cutoff and depth parameters

Depth of reading is controlled by the parameters depth and branch_depth. The depth has a default value DEPTH (in `liberty.h'), which is set to 16 in the distribution, but it may also be set at the command line using the `-D' or `--depth' option. If depth is increased, GNU Go will be stronger and slower. GNU Go will read moves past depth, but in doing so it makes simplifying assumptions that can cause it to miss moves.

Specifically, when stackp > depth, GNU Go assumes that as soon as the string can get 3 liberties it is alive. This assumption is sufficient for reading ladders.

The branch_depth is typically set a little below depth. Between branch_depth and depth, attacks on strings with 3 liberties are considered, but branching is inhibited, so fewer variations are considered.

%@findex small_semeai %Currently the reading code does not try to defend a string by %attacking a boundary string with more than two liberties. Because %of this restriction, it can make oversights. A symptom of this is %two adjacent strings, each having three or four liberties, each %classified as DEAD. To resolve such situations, a function %small_semeai() (in `engine/semeai.c') looks for such %pairs of strings and corrects their classification.

The backfill_depth is a similar variable with a default 12. Below this depth, GNU Go will try "backfilling" to capture stones. For example in this situation:

 
.OOOOOO.    on the edge of the board, O can capture X but
OOXXXXXO    in order to do so he has to first play at a in
.aObX.XO    preparation for making the atari at b. This is
--------    called backfilling.

Backfilling is only tried with stackp <= backfill_depth. The parameter backfill_depth may be set using the `-B' option.

The fourlib_depth is a parameter with a default of only 7. Below this depth, GNU Go will try to attack strings with four liberties. The fourlib_depth may be set using the `-F' option.

The parameter ko_depth is a similar cutoff. If stackp<ko_depth, the reading code will make experiments involving taking a ko even if it is not legal to do so (i.e., it is hypothesized that a remote ko threat is made and answered before continuation). This parameter may be set using the `-K' option.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.2 Hashing of Positions

To speed up the reading process, we note that a position can be reached in several different ways. In fact, it is a very common occurrence that a previously checked position is rechecked, often within the same search but from a different branch in the recursion tree.

This wastes a lot of computing resources, so in a number of places, we store away the current position, the function we are in, and which worm is under attack or to be defended. When the search for this position is finished, we also store away the result of the search and which move made the attack or defense succeed.

All this data is stored in a hash table, sometimes also called a transposition table, where Go positions are the key and results of the reading for certain functions and groups are the data. You can increase the size of the Hash table using the `-M' or `--memory' option see section 3.9 Invoking GNU Go: Command line options.

The hash table is created once and for all at the beginning of the game by the function hashtable_new(). Although hash memory is thus allocated only once in the game, the table is reinitialized at the beginning of each move by a call to hashtable_clear() from genmove().

11.2.1 Calculation of the hash value  
11.2.2 Organization of the hash table  
11.2.3 Hash Structures  Structures in `hash.h'


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.2.1 Calculation of the hash value

The hash algorithm is called Zobrist hashing, and is a standard technique for go and chess programming. The algorithm as used by us works as follows:

  1. First we define a go position. This positions consists of

    It is not necessary to specify the color to move (white or black) as part of the position. The reason for this is that read results are stored separately for the various reading functions such as attack3, and it is implicit in the calling function which player is to move.

  2. For each location on the board we generate random numbers:

    These random numbers are generated once at initialization time and then used throughout the life time of the hash table.

  3. The hash key for a position is the XOR of all the random numbers which are applicable for the position (white stones, black stones, and ko position).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.2.2 Organization of the hash table

The hash table consists of 3 parts:

When the hash table is created, these 3 areas are allocated using malloc(). When the hash table is populated, all contents are taken from the Hash nodes and the Read results. No further allocation is done and when all nodes or results are used, the hash table is full. Nothing is deleted from the hash table except when it is totally emptied, at which point it can be used again as if newly initialized.

When a function wants to use the hash table, it looks up the current position using hashtable_search(). If the position doesn't already exist there, it can be entered using

hashtable_enter_position().

Once the function has a pointer to the hash node containing a function, it can search for a result of a previous search using hashnode_search(). If a result is found, it can be used, and if not, a new result can be entered after a search using hashnode_new_result().

Hash nodes which hash to the same position in the hash table (collisions) form a simple linked list. Read results for the same position, created by different functions and different attacked or defended strings also form a linked list.

This is deemed sufficiently efficient for now, but the representation of collisions could be changed in the future. It is also not determined what the optimum sizes for the hash table, the number of positions and the number of results are.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.2.3 Hash Structures

The basic hash structures are declared in `engine/hash.h' and `engine/cache.c'

 
typedef struct hashposition_t {
  Compacttype  board[COMPACT_BOARD_SIZE];
  int          ko_pos;
} Hashposition;

Represents the board and optionally the location of a ko, which is an illegal move. The player whose move is next is not recorded.

 
typedef struct {
  Hashvalue     hashval;
  Hashposition  hashpos;
} Hash_data;

Represents the return value of a function (hashval) and the board state (hashpos).

 
typedef struct read_result_t {
  unsigned int data1;	
  unsigned int data2;

  struct read_result_t *next;
} Read_result;

The data1 field packs into 32 bits the following fields:

 
komaster:  2 bits (EMPTY, BLACK, WHITE, or GRAY)
kom_pos : 10 bits (allows MAX_BOARD up to 31)
routine :  4 bits (currently 10 different choices)
str1    : 10 bits
stackp  :  5 bits

The data2 field packs into 32 bits the following fields:

 
status :   2 bits (0 free, 1 open, 2 closed)
result1:   4 bits
result2:   4 bits
move   :  10 bits
str2   :  10 bits

The komaster and (kom_pos) field are documented in See section 11.4 Ko Handling.

When a new result node is created, 'status' is set to 1 'open'. This is then set to 2 'closed' when the result is entered. The main use for this is to identify open result nodes when the hashtable is partially cleared. Another potential use for this field is to identify repeated positions in the reading, in particular local double or triple kos.

 
typedef struct hashnode_t {
  Hash_data            key;
  Read_result        * results;
  struct hashnode_t  * next;
} Hashnode;

The hash table consists of hash nodes. Each hash node consists of The hash value for the position it holds, the position itself and the actual information which is purpose of the table from the start.

There is also a pointer to another hash node which is used when the nodes are sorted into hash buckets (see below).

 
typedef struct hashtable {
  size_t         hashtablesize;	/* Number of hash buckets */
  Hashnode    ** hashtable;	/* Pointer to array of hashnode lists */

  int            num_nodes;	/* Total number of hash nodes */
  Hashnode     * all_nodes;	/* Pointer to all allocated hash nodes. */
  int            free_node;	/* Index to next free node. */

  int            num_results;	/* Total number of results */
  Read_result  * all_results;	/* Pointer to all allocated results. */
  int            free_result;	/* Index to next free result. */
} Hashtable;

The hash table consists of three parts:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.3 Persistent Reading Cache

Some calculations can be safely saved from move to move. If the opponent's move is not close to our worm or dragon, we do not have to reconsider the life or death of that group on the next move. So the result is saved in a persistent cache. Persistent caches are used for are used in the engine for several types of read results.

In this section we will discuss the persistent caching of tactical reading but the same principles apply to the other persistent caches.

Persistent caching is an important performance feature. However it can lead to mistakes and debugging problems--situations where GNU Go generates the right move during debugging but plays a wrong move during a game. If you suspect a persistent cache effect you may try loading the sgf file with the `--replay' option and see if the mistake is repeated (see section 3.9 Invoking GNU Go: Command line options).

The function store_persistent_cache() is called only by attack and find_defense, never from their static recursive counterparts do_attack and do_defend. The function store_persistent_reading_cache() attempts to cache the most expensive reading results. The function search_persistent_reading_cache attempts to retrieve a result from the cache.

If all cache entries are occupied, we try to replace the least useful one. This is indicated by the score field, which is initially the number of nodes expended by this particular reading, and later multiplied by the number of times it has been retrieved from the cache.

Once a (permanent) move is made, a number of cache entries immediately become invalid. These are cleaned away by the function purge_persistent_reading_cache(). To have a criterion for when a result may be purged, the function store_persistent_cache() computes the reading shadow and active area. If a permanent move is subsequently played in the active area, the cached result is invalidated. We now explain this algorithm in detail.

The reading shadow is the concatenation of all moves in all variations, as well as locations where an illegal move has been tried.

Once the read is finished, the reading shadow is expanded to the active area which may be cached. The intention is that as long as no stones are played in the active area, the cached value may safely be used.

Here is the algorithm used to compute the active area. This algorithm is in the function store_persistent_reading_cache(). The most expensive readings so far are stored in the persistent cache.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.4 Ko Handling

The principles of ko handling are the same for tactical reading and owl reading.

We have already mentioned (see section 11.1 Reading Basics) that GNU Go uses a return code of KO_A or KO_B if the result depends on ko. The return code of KO_B means that the position can be won provided the player whose move calls the function can come up with a sufficiently large ko threat. In order to verify this, the function must simulate making a ko threat and having it answered by taking the ko even if it is illegal. We call such an experimental taking of the ko a conditional ko capture.

Conditional ko captures are accomplished by the function tryko(). This function is like trymove() except that it does not require legality of the move in question.

The static reading functions, and the global functions do_attack and do_find_defense consult parameters komaster, kom_pos, which are declared static in `board.c'. These mediate ko captures to prevent the occurrence of infinite loops. During reading, the komaster values are pushed and popped from a stack.

Normally komaster is EMPTY but it can also be `BLACK', `WHITE', GRAY_BLACK, GRAY_WHITE or WEAK_KO. The komaster is set to color when color makes a conditional ko capture. In this case kom_pos is set to the location of the captured ko stone.

If the opponent is komaster, the reading functions will not try to take the ko at kom_pos. Also, the komaster is normally not allowed to take another ko. The exception is a nested ko, characterized by the condition that the captured ko stone is at distance 1 both vertically and horizontally from kom_pos, which is the location of the last stone taken by the komaster. Thus in this situation:

 
         .OX
         OX*X
        OmOX
         OO

Here if `m' is the location of kom_pos, then the move at `*' is allowed.

The rationale behind this rule is that in the case where there are two kos on the board, the komaster cannot win both, and by becoming komaster he has already chosen which ko he wants to win. But in the case of a nested ko, taking one ko is a precondition to taking the other one, so we allow this.

If the komaster's opponent takes a ko, then both players have taken one ko. In this case komaster is set to GRAY_BLACK or GRAY_WHITE and after this further ko captures are even further restricted.

If the ko at kom_pos is filled, then the komaster reverts to EMPTY.

In detail, the komaster scheme is as follows. Color `O' is to move. This scheme is known as scheme 5 since in versions of GNU Go through 3.4, several different schemes were included.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.5 A Ko Example

To see the komaster scheme in action, consider this position from the file `regressions/games/life_and_death/tripod9.sgf'. We recommend studying this example by examining the variation file produced by the command:

 
  gnugo -l tripod9.sgf --decide-dragon C3 -o vars.sgf

In the lower left hand corner, there are kos at A2 and B4. Black is unconditionally dead because if W wins either ko there is nothing B can do.

 
 8 . . . . . . . .
 7 . . O . . . . .
 6 . . O . . . . .
 5 O O O . . . . .
 4 O . O O . . . .
 3 X O X O O O O .
 2 . X X X O . . .
 1 X O . . . . . .
   A B C D E F G H

This is how the komaster scheme sees this. B (i.e. X) starts by taking the ko at B4. W replies by taking the ko at A1. The board looks like this:

 
 8 . . . . . . . .
 7 . . O . . . . .
 6 . . O . . . . .
 5 O O O . . . . .
 4 O X O O . . . .
 3 X . X O O O O .
 2 O X X X O . . .
 1 . O . . . . . .
   A B C D E F G H

Now any move except the ko recapture (currently illegal) at A1 loses for B, so B retakes the ko and becomes komaster. The board looks like this:

 
 8 . . . . . . . .         komaster: BLACK
 7 . . O . . . . .         kom_pos: A2
 6 . . O . . . . .
 5 O O O . . . . .
 4 O X O O . . . .
 3 X . X O O O O .
 2 . X X X O . . .
 1 X O . . . . . .
   A B C D E F G H

W takes the ko at B3 after which the komaster is GRAY and ko recaptures are not allowed.

 
 8 . . . . . . . .         komaster: GRAY
 7 . . O . . . . .         kom_pos: B4
 6 . . O . . . . .
 5 O O O . . . . .
 4 O . O O . . . .
 3 X O X O O O O .
 2 . X X X O . . .
 1 X O . . . . . .
   A B C D E F G H

Since B is not allowed any ko recaptures, there is nothing he can do and he is found dead. Thus the komaster scheme produces the correct result.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.6 Another Ko Example

We now consider an example to show why the komaster is reset to EMPTY if the ko is resolved in the komaster's favor. This means that the ko is filled, or else that is becomes no longer a ko and it is illegal for the komaster's opponent to play there.

The position resulting under consideration is in the file `regressions/games/ko5.sgf'. This is the position:

 
 . . . . . . O O 8
 X X X . . . O . 7
 X . X X . . O . 6
 . X . X X X O O 5
 X X . X . X O X 4
 . O X O O O X . 3
 O O X O . O X X 2
 . O . X O X X . 1
 F G H J K L M N

We recommend studying this example by examining the variation file produced by the command:

 
gnugo -l ko5.sgf --quiet --decide-string L1 -o vars.sgf

The correct resolution is that H1 attacks L1 unconditionally while K2 defends it with ko (code KO_A).

After Black (X) takes the ko at K3, white can do nothing but retake the ko conditionally, becoming komaster. B cannot do much, but in one variation he plays at K4 and W takes at H1. The following position results:

 
 . . . . . . O O 8
 X X X . . . O . 7
 X . X X . . O . 6
 . X . X X X O O 5
 X X . X X X O X 4
 . O X O O O X . 3
 O O X O . O X X 2
 . O O . O X X . 1
 F G H J K L M N

Now it is important the `O' is no longer komaster. Were `O' still komaster, he could capture the ko at N3 and there would be no way to finish off B.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.7 Alternate Komaster Schemes

The following alternate schemes have been proposed. It is assumed that `O' is the player about to move.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.7.1 Essentially the 2.7.232 scheme.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.7.2 Revised 2.7.232 version


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.8 Superstrings

A superstring is an extended string, where the extensions are through the following kinds of connections:

  1. Solid connections (just like ordinary string).
     
      OO
    
  2. Diagonal connection or one space jump through an intersection where an opponent move would be suicide or self-atari.
     
      ...
      O.O
      XOX
      X.X
    
  3. Bamboo joint.
     
      OO
      ..
      OO
    
  4. Diagonal connection where both adjacent intersections are empty.
     
      .O
      O.
    
  5. Connection through adjacent or diagonal tactically captured stones. Connections of this type are omitted when the superstring code is called from `reading.c', but included when the superstring code is called from `owl.c'.

Like a dragon, a superstring is an amalgamation of strings, but it is a much tighter organization of stones than a dragon, and its purpose is different. Superstrings are encountered already in the tactical reading because sometimes attacking or defending an element of the superstring is the best way to attack or defend a string. This is in contrast with dragons, which are ignored during tactical reading.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.9 Debugging the reading code

The reading code searches for a path through the move tree to determine whether a string can be captured. We have a tool for investigating this with the `--decidestring' option. This may be run with or without an output file.

Simply running

 
gnugo -t -l [input file name] -L [movenumber] --decidestring [location]

will run attack() to determine whether the string can be captured. If it can, it will also run find_defense() to determine whether or not it can be defended. It will give a count of the number of variations read. The `-t' is necessary, or else GNU Go will not report its findings.

If we add `-o output file' GNU Go will produce an output file with all variations considered. The variations are numbered in comments.

This file of variations is not very useful without a way of navigating the source code. This is provided with the GDB source file, listed at the end. You can source this from GDB, or just make it your GDB init file.

If you are using GDB to debug GNU Go you may find it less confusing to compile without optimization. The optimization sometimes changes the order in which program steps are executed. For example, to compile `reading.c' without optimization, edit `engine/Makefile' to remove the string -O2 from the file, touch `engine/reading.c' and make. Note that the Makefile is automatically generated and may get overwritten later.

If in the course of reading you need to analyze a result where a function gets its value by returning a cached position from the hashing code, rerun the example with the hashing turned off by the command line option `--hash 0'. You should get the same result. (If you do not, please send us a bug report.) Don't run `--hash 0' unless you have a good reason to, since it increases the number of variations.

With the source file given at the end of this document loaded, we can now navigate the variations. It is a good idea to use cgoban with a small `-fontHeight', so that the variation window takes in a big picture. (You can resize the board.)

Suppose after perusing this file, we find that variation 17 is interesting and we would like to find out exactly what is going on here.

The macro 'jt n' will jump to the n-th variation.

 
(gdb) set args -l [filename] -L [move number] --decidestring [location]
(gdb) tbreak main
(gdb) run
(gdb) jt 17

will then jump to the location in question.

Actually the attack variations and defense variations are numbered separately. (But find_defense() is only run if attack() succeeds, so the defense variations may or may not exist.) It is redundant to have to tbreak main each time. So there are two macros avar and dvar.

 
(gdb) avar 17

restarts the program, and jumps to the 17-th attack variation.

 
(gdb) dvar 17

jumps to the 17-th defense variation. Both variation sets are found in the same sgf file, though they are numbered separately.

Other commands defined in this file:

 

dump will print the move stack.
nv moves to the next variation
ascii i j converts (i,j) to ascii

#######################################################
###############      .gdbinit file      ###############
#######################################################

# this command displays the stack

define dump
set dump_stack()
end

# display the name of the move in ascii

define ascii
set gprintf("%o%m\n",$arg0,$arg1)
end

# display the all information about a dragon

define dragon
set ascii_report_dragon("$arg0")
end

define worm
set ascii_report_worm("$arg0")
end

# move to the next variation

define nv
tbreak trymove
continue
finish
next
end

# move forward to a particular variation

define jt
while (count_variations < $arg0)
nv
end
nv
dump
end

# restart, jump to a particular attack variation

define avar
delete
tbreak sgffile_decidestring
run
tbreak attack
continue
jt $arg0
end

# restart, jump to a particular defense variation

define dvar
delete
tbreak sgffile_decidestring
run
tbreak attack
continue
finish
next 3
jt $arg0
end


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.10 Connection Reading

GNU Go does reading to determine if strings can be connected. The algorithms for this are in `readconnect.c'. As with the reading code, the connection code is not pattern based.

The connection code is invoked by the engine through the functions:

To see the connection code in action, you may try the following example.

 
gnugo --quiet -l connection3.sgf --decide-connection M3/N7 -o vars.sgf

(The file `connection3.sgf' is in `regression/games'.) Examine the sgf file produced by this to see what kind of reading is done by the functions string_connect() and string_disconnect(), which are called by the function decide_connection.

One use of the connection code is used is through the autohelper macros oplay_connect, xplay_connect, oplay_disconnect and xplay_disconnect which are used in the connection databases.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12. Pattern Based Reading

In the tactical reading code in `reading.c', the code generating the moves which are tried are all hand coded in C, for efficiency. There is much to be said for another type of reading, in which the moves to be tried are generated from a pattern database.

GNU Go does three main types of pattern based reading. First, there is the OWL code (Optics with Limit Negotiation) which attempts to read out to a point where the code in `engine/optics.c' (see section 8. Eyes and Half Eyes) can be used to evaluate it. Like the tactical reading code, a persistent cache is employed to maintain some of the owl data from move to move. This is an essential speedup without which GNU Go would play too slowly.

Secondly, there is the `engine/combination.c' which attempts to find combinations--situations where a series of threats eventually culminates in one that cannot be parried.

Finally there is the semeai module. A semeai is a capturing race between two adjacent DEAD or CRITICAL dragons of opposite colors. The principal function, owl_analyze_semeai() is contained in `owl.c'. Due to the complex nature of semeais, the results of this function are more frequently wrong than the usual owl code.

12.1 The Owl Code  Life and death reading
12.2 Combination reading  Combinations


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.1 The Owl Code

The life and death code in `optics.c', described elsewhere (see section 8. Eyes and Half Eyes), works reasonably well as long as the position is in a terminal position, which we define to be one where there are no moves left which can expand the eye space, or limit it. In situations where the dragon is surrounded, yet has room to thrash around a bit making eyes, a simple application of the graph-based analysis will not work. Instead, a bit of reading is needed to reach a terminal position.

The defender tries to expand his eyespace, the attacker to limit it, and when neither finds an effective move, the position is evaluated. We call this type of life and death reading Optics With Limit-negotiation (OWL). The module which implements it is in `engine/owl.c'.

There are two reasonably small databases `patterns/owl_defendpats.db' and `patterns/owl_attackpats.db' of expanding and limiting moves. The code in `owl.c' generates a small move tree, allowing the attacker only moves from `owl_attackpats.db', and the defender only moves from `owl_defendpats.db'. In addition to the moves suggested by patterns, vital moves from the eye space analysis are also tested.

A third database, `owl_vital_apats.db' includes patterns which override the eyespace analysis done by the optics code. Since the eyeshape graphs ignore the complications of shortage of liberties and cutting points in the surrounding chains, the static analysis of eyespace is sometimes wrong. The problem is when the optics code says that a dragon definitely has 2 eyes, but it isn't true due to shortage of liberties, so the ordinary owl patterns never get into play. In such situations `owl_vital_apats.db' is the only available measure to correct mistakes by the optics. Currently the patterns in `owl_vital_apats.db' are only matched when the level is 9 or greater.

The owl code is tuned by editing these three pattern databases, principally the first two.

A node of the move tree is considered terminal if no further moves are found from `owl_attackpats.db' or `owl_defendpats.db', or if the function compute_eyes_pessimistic() reports that the group is definitely alive. At this point, the status of the group is evaluated. The functions owl_attack() and owl_defend(), with usage similar to attack() and find_defense(), make use of the owl pattern databases to generate the move tree and decide the status of the group.

The function compute_eyes_pessimistic() used by the owl code is very conservative and only feels certain about eyes if the eyespace is completely closed (i.e. no marginal vertices).

The maximum number of moves tried at each node is limited by the parameter MAX_MOVES defined at the beginning of `engine/owl.c'. The most most valuable moves are tried first, with the following restrictions:

The functions owl_attack() and owl_defend() may, like attack() and find_defense(), return an attacking or defending move through their pointer arguments. If the position is already won, owl_attack() may or may not return an attacking move. If it finds no move of interest, it will return PASS, that is, 0. The same goes for owl_defend().

When owl_attack() or owl_defend() is called, the dragon under attack is marked in the array goal. The stones of the dragon originally on the board are marked with goal=1; those added by owl_defend() are marked with goal=2. If all the original strings of the original dragon are captured, owl_attack() considers the dragon to be defeated, even if some stones added later can make a live group.

Only dragons with small escape route are studied when the functions are called from make_dragons().

The owl code can be conveniently tested using the `--decide-owl location' option. This should be used with `-t' to produce a useful trace, `-o' to produce an SGF file of variations produced when the life and death of the dragon at location is checked, or both. `--decide-position' performs the same analysis for all dragons with small escape route.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.2 Combination reading

It may happen that no single one of a set of worms can be killed, yet there is a move that guarantees that at least one can be captured. The simplest example is a double atari. The purpose of the code in `combination.c' is to find such moves.

For example, consider the following situation:

 
+---------
|....OOOOX
|....OOXXX
|..O.OXX..
|.OXO.OX..
|.OX..OO..
|.XXOOOXO.
|..*XXOX..
|....XOX..
|.XX..X...
|X........

Every `X' stone in this position is alive. However the move at `*' produces a position in which at least one of four strings will get captured. This is a combination.

The driving function is called atari_atari because typically a combination involves a sequence of ataris culminating in a capture, though sometimes the moves involved are not ataris. For example in the above example, the first move at `*' is not an atari, though after `O' defends the four stones above, a sequence of ataris ensues resulting in the capture of some string.

Like the owl functions atari_atari does pattern-based reading. The database generating the attacking moves is `aa_attackpats.db'. One danger with this function is that the first atari tried might be irrelevant to the actual combination. To detect this possibility, once we've found a combination, we mark that first move as forbidden, then try again. If no combination of the same size or larger turns up, then the first move was indeed essential.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13. Influence Function

13.1 Conceptual Outline of Influence  
13.2 Territory, Moyo and Area  
13.3 Where influence gets used in the engine  
13.4 Influence and Territory  
13.5 Details of the Territory Valuation  
13.6 The Core of the Influence Function  
13.7 The Influence Algorithm  The algorithm of accumlate_influence()
13.8 Permeability  
13.9 Escape  
13.10 Break Ins  
13.11 Surrounded Dragons  
13.12 Patterns used by the Influence module  
13.13 Colored display and debugging of influence  
13.14 Influence Tuning with view.pike  Influence tuning with view.pike


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.1 Conceptual Outline of Influence

We define call stones lively if they cannot be tactically attacked, or if they have a tactical defense and belong to the player whose turn it is. Similarly, stones that cannot be strategically attacked (in the sense of the life-and-death analysis), or that have a strategical defense and belong to the player to move, are called alive. If we want to use the influence function before deciding the strategical status, all lively stones count as alive.

Every alive stone on the board works as an influence source, with influence of its color radiating outwards in all directions. The strength of the influence declines exponentially with the distance from the source.

Influence can only flow unhindered if the board is empty, however. All lively stones (regardless of color) act as influence barriers, as do connections between enemy stones that can't be broken through. For example the one space jump counts as a barrier unless either of the stones can be captured. Notice that it doesn't matter much if the connection between the two stones can be broken, since in that case there would come influence from both directions anyway.

From the influence of both colors we compute a territorial value between -1.0 and +1.0 for each intersection, which can be seen as the likely hood of it becoming territory for either color.

In order to avoid finding bogus territory, we add extra influence sources at places where an invasion can be launched, e.g. at 3-3 under a handicap stone, in the middle of wide edge extensions and in the center of large open spaces anywhere. Similarly we add extra influence sources where intrusions can be made into what otherwise looks as solid territory, e.g. monkey jumps. These intrusions depend on whose turn we assume it to be.

All these extra influence sources, as well as connections, are controlled by a pattern database, which consists of the two files patterns/influence.db and patterns/barriers.db. The details are explained in 13.12 Patterns used by the Influence module.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.2 Territory, Moyo and Area

Using the influence code, empty regions of the board are partitioned in three ways. A vertex may be described as White or Black's territory, moyo or area. The functions whose_territory(), whose_moyo() and whose_area() will return a color, or EMPTY if it belongs to one player or the other in one of these classifications.

Generally territory is moyo and moyo is area. To get a feeling for these concepts, load an sgf file in a middle game position with the option `-m 0x0180' and examine the resulting diagrams (see section 13.13 Colored display and debugging of influence).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.3 Where influence gets used in the engine

The information obtained from the influence computation is used in a variety of places in the engine, and the influence module is called several times in the process of the move generation. The details of the influence computation vary according to the needs of the calling function.

After GNU Go has decided about the tactical stability of strings, the influence module gets called the first time. Here all lively stones act as an influence source of default strength 100. The result is stored in the variables initial_influence and initial_opposite_influence, and it is used as an important information for guessing the strength of dragons. For example, a dragon that is part of a moyo of size 25 is immediately considered alive. For dragons with a smaller moyo size, a life-and-death analysis will be done by the owl code (see 12. Pattern Based Reading). A dragon with a moyo size of only 5 will be considered weak, even if the owl code has decided that it cannot be killed.

As a tool for both the owl code and the strength estimate of dragons, an "escape" influence gets computed for each dragon (see section 13.9 Escape).

Once all dragons have been evaluated, the influence module is called again and the variables initial_influence and initial_opposite_influence get overwritten. Of course, the dragon status', which are available now, are taken into account. Stones belonging to a dead dragon will not serve as an influence source, and the strengths of other stones get adjusted according to the strength of their respective dragon.

The result of this run is the most important tool for move evaluation. All helper functions of patterns as explained in 9. The Pattern Code that refer to influence results (e. g. olib(*) etc.) actually use these results. Further, initial_influence serves as the reference for computing the territorial value of a move. That is, from the influence strengths stored in initial_influence, a territory value is assigned to each intersection. This value is supposed to estimate the likelyhood that this intersection will become white or black territory.

Then, for each move that gets considered in the function value_moves, the influence module is called again via the function compute_move_influence to assess the likely territorial balance after this move, and the result is compared with the state before that move.

An additional influence computation is done in order to compute the followup value of a move. Some explainations are in 13.5 Details of the Territory Valuation.

Some of the public functions from `influence.c' which are used throughout the engine are listed in 18.4 Utilities from `engine/influence.c'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.4 Influence and Territory

In this section we consider how the influence function is used to estimate territory in the function estimate_territorial_value().

A move like `*' by `O' below is worth one point:

 
OXXX.
OX.XX
O*a.X
OX.XX
OXXX.

This is evaluated by the influence function in the following way: We first assign territory under the assumption that X moves first in all local positions in the original position; then we reassing territory, again under the assumption that `X' moves first in all local positions, but after we let `O' make the move at `*'. These two territory assignments are compared and the difference gives the territorial value of the move.

Technically, the assumption that `X' plays first everywhere is implemented via an asymmetric pattern database in barriers.db. What exactly is a safe connection that stops hostile influence from passing through is different for `O' and `X'; of course such a connection has to be tighter for stones with color `O'. Also, additional intrusion influence sources are added for `X' in places where `X' stones have natural followup moves.

In this specific example above, the asymmetry (before any move has been made) would turn out as follows: If `X' is in turn to move, the white influence would get stopped by a barrier at `*', leaving 4 points of territory for `X'. However, if `O' was next to move, then a followup move for the white stones at the left would be assumed in the form of an extra ("intrusion") influence source at `*'. This would get stopped at `a', leaving three points of territory.

Returning to the valuation of a move by `O' at `*', we get a value of 1 for the move at `*'. However, of course this move is sente once it is worth playing, and should therefore (in miai counting) be awarded an effective value of 2. Hence we need to recognize the followup value of a move. GNU Go 3.0 took care of this by using patterns in patterns.db that enforced an explicit followup value. Versions from 3.2 on instead compute a seperate followup influence to each move considered. In the above example, an intrusion source will be added at `a' as a followup move to `*'. This destroys all of Black's territory and hence gives a followup value of 3.

The pattern based followup value are still needed at some places, however.

To give another example, consider this position where we want to estimate the value of an `O' move at `*':

 
OOOXXX
..OX..
..OX..
...*..
------

Before the move we assume `X' moves first in the local position (and that `O' has to connect), which gives territory like this (lower case letter identify territory for each player):

 
OOOXXX
ooOXxx
o.OXxx
o...xx
------

Then we let `O' make the move at `*' and assume `X' moves first again next. The territory then becomes (`X' is also assumed to have to connect):

 
OOOXXX
ooOXxx
ooOX.x
oo.O.x
------

We see that this makes a difference in territory of 4, which is what influence_delta_territory() should report. Then again, we have followup value, and here also a reverse followup value. The reverse followup value, which in this case will be so high that the move is treated as reverse sente, is added by an explicit pattern. Other sources for followup or reverse followup values are threats to capture a rescue a string of stones. See the code and comments in the function value_move_reaons for how followup and reverse followup values are used to adjust the effective move value.

To give an example of territorial value where something is captured, consider the `O' move at `*' here,

 
XXXXXXXO
X.OOOOXO
X.O..O*O
--------

As before we first let the influence function determine territory assuming X moves first, i.e. with a captured group:

 
XXXXXXXO
XxyyyyXO
Xxyxxy.O
--------

Here `y' indicates `X' territory + captured stone, i.e. these count for two points. After the `O' move at `*' we instead get

 
XXXXXXXO
X.OOOOXO
X.OooOOO
--------

and we see that `X' has 16 territory fewer and `O' has two territory more, for a total difference of 18 points.

That the influence function counts the value of captured stones was introduced in GNU Go 3.2. Previously this was instead done using the effective_size heuristic. The effective size is the number of stones plus the surrounding empty spaces which are closer to this string or dragon than to any other stones. Here the `O' string would thus have effective size 6 (number of stones) + 2 (interior eye) + 2*0.5 (the two empty vertices to the left of the string, split half each with the surrounding X string) + 1*0.33 (the connection point, split between three strings) = 9.33. As noted this value was doubled, giving 18.67 which is reasonably close to the correct value of 18. The effective size heuristic is still used in certain parts of the move valuation where we can't easily get a more accurate value from the influence function (e. g. attacks depending on a ko, attack threats).

Note that this section only describes the territorial valuation of a move. Apart from that, GNU Go uses various heuristics in assigning a strategical value (weakening and strengthening of other stones on the board) to a move. Also, the influence function isn't quite as well tuned as the examples above may seem to claim. But it should give a fairly good idea of how the design is intended.

Another matter is that so far we have only considered the change in secure territory. GNU Go 3.2 and later versions use a revised heuristic, which is explained in the next section, to assign probable territory to each player.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.5 Details of the Territory Valuation

This section explains how GNU Go assigns a territorial value to an intersection once the white and black influence have been computed. The intention is that an intersection that has a chance of xx% of becoming white territory is counted as 0.xx points of territory for white, and similar for black.

The algorithm in the function new_value_territory goes roughly as follows:

If wi is the white influence at a point, and bi the black influence, then value = ( (wi-bi)/ (wi+bi) )^3 (positive values indicates likley white territory, negative stand for black territory) turns out to be very simple first guess that is still far off, but reasonable enough to be useful.

This value is then suspect a number of corrections. Assume that this first guess resulted in a positive value.

If both bi and wi are small, it gets reduced. What exactly is "small" depends on whether the intersection is close to a corner or an edge of the board, since it is easier to claim territory in the corner than in the center.

Then the value at each intersection is degraded to the minimum value of its neighbors. This can be seen as a second implementation of the proverb saying that there is no territory in the center of the board. This step substantially reduces the size of spheres of territory that are open at several sides.

Finally, there are a number of patterns that explicitly forbid GNU Go to count territory at some intersections. This is used e. g. for false eyes that will eventually have to be filled in. Also, points for prisoners are added.

To fine tune this scheme, some revisions have been made to the influence computations that are relevant for territorial evaluation. This includes a reduced default attenuation and some revised pattern handling.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.6 The Core of the Influence Function

The basic influence radiation process can efficiently be implemented as a breadth first search for adjacent and more distant points, using a queue structure.

Influence barriers can be found by pattern matching, assisted by reading through constraints and/or helpers. Wall structures, invasion points and intrusion points can be found by pattern matching as well.

When influence is computed, the basic idea is that there are a number of influence sources on the board, whose contributions are summed to produce the influence values. For the time being we can assume that the living stones on the board are the influence sources, although this is not the whole story.

The function compute_influence() contains a loop over the board, and for each influence source on the board, the function accumulate_influence() is called. This is the core of the influence function. Before we get into the details, this is how the influence field from a single isolated influence source of strength 100 turns out (with an attenuation of 3.0):

 
  0  0  0  0  0  0  0  0  0  0  0
  0  0  0  0  1  1  1  0  0  0  0
  0  0  0  1  2  3  2  1  0  0  0
  0  0  1  3  5 11  5  3  1  0  0
  0  1  2  5 16 33 16  5  2  1  0
  0  1  3 11 33  X 33 11  3  1  0
  0  1  2  5 16 33 16  5  2  1  0
  0  0  1  3  5 11  5  3  1  0  0
  0  0  0  1  2  3  2  1  0  0  0
  0  0  0  0  1  1  1  0  0  0  0
  0  0  0  0  0  0  0  0  0  0  0

These values are in reality floating point numbers but have been rounded down to the nearest integer for presentation. This means that the influence field does not stop when the numbers become zeroes.

Internally accumulate_influence() starts at the influence source and spreads influence outwards by means of a breadth first propagation, implemented in the form of a queue. The order of propagation and the condition that influence only is spread outwards guarantee that no intersection is visited more than once and that the process terminates. In the example above, the intersections are visited in the following order:

 
  +  +  +  +  +  +  +  +  +  +  +
  + 78 68 66 64 63 65 67 69 79  +
  + 62 46 38 36 35 37 39 47 75  +
  + 60 34 22 16 15 17 23 43 73  +
  + 58 32 14  6  3  7 19 41 71  +
  + 56 30 12  2  0  4 18 40 70  +
  + 57 31 13  5  1  8 20 42 72  +
  + 59 33 21 10  9 11 24 44 74  +
  + 61 45 28 26 25 27 29 48 76  +
  + 77 54 52 50 49 51 53 55 80  +
  +  +  +  +  +  +  +  +  +  +  +

The visitation of intersections continues in the same way on the intersections marked '`+' and further outwards. In a real position there will be stones and tight connections stopping the influence from spreading to certain intersections. This will disrupt the diagram above, but the main property of the propagation still remains, i.e. no intersection is visited more than once and after being visited no more influence will be propagated to the intersection.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.7 The Influence Algorithm

Let (m, n) be the coordinates of the influence source and (i, j) the coordinates of a an intersection being visited during propagation, using the same notation as in the accumulate_influence() function. Influence is now propagated to its eight closest neighbors, including the diagonal ones, according to the follow scheme:

For each of the eight directions (di, dj), do:

  1. Compute the scalar product di*(i-m) + dj*(j-n) between the vectors (di,dj) and (i,j) - (m,n)
  2. If this is negative or zero, the direction is not outwards and we continue with the next direction. The exception is when we are visiting the influence source, i.e. the first intersection, when we spread influence in all directions anyway.
  3. If (i+di, j+dj) is outside the board or occupied we also continue with the next direction.
  4. Let S be the strength of the influence at (i, j). The influence propagated to (i+di, j+dj) from this intersection is given by P*(1/A)*D*S, where the three different kinds of damping are:

Influence is typically contributed from up to three neighbors "between" this intersection and the influence source. These values are simply added together. As pointed out before, all contributions will automatically have been made before the intersection itself is visited.

When the total influence for the whole board is computed by compute_influence(), accumulate_influence() is called once for each influence source. These invocations are totally independent and the influence contributions from the different sources are added together.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.8 Permeability

The permeability at the different points is initially one at all empty intersections and zero at occupied intersections. To get a useful influence function we need to modify this, however. Consider the following position:

 
|......
|OOOO..
|...O..
|...a.X   ('a' empty intersection)
|...O..
|...OOO
|.....O
+------

The corner is of course secure territory for `O' and clearly the `X' stone has negligible effect inside this position. To stop `X' influence from leaking into the corner we use pattern matching (pattern Barrier1/Barrier2 in `barriers.db') to modify the permeability for `X' at this intersection to zero. `O' can still spread influence through this connection.

Another case that needs to be mentioned is how the permeability damping is computed for diagonal influence radiation. For horizontal and vertical radiation we just use the permeability (for the relevant color) at the intersection we are radiating from. In the diagonal case we additionally multiply with the maximum permeability at the two intersections we are trying to squeeze between. The reason for this can be found in the diagram below:

 
|...X    |...X    
|OO..    |Oda.
|..O.    |.bc.
|..O.    |..O.
+----    +----

We don't want `X' influence to be spread from `a' to `b', and since the permeability at both c and d is zero, the rule above stops this.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.9 Escape

One application of the influence code is in computing the dragon.escape_route field. This is computed by the function compute_escape() as follows. First, every intersection is assigned an escape value, ranging between 0 and 4, depending on the influence value of the opposite color.

The escape_route field is modified by the code in `surround.c' (see section 13.11 Surrounded Dragons). It is divided by two for weakly surrounded dragons, and set to zero for surrounded ones.

In addition to assiging an escape value to empty vertices, we also assign an escape value to friendly dragons. This value can range from 0 to 6 depending on the status of the dragon, with live dragons having value 6.

Then we sum the values of the resulting influence escape values over the intersections (including friendly dragons) at distance 4, that is, over those intersections which can be joined to the dragon by a path of length 4 (and no shorter path) not passing adjacent to any unfriendly dragon. In the following example, we sum the influence escape value over the four vertices labelled '4'.

 
   
   . . . . . . . . .    . . . . . . . . .
   . . . . . X . . O    . . . . . X . . O
   . . X . . . . . O    . . X . 2 . 4 . O
   X . . . . . . . .    X . . 1 1 2 3 4 .
   X O . O . . . . O    X O 1 O 1 2 3 4 O
   X O . O . . . . .    X O 1 O 1 . 4 . .
   X O . . . X . O O    X O 1 . . X . . O
   . . . X . . . . .    . 1 . X . . . . .
   X . . . . X . . .    X . . . . X . . .
   . . . . . . . . .    . . . . . . . . .

Since the dragon is trying to reach safety, the reader might wonder why compute_influence() is called with the opposite color of the dragon contemplating escape. To explain this point, we first remind the reader why there is a color parameter to compute_influence(). Consider the following example position:

 
     ...XX...
     OOO..OOO
     O......O
     O......O
     --------

Whether the bottom will become O territory depends on who is in turn to play. This is implemented with the help of patterns in barriers.db, so that X influence is allowed to leak into the bottom if X is in turn to move but not if O is. There are also "invade" patterns which add influence sources in sufficiently open parts of the board which are handled differently depending on who is in turn to move.

In order to decide the territorial value of an O move in the third line gap above, influence is first computed in the original position with the opponent (i.e. X) in turn to move. Then the O stone is played to give:

 
     ...XX...
     OOO.OOOO
     O......O
     O......O
     --------

Now influence is computed once more, also this time with X in turn to move. The difference in territory (as computed from the influence values) gives the territorial value of the move.

Exactly how influence is computed for use in the escape route estimation is all ad hoc. But it makes sense to assume the opponent color in turn to move so that the escape possibilities aren't overestimated. After we have made a move in the escape direction it is after all the opponent's turn.

The current escape route mechanism seems good enough to be useful but is not completely reliable. Mostly it seems to err on the side of being too optimistic.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.10 Break Ins

The code in `breakin.c' break-ins into territories that require deeper tactical reading and are thus impossible to detect for the influence module. It gets run after the influence module and revises its territory valuations.

The break-in code makes use of two public functions in `readconnect.c',

These functions are public front ends to their counterparts recursive_break_in and recursive_block_off, which call each other recursively.

The procedure is as follows: We look at all big (>= 10) territory regions as detected by the influence code. Using the computation of connection distances from readconnect.c, we compute all nearby vertices of this territory. We look for the closest safe stones belonging to the opponent.

For each such string str we call

If the break in is successful resp. the blocking unsuccessful, we shrink the territory, and see whether the opponent can still break in. We repeat this until the territory is shrunk so much that the opponent can no longer reach it.

To see the break in code in action run GNU Go on the file `regression/games/break_in.sgf' with the option -d0x102000. Among the traces you will find:

 
  Trying to break in from D7 to:
E9 (1)  F9 (1)  G9 (1)  E8 (1)  F8 (1)  G8 (1)  
H8 (1)  G7 (1)  H7 (1)  J7 (1)  H6 (1)  J6 (1)
H5 (1)  J5 (1)  H4 (1)  J4 (1)  H3 (1)  J3 (1)
H2 (1)  J2 (1)    
block_off D7, result 0 PASS (355, 41952 nodes, 0.73 seconds)
E9 (1)  F9 (1)  G9 (1)  E8 (1)  F8 (1)  G8 (1)
H8 (1)  G7 (1)  H7 (1)  J7 (1)  H6 (1)  J6 (1)
H5 (1)  J5 (1)  H4 (1)  J4 (1)  H3 (1)  J3 (1)
H2 (1)  J2 (1)    
B:F4 
  Erasing territory at E8 -b.
  Erasing territory at G3 -b.
  Now trying to break to smaller goal:
F9 (1)  G9 (1)  F8 (1)  G8 (1)  H8 (1)  G7 (1)
H7 (1)  J7 (1)  H6 (1)  J6 (1)  H5 (1)  J5 (1)
H4 (1)  J4 (1)  H3 (1)  J3 (1)  H2 (1)  J2 (1)    

This means that the function break_in is called with the goal marked 'a' in the following diagram. The code attempts to find out whether it is possible to connect into this area from the string at D7.

 
   A B C D E F G H J
 9 . . . . a a a . . 9
 8 . . . . a a a a . 8
 7 . . . X O O a a a 7
 6 . . . X X X O a a 6
 5 . . . . + . . a a 5
 4 . . . X . . O a a 4
 3 . . . . X . . a a 3
 2 . . . . . . O a a 2
 1 . . . . . . . . . 1
   A B C D E F G H J

A breakin is found, so the goal is shrunk by removing E9 and J2, then break_in is called again.

In order to see what reading is actually done in order to do this break in, you may load GNU Go in gtp mode, then issue the commands:

 
loadsgf break_in.sgf 
= black

start_sgftrace
= 

break_in D7 E9 F9 G9 E8 F8 G8 H8 G7 H7 J7 H6 J6 H5 J5 H4 J4 H3 J3 H2 J2
= 1 E8

finish_sgftrace vars.sgf
= 

start_sgftrace
= 

break_in D7 F9 G9 F8 G8 H8 G7 H7 J7 H6 J6 H5 J5 H4 J4 H3 J3 H2 J2
= 1 G7

finish_sgftrace vars1.sgf

This will produce two sgf files containing the variations caused by these calls to the breakin code. The second file, `vars1.sgf' will contain quite a few variations.

The break in code makes a list of break ins which are found. When it is finished, the function add_expand_territory_move is called for each break in, adding a move reason.

The break in code is slow, and only changes a few moves by the engine per game. Nevertheless we believe that it contributes substantially to the strength of the program. The break in code is enabled by default in GNU Go 3.6 at level 10, and disabled at level 9. In fact, this is the only difference between levels 9 and 10 in GNU Go 3.6.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.11 Surrounded Dragons

When is a dragon surrounded?

As has been pointed out by Bruce Wilcox, the geometric lines connecting groups of the opposite color are often important. It is very hard to prevent the escape of this `O' dragon:

 
..........
.....O....
.X.......X
.X...O...X
..........
..........
----------

On the other hand, this dragon is in grave danger:

 
..........
..........
.X.......X
.....O....
.X.......X
.X...O...X
..........
..........
----------

The difference between these two positions is that in the first, the `O' dragon crosses the line connecting the top two `X' stones.

Code in `surround.c' implements a test for when a dragon is surrounded. The idea is to compute the convex hull of the surround set, that is, the set stones belonging to unfriendly neighbor dragons. If the dragon is contained within that hull. If it is, it is said to be surrounded.

In practice this scheme is modified slightly. The implementation uses various algorithms to compute distances and hostile stones are discarded from the surround set when a pair other hostile ones can be found which makes the considered one useless. For example, in the following position the bottom `O' stone would get discarded.

 
O.X.O  
.....
.O.O.
.....
..O..

Also, points are added to the surround set below stones on the second and third lines. This should account for the edge being a natural barrier.

In order to compute distances between corners of the convex hull a sorting by angle algorithm has been implemented. If the distance between a pair enclosing stones is large, the surround status gets decreased to WEAKLY_SURROUNDED, or even 0 for very large ones.

The sorting by angle must be explained. A small diagram will probably help :

 
.O.O.
O...O
..X..
O...O
.O.O.

The sorting algorithm will generate this:

 
.4.5.
3...6
..X..
2...7
.1.8.

That is, the points are sorted by ascending order of the measure of the angle S-G-O, where S is SOUTH, G the (approximated) gravity center of the goal, and O the position of the considered hostile stones.

The necessity of such sorting appears when one tries to measure distances between enclosing stones without sorting them, just by using directly the existing left and right corners arrays. In some positions, the results will be inconsistent. Imagine, for example a position where for instance the points 1,2,3,4,6 and 7 were in the left arrary, leaving only 5 and 8 in the right array. Because of the large distance between 5 and 8, the dragon would have declared weak surrounded or not surrounded at all. Such cases are rare but frequent enough to require the angle sorting.

The following position:

 
O.X.O
.....
.O.O.

This is "more" surrounded than the following position:

 
O.XXXXXX.O
..........
.O......O.

In the second case, the surround status would be lowered to WEAKLY_SURROUNDED.

The surround code is used to modify the escape_route field in the dragon2 data array. When a dragon is WEAKLY_SURROUNDED, the escape_route is divided by 2. If the dragon is SURROUNDED, escape_route is simply set to 0.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.12 Patterns used by the Influence module

This section explains the details of the pattern databases used for the influence computation.

First, we have the patterns in `influence.db', which get matched symmetrically for both colors.

The patterns in `barriers.db' get matched only for `O' being the player next to move.

The intrusion patterns (`B') are more powerful than the description above might suggest. They can be very helpful in identifying weak shapes (by adding an intrusion source for the opponent where he can break through). A negative inference for this is that a single bad `B' pattern, e. g. one that has a wrong constraint, typically causes 5 to 10 FAILs in the regression test suite.

Influence Patterns can have autohelper constraints as usual. As for the constraint attributes, there are (additionally to the usual ones `O', `o', `X' and `x'), attributes `Y' and `FY'. A pattern marked with `Y' will only be used in the influence computations relevant for the territory valuation, while `FY' patterns only get used in the other influence computations.

The action of an influence pattern is at the moment only used for non-territory patterns as mentioned above, and as a workaround for a problem with `B' patterns in the followup influence.

To see why this workaround is necessary, consider the follwoing situation:

 
..XXX
.a*.O
.X.O.
..XXO

(Imagine that there is `X' territory on the left.)

The move by `O' at `*' has a natural followup move at `a'. So, in the computation of the followup influence for `*', there would be an extra influence source for `O' at `a' which would destroy a lot of black territory on the left. This would give a big followup value, and in effect the move `*' would be treated as sente.

But of course it is gote, since `X' will answer at `a', which both stops the possible intrusion and threatens to capture `*'. This situation is in fact quite common.

Hence we need an additional constraint that can tell when an intrusion pattern can be used in followup influence. This is done by misusing the action line: An additional line

 
>return <condition>;

gets added to the pattern. The condition should be true if the intrusion cannot be stopped in sente. In the above example, the relevant intrusion pattern will have an action line of the form

 
>return (!xplay_attack(a,b));

where `b' refers to the stone at `*'. In fact, almost all followup-specific constraints look similar to this.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.13 Colored display and debugging of influence

There are various ways to obtain detailed information about the influence computations. Colored diagrams showing influence are possible from a colored xterm or rxvt window.

There are two options controlling when to generate diagrams:

The other options control which diagrams should be generated in these situations. You have to specify at least one of the options above and at least one of the options below to generate any output.

The options below must be combined with one of the two previous ones, or the diagram will not be printed. For example to print the influence diagram, you may combine 0x08 and 0x010, and use the option `-m 0x018'.

Finally, there is the debug option `-d 0x1' which turns on on DEBUG_INFLUENCE. This gives a message for each influence pattern that gets matched. Unfortunately, these are way too many messages making it tedious to navigate the output. However, if you discover an influence source with `-m 0x80' that looks wrong, the debug output can help you to quickly find out the responsible pattern.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

13.14 Influence Tuning with view.pike

A useful program in the regression directory is view.pike. To run it, you need Pike, which you may download from http://pike.ida.liu.se/.

The test case `endgame:920' fails in GNU Go 3.6. We will explain how to fix it.

Start by firing up view.pike on testcase endgame:920, e.g. by running pike view.pike endgame:920 in the regression directory.

We see from the first view of move values that filling dame at P15 is valued highest with 0.17 points while the correct move at C4 is valued slightly lower with 0.16. The real problem is of course that C4 is worth a full point and thus should be valued about 1.0.

Now click on C4 to get a list of move reasons and move valuation information. Everything looks okay except that change in territory is 0.00 rather than 1.00 as it ought to be.

We can confirm this by choosing the "delta territory for..." button and again clicking C4. Now B5 should have been marked as one point of change in territory, but it's not.

Next step is to enter the influence debug tool. Press the "influence" button, followed by "black influence, dragons known," and "territory value." This shows the expected territory if black locally moves first everywhere (thus "black influence"). Here we can see that B5 is incorrectly considered as 1.0 points of white territory.

We can compare this with the territory after a white move at C4 (still assuming that black locally moves first everywhere after that) by pressing "after move influence for..." and clicking C4. This looks identical, as expected since delta territory was 0, but here it is correct that B5 is 1.0 points of territory for white.

The most straightforward solution to this problem is to add a non-territory pattern, saying that white can't get territory on B5 if black moves first. The nonterritory patterns are in `barriers.db'.

 
Pattern Nonterritory56

...
X.O
?O.

:8,t

eac
XbO
?Od

;oplay_attack(a,b,c,d,d)

>non_xterritory(e);

In these patterns it's always assumed that `O' moves first and thus it says that `X' can't get territory at B5 (`e' in the pattern). Now we need to be a bit careful however since after `O' plays at `a' and `X' cuts in at `b', it may well happen that `O' needs to defend around `d', allowing `X' to cut at `c', possibly making the nonterritory assumption invalid. It's difficult to do this entirely accurate, but the constraint above is fairly conservative and should guarantee that `a' is safe in most, although not all, cases.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14. Another approach to Moyos : Bouzy's 5/21 algorithm

14.1 Moyo history  History of `moyo.c' and `score.c'
14.2 Bouzy's 5/21 algorithm  Bouzy's algorithm

The file `score.c' contains alternative algorithms for the computation of Territory and Moyos. These algorithms are used in estimate_score() but apart from that are generally not used in the rest of the engine since the concepts of Territory, Moyo and Area were reimplemented using the influence code (see section 13.2 Territory, Moyo and Area). The function estimate_score(), which is the only way this code is used in the engine, could easily be replaced with a function such as influence_score() based on the influence code.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14.1 Moyo history

In GNU Go 2.6 extensive use was made of an algorithm from Bruno Bouzy's dissertation, which is available at: ftp://www.joy.ne.jp/welcome/igs/Go/computer/bbthese.ps.Z This algorithm starts with the characteristic function of the live groups on the board and performs `n' operations called dilations, then `m' operations called erosions. If n=5 and m=21 this is called the 5/21 algorithm.

The Bouzy 5/21 algorithm is interesting in that it corresponds reasonably well to the human concept of territory. This algorithm is still used in GNU Go 3.6 in the function estimate_score. Thus we associate the 5/21 algorithm with the word territory. Similarly we use words moyo and area in reference to the 5/10 and 4/0 algorithms, respectively.

The principle defect of the algorithm is that it is not tunable. The current method of estimating moyos and territory is in `influence.c' (see section 13. Influence Function). The territory, moyo and area concepts have been reimplemented using the influence code.

The Bouzy algorithm is briefly reimplemented in the file `scoring.c' and is used by GNU Go 3.6 in estimating the score.

Not all features of the old `moyo.c' from GNU Go 2.6 were reimplemented--particularly the deltas were not--but the reimplementation may be more readable.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14.2 Bouzy's 5/21 algorithm

Bouzy's algorithm was inspired by prior work of Zobrist and ideas from computer vision for determining territory. This algorithm is based on two simple operations, DILATION and EROSION. Applying dilation 5 times and erosion 21 times determines the territory.

To get a feeling for the algorithm, take a position in the early middle game and try the colored display using the `-m 1' option in an RXVT window. The regions considered territory by this algorithm tend to coincide with the judgement of a strong human player.

Before running the algorithm, dead stones (dragon.status==0) must be "removed."

Referring to page 86 of Bouzy's thesis, we start with a function taking a high value (ex : +128 for black, -128 for white) on stones on the goban, 0 to empty intersections. We may iterate the following operations:

dilation: for each intersection of the goban, if the intersection is >= 0, and not adjacent to a < 0 one, then add to the intersection the number of adjacent >0 intersections. The same for other color : if the intersection is <= 0, and not adjacent to a > 0 one, then subtract the number of < 0 intersections.

erosion: for each intersection > 0 (or < 0), subtract (or add) the number of adjacent <= 0 (or >= 0) intersection. Stop at zero. The algorithm is just : 5 dilations, then 21 erosions. The number of erosions should be 1+n(n-1) where n=number of dilation, since this permit to have an isolated stone to give no territory. Thus the couple 4/13 also works, but it is often not good, for example when there is territory on the 6th line.

For example, let us start with a tobi.

 
           128    0    128   

1 dilation :

 
            1          1 

       1   128    2   128   1

            1          1

2 dilations :

 
            1          1

       2    2     3    2    2

   1   2   132    4   132   2   1

       2    2     3    2    2
              
            1          1

3 dilations :

 
            1          1

       2    2     3    2    2
     
   2   4    6     6    6    4   2

1  2   6   136    8   136   6   2   1

   2   4    6     6    6    4   2

       2    2     3    2    2

            1          1

and so on...

Next, with the same example

3 dilations and 1 erosion :

 
             2     2     2

    0   4    6     6     6    4

0   2   6   136    8    136   6    2

    0   4    6     6     6    4

             2     2     2

3 dilations and 2 erosions :

 
                 1

      2    6     6     6    2

      6   136    8    136   6

      2    6     6     6    2
      
                 1

3 dil. / 3 erosions :

 
           5     6     5

      5   136    8    136   5
      
           5     6     5
           
3/4 :

 
          3     5     3 
          
      2  136    8    136   2          
           
          3     5     3
          
3/5 :

 
          1     4     1

         136    8    136
          
          1     4     1
          

3/6 :

 
                3
         
         135    8    135
         
                3

3/7 :

 
         132    8    132
         

We interpret this as a 1 point territory.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

15. The Board Library

15.1 Board Data structures  Board Data Structures
15.2 The Board Array  One-dimensional board array
15.3 Incremental Board data structures  Incremental board data structures
15.4 Some Board Functions  Explanation of some board functions

The foundation of the GNU Go engine is a library of very efficient routines for handling go boards. This board library, called `libboard', can be used for those programs that only need a basic go board but no AI capability. One such program is `patterns/joseki.c', which compiles joseki pattern databases from SGF files.

If you want to use the board library in your own program, you need all the .c-files listed under libboard_SOURCES in engine/Makefile.am, and the files in the directories sgf/ and utils/. Then you should include engine/board.h in your code.

The library consists of the following files:

To use the board library, you must include `liberty.h' just like when you use the whole engine, but of course you cannot use all the functions declared in it, i.e. the functions that are part of the engine, but not part of the board library. You must link your application with libboard.a.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

15.1 Board Data structures

The basic data structures of the board correspond tightly to the board_state struct described in See section 17.3 The board_state struct. They are all stored in global variables for efficiency reasons, the most important of which are:

 
int           board_size;
Intersection  board[MAXSIZE];
int           board_ko_pos;

float         komi;
int           white_captured;
int           black_captured;

Hash_data     hashdata;

The description of the Position struct is applicable to these variables also, so we won't duplicate it here. All these variables are globals for performance reasons. Behind these variables, there are a number of other private data structures. These implement incremental handling of strings, liberties and other properties (see section 15.3 Incremental Board data structures). The variable hashdata contains information about the hash value for the current position (see section 11.2 Hashing of Positions).

These variables should never be manipulated directly, since they are only the front end for the incremental machinery. They can be read, but should only be written by using the functions described in the next section. If you write directly to them, the incremental data structures will become out of sync with each other, and a crash is the likely result.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

15.2 The Board Array

GNU Go represents the board in a one-dimensional array called board. For some purposes a two dimensional indexing of the board by parameters (i,j) might be used.

The board array includes out-of-board markers around the board. To make the relation to the old two-dimensional board representation clear, this figure shows how the 1D indices correspond to the 2D indices when MAX_BOARD is 7.

 
  j  -1   0   1   2   3   4   5   6
i +----------------------------------
-1|   0   1   2   3   4   5   6   7
 0|   8   9  10  11  12  13  14  15
 1|  16  17  18  19  20  21  22  23
 2|  24  25  26  27  28  29  30  31
 3|  32  33  34  35  36  37  38  39
 4|  40  41  42  43  44  45  46  47
 5|  48  49  50  51  52  53  54  55
 6|  56  57  58  59  60  61  62  63
 7|  64  65  66  67  68  69  70  71  72

To convert between a 1D index pos and a 2D index (i,j), the macros POS, I, and J are provided, defined as below:

 
#define POS(i, j)    ((MAX_BOARD + 2) + (i) * (MAX_BOARD + 1) + (j))
#define I(pos)       ((pos) / (MAX_BOARD + 1) - 1)
#define J(pos)       ((pos) % (MAX_BOARD + 1) - 1)

All 1D indices not corresponding to points on the board have the out of board marker value GRAY. Thus if board_size and MAX_BOARD both are 7, this looks like

 
  j  -1   0   1   2   3   4   5   6
i +----------------------------------
-1|   #   #   #   #   #   #   #   #
 0|   #   .   .   .   .   .   .   .
 1|   #   .   .   .   .   .   .   .
 2|   #   .   .   .   .   .   .   .
 3|   #   .   .   .   .   .   .   .
 4|   #   .   .   .   .   .   .   .
 5|   #   .   .   .   .   .   .   .
 6|   #   .   .   .   .   .   .   .
 7|   #   #   #   #   #   #   #   #   #

The indices marked `#' have value GRAY. If MAX_BOARD is 7 and board_size is only 5:

 
  j  -1   0   1   2   3   4   5   6
i +----------------------------------
-1|   #   #   #   #   #   #   #   #
 0|   #   .   .   .   .   .   #   #
 1|   #   .   .   .   .   .   #   #
 2|   #   .   .   .   .   .   #   #
 3|   #   .   .   .   .   .   #   #
 4|   #   .   .   .   .   .   #   #
 5|   #   #   #   #   #   #   #   #
 6|   #   #   #   #   #   #   #   #
 7|   #   #   #   #   #   #   #   #   #

Navigation on the board is done by the SOUTH, WEST, NORTH, and EAST macros,

 
#define NS           (MAX_BOARD + 1)
#define WE           1
#define SOUTH(pos)   ((pos) + NS)
#define WEST(pos)    ((pos) - 1)
#define NORTH(pos)   ((pos) - NS)
#define EAST(pos)    ((pos) + 1)

There are also shorthand macros SW, NW, NE, SE, SS, WW, NN, EE for two step movements.

Any movement from a point on the board to an adjacent or diagonal vertex is guaranteed to produce a valid index into the board array, and the color found is GRAY if it is not on the board. To do explicit tests for out of board there are two macros

 
#define ON_BOARD(pos) (board[pos] != GRAY)
#define ON_BOARD1(pos) (((unsigned) (pos) < BOARDSIZE) && board[pos] != GRAY)

where the first one should be used in the algorithms and the second one is useful for assertion tests.

The advantage of a one-dimensional board array is that it gives a significant performance advantage. We need only one variable to determine a board position, which means that many functions need less arguments. Also, often one computation is sufficient for 1D-coordinate where we would need two with two 2D-coordinates: If we, for example, want to have the coordinate of the upper right of pos, we can do this with NORTH(EAST(pos)) instead of (i+1, j-1).

Important: The 2D coordinate (-1,-1), which is used for pass and sometimes to indicate no point, maps to the 1D coordinate 0, not to -1. Instead of a plain 0, use one of the macros NO_MOVE or PASS_MOVE.

A loop over multiple directions is straightforwardly written:

 
  for (k = 0; k < 4; k++) {
    int d = delta[k];
    do_something(pos + d);
  }

The following constants are useful for loops over the entire board and allocation of arrays with a 1-1 mapping to the board.

 
#define BOARDSIZE    ((MAX_BOARD + 2) * (MAX_BOARD + 1) + 1)
#define BOARDMIN     (MAX_BOARD + 2)
#define BOARDMAX     (MAX_BOARD + 1) * (MAX_BOARD + 1)

BOARDSIZE is the actual size of the 1D board array, BOARDMIN is the first index corresponding to a point on the board, and BOARDMAX is one larger than the last index corresponding to a point on the board.

Often one wants to traverse the board, carrying out some function at every vertex. Here are two possible ways of doing this:

 
  int m, n;
  for (m = 0; m < board_size; m++)
    for (n = 0; n < board_size; n++) {
      do_something(POS(m, n));
    }

Or:

 
  int pos;
  for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
    if (ON_BOARD(pos))
      do_something(pos);
  }


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

15.3 Incremental Board data structures

In addition to the global board state, the algorithms in `board.c' implement a method of incremental updates that keeps track of the following information for each string:

The basic data structure is

 
struct string_data {
  int color;                       /* Color of string, BLACK or WHITE */
  int size;                        /* Number of stones in string. */
  int origin;                      /* Coordinates of "origin", i.e. */
                                   /* "upper left" stone. */
  int liberties;                   /* Number of liberties. */
  int libs[MAX_LIBERTIES];         /* Coordinates of liberties. */
  int neighbors;                   /* Number of neighbor strings */
  int neighborlist[MAXCHAIN];      /* List of neighbor string numbers. */
  int mark;                        /* General purpose mark. */
};

struct string_data string[MAX_STRINGS];

It should be clear that almost all information is stored in the string array. To get a mapping from the board coordinates to the string array we have

 
static int string_number[BOARDMAX];

which contains indices into the string array. This information is only valid at nonempty vertices, however, so it is necessary to first verify that board[pos] != EMPTY.

The string_data structure does not include an array of the stone coordinates. This information is stored in a separate array:

 
static int next_stone[BOARDMAX];

This array implements cyclic linked lists of stones. Each vertex contains a pointer to another (possibly the same) vertex. Starting at an arbitrary stone on the board, following these pointers should traverse the entire string in an arbitrary order before coming back to the starting point. As for the 'string_number' array, this information is invalid at empty points on the board. This data structure has the good properties of requiring fixed space (regardless of the number of strings) and making it easy to add a new stone or join two strings.

Additionally the code makes use of some work variables:

 
static int ml[BOARDMAX];
static int liberty_mark;
static int string_mark;
static int next_string;
static int strings_initialized = 0;

The ml array and liberty_mark are used to "mark" liberties on the board, e.g. to avoid counting the same liberty twice. The convention is that if ml[pos] has the same value as liberty_mark, then pos is marked. To clear all marks it suffices to increase the value of liberty_mark, since it is never allowed to decrease.

The same relation holds between the mark field of the string_data structure and string_mark. Of course these are used for marking individual strings.

next_string gives the number of the next available entry in the string array. Then strings_initialized is set to one when all data structures are known to be up to date. Given an arbitrary board position in the `board' array, this is done by calling incremental_board_init(). It is not necessary to call this function explicitly since any other function that needs the information does this if it has not been done.

The interesting part of the code is the incremental update of the data structures when a stone is played and subsequently removed. To understand the strategies involved in adding a stone it is necessary to first know how undoing a move works. The idea is that as soon as some piece of information is about to be changed, the old value is pushed onto a stack which stores the value and its address. The stack is built from the following structures:

 
struct change_stack_entry {
  int *address;
  int value;
};

struct change_stack_entry change_stack[STACK_SIZE];
int change_stack_index;

and manipulated with the macros

 
BEGIN_CHANGE_RECORD()
PUSH_VALUE(v)
POP_MOVE()

Calling BEGIN_CHANGE_RECORD() stores a null pointer in the address field to indicate the start of changes for a new move. As mentioned earlier PUSH_VALUE() stores a value and its corresponding address. Assuming that all changed information has been duly pushed onto the stack, undoing the move is only a matter of calling POP_MOVE(), which simply assigns the values to the addresses in the reverse order until the null pointer is reached. This description is slightly simplified because this stack can only store 'int' values and we need to also store changes to the board. Thus we have two parallel stacks where one stores int values and the other one stores Intersection values.

When a new stone is played on the board, first captured opponent strings, if any, are removed. In this step we have to push the board values and the next_stone pointers for the removed stones, and update the liberties and neighbor lists for the neighbors of the removed strings. We do not have to push all information in the 'string' entries of the removed strings however. As we do not reuse the entries they will remain intact until the move is pushed and they are back in use.

After this we put down the new stone and get three distinct cases:

  1. The new stone is isolated, i.e. it has no friendly neighbor.
  2. The new stone has exactly one friendly neighbor.
  3. The new stone has at least two friendly neighbors.

The first case is easiest. Then we create a new string by using the number given by next_string and increasing this variable. The string will have size one, next_stone points directly back on itself, the liberties can be found by looking for empty points in the four directions, possible neighbor strings are found in the same way, and those need also to remove one liberty and add one neighbor.

In the second case we do not create a new string but extend the neighbor with the new stone. This involves linking the new stone into the cyclic chain, if needed moving the origin, and updating liberties and neighbors. Liberty and neighbor information also needs updating for the neighbors of the new stone.

In the third case finally, we need to join already existing strings. In order not to have to store excessive amounts of information, we create a new string for the new stone and let it assimilate the neighbor strings. Thus all information about those can simply be left around in the 'string' array, exactly as for removed strings. Here it becomes a little more complex to keep track of liberties and neighbors since those may have been shared by more than one of the joined strings. Making good use of marks it all becomes rather straightforward anyway.

The often used construction

 
    pos = FIRST_STONE(s);
    do {
        ...
        pos = NEXT_STONE(pos);
    } while (!BACK_TO_FIRST_STONE(s, pos));

traverses the stones of the string with number `s' exactly once, with pos holding the coordinates. In general pos is used as board coordinate and `s' as an index into the string array or sometimes a pointer to an entry in the string array.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

15.4 Some Board Functions

Reading, often called search in computer game theory, is a fundamental process in GNU Go. This is the process of generating hypothetical future boards in order to determine the answer to some question, for example "can these stones live." Since these are hypothetical future positions, it is important to be able to undo them, ultimately returning to the present board. Thus a move stack is maintained during reading. When a move is tried, by the function trymove, or its variant tryko. This function pushes the current board on the stack and plays a move. The stack pointer stackp, which keeps track of the position, is incremented. The function popgo() pops the move stack, decrementing stackp and undoing the last move made.

Every successful trymove() must be matched with a popgo(). Thus the correct way of using this function is:

 
  if (trymove(pos, color, ... )) {
       ...    [potentially lots of code here]
       popgo();
  }   

In case the move is a ko capture, the legality of the capture is subject to the komaster scheme (see section 11.4 Ko Handling).

As you see, trymove() plays a move which can be easily retracted (with popgo()) and it is call thousands of times per actual game move as GNU Go analyzes the board position. By contrast the function play_move() plays a move which is intended to be permanent, though it is still possible to undo it if, for example, the opponent retracts a move.

Other board functions are documented in See section 18.3 Board Utilities.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16. Handling SGF trees in memory

SGF - Smart Game Format - is a file format which is used for storing game records for a number of different games, among them chess and go. The format is a framework with special adaptions to each game. This is not a description of the file format standard. Too see the exact definition of the file format, see http://www.red-bean.com/sgf/.

GNU Go contains a library to handle go game records in the SGF format in memory and to read and write SGF files. This library - libsgf.a - is in the sgf subdirectory. To use the SGF routines, include the file `sgftree.h'.

Each game record is stored as a tree of nodes, where each node represents a state of the game, often after some move is made. Each node contains zero or more properties, which gives meaning to the node. There can also be a number of child nodes which are different variations of the game tree. The first child node is the main variation.

Here is the definition of SGFNode, and SGFProperty, the data structures which are used to encode the game tree.

 
typedef struct SGFProperty_t {
  struct SGFProperty_t *next;
  short  name;
  char   value[1];
} SGFProperty;


typedef struct SGFNode_t {
  SGFProperty      *props;
  struct SGFNode_t *parent;
  struct SGFNode_t *child;
  struct SGFNode_t *next;
} SGFNode;

Each node of the SGF tree is stored in an SGFNode struct. It has a pointer to a linked list of properties (see below) called props. It also has a pointer to a linked list of children, where each child is a variation which starts at this node. The variations are linked through the next pointer and each variation continues through the child pointer. Each and every node also has a pointer to its parent node (the parent field), except the top node whose parent pointer is NULL.

An SGF property is encoded in the SGFPoperty struct. It is linked in a list through the next field. A property has a name which is encoded in a short int. Symbolic names of properties can be found in `sgf_properties.h'.

Some properties also have a value, which could be an integer, a floating point value, a character or a string. These values can be accessed or set through special functions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.1 The SGFTree datatype

Sometimes we just want to record an ongoing game or something similarly simple and not do any sofisticated tree manipulation. In that case we can use the simplified interface provided by SGFTree below.

 
typedef struct SGFTree_t {
  SGFNode *root;
  SGFNode *lastnode;
} SGFTree;

An SGFTree contains a pointer to the root node of an SGF tree and a pointer to the node that we last accessed. Most of the time this will be the last move of an ongoing game.

Most of the functions which manipulate an SGFTree work exactly like their SGFNode counterparts, except that they work on the current node of the tree.

All the functions below that take arguments tree and node will work on:

  1. node if non-NULL
  2. tree->lastnode if non-NULL
  3. The current end of the game tree.
in that order.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17. Application Programmers Interface to GNU Go

If you want to write your own interface to GNU Go, or if you want to create a go application using the GNU Go engine, this chapter is of interest to you.

First an overview: GNU Go consists of two parts: the GNU Go engine and a program (user interface) which uses this engine. These are linked together into one binary. The current program implements the following user modes:

The GNU Go engine can be used in other applications. For example, supplied with GNU Go is another program using the engine, called `debugboard', in the directory `interface/debugboard/'. The program debugboard lets the user load SGF files and can then interactively look at different properties of the position such as group status and eye status.

The purpose of this Chapter is to show how to interface your own program such as debugboard with the GNU Go engine.

Figure 1 describes the structure of a program using the GNU Go engine.

 
                 +-----------------------------------+
                 |                                   |
                 |          Go application           |
                 |                                   |
                 +-----+----------+------+           |
                 |     |          |      |           |
                 |     |   Game   |      |           |
                 |     | handling |      |           |
                 |     |          |      |           |
                 |     +----+-----+      |           |
                 |   SGF    |    Move    |           |
                 | handling | generation |           |
                 |          |            |           |
                 +----------+------------+-----------+
                 |                                   |
                 |           Board handling          |
                 |                                   |
                 +-----------------------------------+
     
        Figure 1: The structure of a program using the GNU Go engine

The foundation is a library called libboard.a which provides efficient handling of a go board with rule checks for moves, with incremental handling of connected strings of stones and with methods to efficiently hash go positions.

On top of this, there is a library which helps the application use Smart Game Format (SGF) files, with complete handling of game trees in memory and in files. This library is called libsgf.a

The main part of the code within GNU Go is the move generation library which given a position generates a move. This part of the engine can also be used to manipulate a go position, add or remove stones, do tactical and strategic reading and to query the engine for legal moves. These functions are collected into libengine.a.

The game handling code helps the application programmer keep tracks of the moves in a game. Games can be saved to SGF files and then later be read back again. These are also within libengine.a.

The responsibility of the application is to provide the user with a user interface, graphical or not, and let the user interact with the engine.

17.1 How to use the engine in your own program: getting started  How to use the engine in your program
17.2 Basic Data Structures in the Engine  
17.3 The board_state struct  
17.4 Functions which manipulate a Position  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.1 How to use the engine in your own program: getting started

To use the GNU Go engine in your own program you must include the file `gnugo.h'. This file describes the whole public API. There is another file, `liberty.h', which describes the internal interface within the engine. If you want to make a new module within the engine, e.g. for suggesting moves you will have to include this file also. In this section we will only describe the public interface.

Before you do anything else, you have to call the function init_gnugo(). This function initializes everything within the engine. It takes one parameter: the number of megabytes the engine can use for the internal hash table. In addition to this the engine will use a few megabytes for other purposes such as data describing groups (liberties, life status, etc), eyes and so on.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.2 Basic Data Structures in the Engine

There are some basic definitions in gnugo.h which are used everywhere. The most important of these are the numeric declarations of colors. Each intersection on the board is represented by one of these:

 
     color              value
     EMPTY                0
     WHITE                1
     BLACK                2

There is a macro, OTHER_COLOR(color) which can be used to get the other color than the parameter. This macro can only be used on WHITE or BLACK, but not on EMPTY.

GNU Go uses two different representations of the board, for most purposes a one-dimensional one, but for a few purposes a two dimensional one (see section 15. The Board Library). The one-dimensional board was introduced before GNU Go 3.2, while the two-dimensional board dates back to the ancestral program written by Man Lung Li before 1995. The API still uses the two-dimensional board, so the API functions have not changed much since GNU Go 3.0.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.3 The board_state struct

A basic data structure in the engine is the board_state struct. This structure is internal to the engine and is defined in `liberty.h'.

 
     typedef unsigned char Intersection;
     
     struct board_state {
       int board_size;
     
       Intersection board[BOARDSIZE];
       int board_ko_pos;
       int black_captured;
       int white_captured;
     
       Intersection initial_board[BOARDSIZE];
       int initial_board_ko_pos;
       int initial_white_captured;
       int initial_black_captured;
       int move_history_color[MAX_MOVE_HISTORY];
       int move_history_pos[MAX_MOVE_HISTORY];
       int move_history_pointer;
     
       float komi;
       int move_number;
     };

Here Intersection stores EMPTY, WHITE or BLACK. It is currently defined as an unsigned char to make it reasonably efficient in both storage and access time. The board state contains an array of Intersection's representing the board. The move history is contained in the struct. Also contained in the struct is the location of a ko (EMPTY) if the last move was not a ko capture, the komi, the number of captures, and corresponding data for the initial position at the beginning of the move history.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.4 Functions which manipulate a Position

All the functions in the engine that manipulate Positions have names prefixed by gnugo_. These functions still use the two-dimensional representation of the board (see section 15.2 The Board Array). Here is a complete list, as prototyped in `gnugo.h':


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.5 Game handling

The functions (in see section 17.4 Functions which manipulate a Position) are all that are needed to create a fully functional go program. But to make the life easier for the programmer, there is a small set of functions specially designed for handling ongoing games.

The data structure describing an ongoing game is the Gameinfo. It is defined as follows:

 
typedef struct {
  int       handicap;

  int       to_move;            /* whose move it currently is */
  SGFTree   game_record;        /* Game record in sgf format. */

  int       computer_player;    /* BLACK, WHITE, or EMPTY (used as BOTH) */

  char      outfilename[128];   /* Trickle file */
  FILE      *outfile;
} Gameinfo;

The meaning of handicap should be obvious. to_move is the color of the side whose turn it is to move.

The SGF tree game_record is used to store all the moves in the entire game, including a header node which contains, among other things, komi and handicap.

If one or both of the opponents is the computer, the field computer_player is used. Otherwise it can be ignored.

GNU Go can use a trickle file to continuously save all the moves of an ongoing game. This file can also contain information about internal state of the engine such as move reasons for various locations or move valuations. The name of this file should be stored in outfilename and the file pointer to the open file is stored in outfile. If no trickle file is used, outfilename[0] will contain a null character and outfile will be set to NULL.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

17.5.1 Functions which manipulate a Gameinfo

All the functions in the engine that manipulate Gameinfos have names prefixed by gameinfo_. Here is a complete list, as prototyped in `gnugo.h':


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

18. Utility Functions

In this Chapter, we document some of the utilities which may be called from the GNU Go engine.

18.1 General Utilities  Utilities from `engine/utils.c'
18.2 Print Utilities  Utilities from `engine/printutils.c'
18.3 Board Utilities  Utilities from `engine/board.c'
18.4 Utilities from `engine/influence.c'  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

18.1 General Utilities

Utility functions from `engine/utils.c'. Many of these functions underlie autohelper functions (see section 9.7 Autohelper Functions).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

18.2 Print Utilities

Functions in `engine/printutils.c' do formatted printing similar to printf and its allies. The following formats are recognized:

We list the non statically declared functions in `printutils.c'.

The following functions are in `showbord.c'. Not all public functions in that file are listed here.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

18.3 Board Utilities

The functions documented in this section are from `board.c'. Other functions in `board.c' are described in See section 15.4 Some Board Functions.

Next we come to countlib() and its allies, which address the problem of determining how many liberties a string has. Although countlib() addresses this basic question, other functions can often get the needed information more quickly, so there are a number of different functions in this family.

Next we have some general utility functions.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

18.4 Utilities from `engine/influence.c'

We will only list here a portion of the public functions in influence.c. The influence code is invoked through the function compute_influence (see section 13.3 Where influence gets used in the engine). It is invoked as follows.

Other functions in `influence.c' are of the nature of utilities which may be useful throughout the engine. We list the most useful ones here.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19. The Go Text Protocol

19.1 The Go Text Protocol  
19.2 Running GNU Go in GTP mode  
19.3 GTP applications  
19.4 The Metamachine  
19.5 Adding new GTP commands  
19.6 GTP command reference  Details on every GTP command


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.1 The Go Text Protocol

GNU Go 3.0 introduced a new interface, the Go Text Protocol, abbreviated GTP. The intention was to make an interface that is better suited for machine-machine communication than the ascii interface and simpler, more powerful, and more flexible than the Go Modem Protocol.

There are two versions of the protocol. Version 1 was used with GNU Go 3.0 and 3.2. GNU Go 3.4 and later versions use protocol version 2. The specification of GTP version 2 is available at http://www.lysator.liu.se/~gunnar/gtp/. GNU Go 3.4 is the reference implementation for GTP version 2, but all but the most common commands are to be regarded as private extensions of the protocol.

The GTP has a variety of applications. For GNU Go the first use was in regression testing (see section 20. Regression testing), followed by communication with the NNGS go server and for automated test games against itself and other programs. Now there are also many graphical user interfaces available supporting GTP, as well as bridges to other Go servers than NNGS.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.2 Running GNU Go in GTP mode

To start GNU Go in GTP mode, simply invoke it with the option `--mode gtp'. You will not get a prompt or any other output to start with but GNU Go is silently waiting for GTP commands.

A sample GTP session may look as follows:

 
virihaure 462% ./gnugo --mode gtp
1 boardsize 7
=1

2 clear_board
=2

3 play black D5
=3

4 genmove white
=4 C3

5 play black C3
?5 illegal move

6 play black E3
=6

7 showboard
=7
   A B C D E F G
 7 . . . . . . . 7
 6 . . . . . . . 6
 5 . . + X + . . 5
 4 . . . + . . . 4
 3 . . O . X . . 3
 2 . . . . . . . 2     WHITE (O) has captured 0 stones
 1 . . . . . . . 1     BLACK (X) has captured 0 stones
   A B C D E F G

8 quit
=8

Commands are given on a single line, starting by an optional identity number, followed by the command name and its arguments.

If the command is successful, the response starts by an equals sign (`='), followed by the identity number of the command (if any) and then the result. In this example all results were empty strings except for command 4 where the answer was the white move at C3, and command 7 where the result was a diagram of the current board position. The response ends by two consecutive newlines.

Failing commands are signified by a question mark (`?') instead of an equals sign, as in the response to command 5.

The detailed specification of the protocol can be found at http://www.lysator.liu.se/~gunnar/gtp/. The available commands in GNU Go may always be listed using the command list_commands. They are also documented in See section 19.6 GTP command reference.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.3 GTP applications

GTP is an asymmetric protocol involving two parties which we call controller and engine. The controller sends all commands and the engine only responds to these commands. GNU Go implements the engine end of the protocol.

With the source code of GNU Go is also distributed a number of applications implementing the controller end. Among the most interesting of these are:

More GTP applications, including bridges to go servers and graphical user interfaces, are listed at http://www.lysator.liu.se/~gunnar/gtp/.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.4 The Metamachine

An interesting application of the GTP is the concept of using GNU Go as an "Oracle" that can be consulted by another process. This could be another computer program that asks GNU Go to generate future board positions, then evaluate them.

David Doshay at the University of California at Santa Cruz has done interesting experiments with a parallel engine, known as SlugGo, that is based on GNU Go. These are described in http://lists.gnu.org/archive/html/gnugo-devel/2004-08/msg00060.html.

The "Metamachine" experiment is a more modest approach using the GTP to communicate with a GNU Go process that is used as an oracle. The following scheme is used.

This scheme does not produce a stronger engine, but it is suggestive, and the SlugGo experiment seems to show that a more elaborate scheme along the same lines could produce a stronger engine.

Two implementations are distributed with GNU Go. Both make use of fork and pipe system calls, so they require a Unix-like environment. The Metamachine has been tested under GNU/Linux.

Important: If the Metamachine terminates normally, the GNU Go process will be killed. However there is a danger that something will go wrong. When you are finished running the Metamachine, it is a good idea to run ps -A|grep gnugo or ps -aux|grep gnugo to make sure there are no unterminated processes. (If there are, just kill them.)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.4.1 The Standalone Metamachine

In `interface/gtp_examples/metamachine.c' is a standalone implementation of the Metamachine. Compile it with cc -o metamachine metamachine.c and run it. It forks a gnugo process with which it communicates through the GTP, to use as an oracle.

The following scheme is followed:

 
             stdin             pipe a
  GTP client ----> Metamachine -----> GNU Go
             <----             <-----
            stdout             pipe b

Most commands issued by the client are passed along verbatim to GNU Go by the Metamachine. The exception is gg_genmove, which is intercepted then processed differently, as described above. The client is unaware of this, and only knows that it issued a gg_genmove command and received a reply. Thus to the the Metamachine appears as an ordinary GTP engine.

Usage: no arguments gives normal GTP behavior. metamachine --debug sends diagnostics to stderr.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.4.2 GNU Go as a Metamachine

Alternatively, you may compile GNU Go with the configure option `--enable-metamachine'. This causes the file oracle.c to be compiled, which contains the Metamachine code. This has no effect on the engine unless you run GNU Go with the runtime option `--metamachine'. Thus you must use both the configure and the runtime option to get the Metamachine.

This method is better than the standalone program since you have access to GNU Go's facilities. For example, you can run the Metamachine with CGoban or in Ascii mode this way.

You can get traces by adding the command line `-d0x1000000'. In debugging the Metamachine, a danger is that any small oversight in designing the program can cause the forked process and the controller to hang, each one waiting for a response from the other. If this seems to happen it is useful to know that you can attach gdb to a running process and find out what it is doing.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.5 Adding new GTP commands

The implementation of GTP in GNU Go is distributed over three files, `interface/gtp.h', `interface/gtp.c', and `interface/play_gtp.c'. The first two implement a small library of helper functions which can be used also by other programs. In the interest of promoting the GTP they are licensed with minimal restrictions (see section A.3 The Go Text Protocol License). The actual GTP commands are implemented in `play_gtp.c', which has knowledge about the engine internals.

To see how a simple but fairly typical command is implemented we look at gtp_countlib() (a GNU Go private extension command):

 
static int
gtp_countlib(char *s)
{
  int i, j;
  if (!gtp_decode_coord(s, &i, &j))
    return gtp_failure("invalid coordinate");

  if (BOARD(i, j) == EMPTY)
    return gtp_failure("vertex must not be empty");

  return gtp_success("%d", countlib(POS(i, j)));
}

The arguments to the command are passed in the string s. In this case we expect a vertex as argument and thus try to read it with gtp_decode_coord() from `gtp.c'.

A correctly formatted response should start with either `=' or `?', followed by the identity number (if one was sent), the actual result, and finally two consecutive newlines. It is important to get this formatting correct since the controller in the other end relies on it. Naturally the result itself cannot contain two consecutive newlines but it may be split over several lines by single newlines.

The easiest way to generate a correctly formatted response is with one of the functions gtp_failure() and gtp_success(), assuming that their formatted output does not end with a newline.

Sometimes the output is too complex for use with gtp_success, e.g. if we want to print vertices, which gtp_success() does not support. Then we have to fall back to the construction in e.g. gtp_genmove():

 
static int
gtp_genmove(char *s)
{
  [...]
  gtp_start_response(GTP_SUCCESS);
  gtp_print_vertex(i, j);
  return gtp_finish_response();
}

Here gtp_start_response() writes the equal sign and the identity number while gtp_finish_response() adds the final two newlines. The next example is from gtp_list_commands():

 
static int
gtp_list_commands(char *s)
{
  int k;
  UNUSED(s);

  gtp_start_response(GTP_SUCCESS);

  for (k = 0; commands[k].name != NULL; k++)
    gtp_printf("%s\n", commands[k].name);

  gtp_printf("\n");
  return GTP_OK;
}

As we have said, the response should be finished with two newlines. Here we have to finish up the response ourselves since we already have one newline in place from the last command printed in the loop.

In order to add a new GTP command to GNU Go, the following pieces of code need to be inserted in `play_gtp.c':

  1. A function declaration using the DECLARE macro in the list starting at line 68.
  2. An entry in the commands[] array starting at line 200.
  3. An implementation of the function handling the command.

Useful helper functions in `gtp.c'/`gtp.h' are:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.6 GTP command reference

This section lists the GTP commands implemented in GNU Go along with some information about each command. Each entry in the list has the following fields:

Without further ado, here is the big list (in no particular order):


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20. Regression testing

The standard purpose of regression testing is to avoid getting the same bug twice. When a bug is found, the programmer fixes the bug and adds a test to the test suite. The test should fail before the fix and pass after the fix. When a new version is about to be released, all the tests in the regression test suite are run and if an old bug reappears, this will be seen quickly since the appropriate test will fail.

The regression testing in GNU Go is slightly different. A typical test case involves specifying a position and asking the engine what move it would make. This is compared to one or more correct moves to decide whether the test case passes or fails. It is also stored whether a test case is expected to pass or fail, and deviations in this status signify whether a change has solved some problem and/or broken something else. Thus the regression tests both include positions highlighting some mistake being done by the engine, which are waiting to be fixed, and positions where the engine does the right thing, where we want to detect if a change breaks something.

20.1 Regression testing in GNU Go  Regression Testing in GNU Go
20.2 Test suites  Test Suites
20.3 Running the Regression Tests  
20.4 Running regress.pike  
20.5 Viewing tests with Emacs  
20.6 HTML Regression Views  HTML Views


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20.1 Regression testing in GNU Go

Regression testing is performed by the files in the `regression/' directory. The tests are specified as GTP commands in files with the suffix `.tst', with corresponding correct results and expected pass/fail status encoded in GTP comments following the test. To run a test suite the shell scripts `test.sh', `eval.sh', and `regress.sh' can be used. There are also Makefile targets to do this. If you make all_batches most of the tests are run. The Pike script `regress.pike' can also be used to run all tests or a subset of the tests.

Game records used by the regression tests are stored in the directory `regression/games/' and its subdirectories.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20.2 Test suites

The regression tests are grouped into suites and stored in files as GTP commands. A part of a test suite can look as follows:

 
# Connecting with ko at B14 looks best. Cutting at D17 might be
# considered. B17 (game move) is inferior.
loadsgf games/strategy25.sgf 61
90 gg_genmove black
#? [B14|D17]

# The game move at P13 is a suicidal blunder.
loadsgf games/strategy25.sgf 249
95 gg_genmove black
#? [!P13]

loadsgf games/strategy26.sgf 257
100 gg_genmove black
#? [M16]*

Lines starting with a hash sign, or in general anything following a hash sign, are interpreted as comments by the GTP mode and thus ignored by the engine. GTP commands are executed in the order they appear, but only those on numbered lines are used for testing. The comment lines starting with #? are magical to the regression testing scripts and indicate correct results and expected pass/fail status. The string within brackets is matched as a regular expression against the response from the previous numbered GTP command. A particular useful feature of regular expressions is that by using `|' it is possible to specify alternatives. Thus B14|D17 above means that if either B14 or D17 is the move generated in test case 90, it passes. There is one important special case to be aware of. If the correct result string starts with an exclamation mark, this is excluded from the regular expression but afterwards the result of the matching is negated. Thus !P13 in test case 95 means that any move except P13 is accepted as a correct result.

In test case 100, the brackets on the #? line is followed by an asterisk. This means that the test is expected to fail. If there is no asterisk, the test is expected to pass. The brackets may also be followed by a `&', meaning that the result is ignored. This is primarily used to report statistics, e.g. how many tactical reading nodes were spent while running the test suite.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20.3 Running the Regression Tests

./test.sh blunder.tst runs the tests in `blunder.tst' and prints the results of the commands on numbered lines, which may look like:

 
1 E5
2 F9
3 O18
4 B7
5 A4
6 E4
7 E3
8 A3
9 D9
10 J9
11 B3
12 C6
13 C6

This is usually not very informative, however. More interesting is ./eval.sh blunder.tst which also compares the results above against the correct ones in the test file and prints a report for each test on the form:

 
1 failed: Correct '!E5', got 'E5'
2 failed: Correct 'C9|H9', got 'F9'
3 PASSED
4 failed: Correct 'B5|C5|C4|D4|E4|E3|F3', got 'B7'
5 PASSED
6 failed: Correct 'D4', got 'E4'
7 PASSED
8 failed: Correct 'B4', got 'A3'
9 failed: Correct 'G8|G9|H8', got 'D9'
10 failed: Correct 'G9|F9|C7', got 'J9'
11 failed: Correct 'D4|E4|E5|F4|C6', got 'B3'
12 failed: Correct 'D4', got 'C6'
13 failed: Correct 'D4|E4|E5|F4', got 'C6'

The result of a test can be one of four different cases:

If you want a less verbose report, ./regress.sh . blunder.tst does the same thing as the previous command, but only reports unexpected results. The example above is compressed to

 
3 unexpected PASS!
5 unexpected PASS!
7 unexpected PASS!

For convenience the tests are also available as makefile targets. For example, make blunder runs the tests in the blunder test suite by executing eval.sh blunder.tst. make all_batches runs all test suites in a sequence using the regress.sh script.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20.4 Running regress.pike

A more powerful way to run regressions is with the script `regress.pike'. This requires that you have Pike (http://pike.ida.liu.se) installed.

Executing ./regress.pike without arguments will run all testsuites that make all_batches would run. The difference is that unexpected results are reported immediately when they have been found (instead of after the whole file has been run) and that statistics of time consumption and node usage is presented for each test file and in total.

To run a single test suite do e.g. ./regress.pike nicklas3.tst or ./regress.pike nicklas3. The result may look like:

 
nicklas3                                 2.96    614772    3322      469
Total nodes: 614772 3322 469
Total time: 2.96 (3.22)
Total uncertainty: 0.00
The numbers here mean that the test suite took 2.96 seconds of processor time and 3.22 seconds of real time. The consumption of reading nodes was 614772 for tactical reading, 3322 for owl reading, and 469 for connection reading. The last line relates to the variability of the generated moves in the test suite, and 0 means that none was decided by the randomness contribution to the move valuation. Multiple testsuites can be run by e.g. ./regress.pike owl ld_owl owl1.

It is also possible to run a single testcase, e.g. ./regress.pike strategy:6, a number of testcases, e.g. ./regress.pike strategy:6,23,45, a range of testcases, e.g. ./regress.pike strategy:13-15 or more complex combinations e.g. ./regress.pike strategy:6,13-15,23,45 nicklas3:602,1403.

There are also command line options to choose what engine to run, what options to send to the engine, to turn on verbose output, and to use a file to specify which testcases to run. Run ./regress.pike --help for a complete and up to date list of options.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20.5 Viewing tests with Emacs

To get a quick regression view, you may use the graphical display mode available with Emacs (see section 3.5 GNU Go mode in Emacs). You will want the cursor in the regression buffer when you enter M-x gnugo, so that GNU Go opens in the correct directory. A good way to be in the right directory is to open the window of the test you want to investigate. Then you can cut and past GTP commands directly from the test to the minibuffer, using the : command from Emacs. Although Emacs mode does not have a coordinate grid, you may get an ascii board with the coordinate grid using : showboard command.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20.6 HTML Regression Views

Extremely useful HTML Views of the regression tests may be produced using two perl scripts `regression/regress.pl' and `regression/regress.plx'.

  1. The driver program (regress.pl) which:
  2. The interface to view the captured output (regress.plx) which:


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20.6.1 Setting up the HTML regression Views

This documentation assumes an apache configured as per Debian's Apache 1.3 distribution, but it should be fairly close to the config for other distributions.

First, you will need to configure Apache to run CGI scripts in the directory you wish to serve the html views from. To do this, add the following to `/etc/apache/httpd.conf' (or to a user-specific conf file if applicable):

 
<Directory /path/to/script/>
    Options +ExecCGI
</Directory>

This allows CGI scripts to be executed in the directory used by regress.plx. Next, you need to tell Apache that `.plx' is a CGI script ending. Your `httpd.conf' file should contain a section <IfModule mod_mime.c>. Within that section, there may or may not be a line:

AddHandler cgi-script ....

If there isn't already, add it; add `.plx' to the list of extensions.

You will also need to make sure you have the necessary modules loaded to run CGI scripts; mod_cgi and mod_mime should be sufficient. Your `httpd.conf' should have the relevant LoadModule lines; uncomment them if neccessary.

Next, you need to put a copy of `regress.plx' in the directory that you plan to serve the html views from.

You will also need to install the Perl module GD, available from CPAN or via apt-get install libgd-perl on Debian.

Finally, run `regression/regress.pl' to create the xml data used to generate the html views; then, copy the `html/' directory to the same directory as `regress.plx' resides in.

At this point, you should have a working copy of the html regression views.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

A. Copying

The program GNU Go is distributed under the terms of the GNU General Public License (GPL). Its documentation is distributed under the terms of the GNU Free Documentation License (GFDL).

A.1 GNU GENERAL PUBLIC LICENSE  The GNU General Public License
A.2 GNU FREE DOCUMENTATION LICENSE  The GNU Free Documentation License
A.3 The Go Text Protocol License  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

A.1 GNU GENERAL PUBLIC LICENSE

Version 2, June 1991

 
Copyright © 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Preamble

The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.

When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.

For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.

We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.

Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.

Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and modification follow.

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  1. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".

    Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.

  2. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

    You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.

  3. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:

    1. You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.

    2. You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.

    3. If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)

    These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.

    Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.

    In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.

  4. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:

    1. Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,

    2. Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,

    3. Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)

    The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.

    If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.

  5. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

  6. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.

  7. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.

  8. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.

    If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.

    It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.

    This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.

  9. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.

  10. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

    Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.

  11. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

    NO WARRANTY

  12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.

 
one line to give the program's name and an idea of what it does.
Copyright (C) 19yy  name of author

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this when it starts in an interactive mode:

 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'.  This is free software, and you are welcome
to redistribute it under certain conditions; type `show c' 
for details.

The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:

 
Yoyodyne, Inc., hereby disclaims all copyright
interest in the program `Gnomovision'
(which makes passes at compilers) written 
by James Hacker.

signature of Ty Coon, 1 April 1989
Ty Coon, President of Vice

This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

A.2 GNU FREE DOCUMENTATION LICENSE

Version 1.1, March 2000

 
Copyright (C) 2000  Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
  1. PREAMBLE

    The purpose of this License is to make a manual, textbook, or other written document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

    This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

    We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.

  2. APPLICABILITY AND DEFINITIONS

    This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you".

    A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

    A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (For example, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

    The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License.

    The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License.

    A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, whose contents can be viewed and edited directly and straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent. A copy that is not "Transparent" is called "Opaque".

    Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML designed for human modification. Opaque formats include PostScript, PDF, proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML produced by some word processors for output purposes only.

    The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.

  3. VERBATIM COPYING

    You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.

    You may also lend copies, under the same conditions stated above, and you may publicly display copies.

  4. COPYING IN QUANTITY

    If you publish printed copies of the Document numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.

    If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

    If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a publicly-accessible computer-network location containing a complete Transparent copy of the Document, free of added material, which the general network-using public has access to download anonymously at no charge using public-standard network protocols. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

    It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

  5. MODIFICATIONS

    You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

    1. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.

    2. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has less than five).

    3. State on the Title page the name of the publisher of the Modified Version, as the publisher.

    4. Preserve all the copyright notices of the Document.

    5. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.

    6. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.

    7. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.

    8. Include an unaltered copy of this License.

    9. Preserve the section entitled "History", and its title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.

    10. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.

    11. In any section entitled "Acknowledgements" or "Dedications", preserve the section's title, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.

    12. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.

    13. Delete any section entitled "Endorsements". Such a section may not be included in the Modified Version.

    14. Do not retitle any existing section as "Endorsements" or to conflict in title with any Invariant Section.

    If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.

    You may add a section entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

    You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

    The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.

  6. COMBINING DOCUMENTS

    You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice.

    The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

    In the combination, you must combine any sections entitled "History" in the various original documents, forming one section entitled "History"; likewise combine any sections entitled "Acknowledgements", and any sections entitled "Dedications". You must delete all sections entitled "Endorsements."

  7. COLLECTIONS OF DOCUMENTS

    You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

    You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

  8. AGGREGATION WITH INDEPENDENT WORKS

    A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, does not as a whole count as a Modified Version of the Document, provided no compilation copyright is claimed for the compilation. Such a compilation is called an "aggregate", and this License does not apply to the other self-contained works thus compiled with the Document, on account of their being thus compiled, if they are not themselves derivative works of the Document.

    If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one quarter of the entire aggregate, the Document's Cover Texts may be placed on covers that surround only the Document within the aggregate. Otherwise they must appear on covers around the whole aggregate.

  9. TRANSLATION

    Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License provided that you also include the original English version of this License. In case of a disagreement between the translation and the original English version of this License, the original English version will prevail.

  10. TERMINATION

    You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

  11. FUTURE REVISIONS OF THIS LICENSE

    The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/.

    Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

ADDENDUM: How to use this License for your documents

To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:

 

  Copyright (C)  year  your name.
  Permission is granted to copy, distribute and/or modify this document
  under the terms of the GNU Free Documentation License, Version 1.1
  or any later version published by the Free Software Foundation;
  with the Invariant Sections being list their titles, with the
  Front-Cover Texts being list, and with the Back-Cover Texts being list.
  A copy of the license is included in the section entitled ``GNU
  Free Documentation License''.

If you have no Invariant Sections, write "with no Invariant Sections" instead of saying which ones are invariant. If you have no Front-Cover Texts, write "no Front-Cover Texts" instead of "Front-Cover Texts being list"; likewise for Back-Cover Texts.

If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

A.3 The Go Text Protocol License

In order to facilitate the use of the Go Text Protocol, the two files `gtp.c' and `gtp.h' are licensed under the following terms.

Copyright 2001 by the Free Software Foundation.

Permission is hereby granted, free of charge, to any person obtaining a copy of this file `gtp.x', to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Concept Index

Jump to:   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   Z  

Index Entry Section

A
aa_confirm_safety19.6 GTP command reference
accurate_approxlib19.6 GTP command reference
accuratelib19.6 GTP command reference
adjacent dragons7.5 Dragons
adjacent dragons7.5 Dragons
all_legal19.6 GTP command reference
amalgamation of worms into dragons7.2 Amalgamation
analyze_eyegraph19.6 GTP command reference
analyze_semeai19.6 GTP command reference
analyze_semeai_after_move19.6 GTP command reference
API17. Application Programmers Interface to GNU Go
area13.2 Territory, Moyo and Area
ascii description of shapes9.1 Overview
ascii interface3.4 Ascii Interface
ascii mode3.9.4 Ascii mode options
attack19.6 GTP command reference
attack shapes database9.1 Overview
attack_either19.6 GTP command reference
autohelper actions9.6 Autohelper Actions
Autohelpers9.5 Autohelpers and Constraints
automaton10. The DFA pattern matcher

B
black19.6 GTP command reference
block_off19.6 GTP command reference
board_state17.3 The board_state struct
boardsize19.6 GTP command reference
break_in19.6 GTP command reference

C
cache3.9.2 Other general options
cache-size3.9.2 Other general options
captures19.6 GTP command reference
CGoban3.2 Running GNU Go via CGoban
clear_board19.6 GTP command reference
clear_cache19.6 GTP command reference
color19.6 GTP command reference
color (dragon)7.5 Dragons
colored display5.8 Colored Display
colored display7.6 Colored Dragon Display
combination_attack19.6 GTP command reference
combination_defend19.6 GTP command reference
command line options3.9 Invoking GNU Go: Command line options
connect19.6 GTP command reference
connection shapes database9.1 Overview
connection shapes database9.9 The Connections Database
connections7.3 Connection
connections database9.9 The Connections Database
corner matcher9.18 Corner Matcher
countlib19.6 GTP command reference
cputime19.6 GTP command reference
cutting stone7.1 Worms
cutting stone, potential7.1 Worms

D
data structures17.2 Basic Data Structures in the Engine
debugging on a graphical board5.6 Debugging on a Graphical Board
debugging options3.9.5 Development options
Debugging the reading code11.9 Debugging the reading code
decide-dragon5.4 Checking the Owl Code
decide-string5.3 Checking the reading code
decrease_depths19.6 GTP command reference
defence shapes database9.1 Overview
defend19.6 GTP command reference
defend_both19.6 GTP command reference
depth3.9.3 Other options affecting strength and speed
Depth of reading11. Tactical reading
description of shapes9.1 Overview
dfa10. The DFA pattern matcher
dfa.c10. The DFA pattern matcher
dfa.h10. The DFA pattern matcher
disconnect19.6 GTP command reference
distance from liberty to dragon7.1 Worms
does_attack19.6 GTP command reference
does_defend19.6 GTP command reference
does_surround19.6 GTP command reference
dragon7. Worms and Dragons
dragon escape_route7.5 Dragons
dragon genus7.5 Dragons
dragon lunch7.5 Dragons
dragon number7.5 Dragons
dragon origin7.5 Dragons
dragon safety7.5 Dragons
dragon size7.5 Dragons
dragon status7.5 Dragons
dragon weakness7.5 Dragons
dragon_data19.6 GTP command reference
dragon_status19.6 GTP command reference
dragon_stones19.6 GTP command reference
dragons7.5 Dragons
draw_search_area19.6 GTP command reference
dump_stack19.6 GTP command reference

E
echo19.6 GTP command reference
echo_err19.6 GTP command reference
editing pattern database9.19 Emacs Mode for Editing Patterns
editing patterns9.19 Emacs Mode for Editing Patterns
effective size7.5 Dragons
effective size (worm)7.1 Worms
eliminate the randomness9.11 Tuning the Pattern databases
emacs mode3.5 GNU Go mode in Emacs
escape_route7.5 Dragons
estimate_score19.6 GTP command reference
eval_eye19.6 GTP command reference
experimental_score19.6 GTP command reference
eye shapes database9.1 Overview
eye space display5.8.2 Eye Space Display
eye_data19.6 GTP command reference

F
false eye7.4 Half Eyes and False Eyes
fast pattern matching10. The DFA pattern matcher
final_score19.6 GTP command reference
final_status19.6 GTP command reference
final_status_list19.6 GTP command reference
findlib19.6 GTP command reference
finish_sgftrace19.6 GTP command reference
finite state automaton10. The DFA pattern matcher
fixed_handicap19.6 GTP command reference
FIXME4.6.4 FIXME
followup_influence19.6 GTP command reference
format of the pattern database9.1 Overview
formatted printing18.2 Print Utilities

G
GDB5.5 GTP and GDB techniques
GDB11.9 Debugging the reading code
generation of helper functions9.5 Autohelpers and Constraints
genmove19.6 GTP command reference
genmove_black19.6 GTP command reference
genmove_white19.6 GTP command reference
genus7.5 Dragons
genus (worm)7.1 Worms
get_connection_node_counter19.6 GTP command reference
get_handicap19.6 GTP command reference
get_komi19.6 GTP command reference
get_life_node_counter19.6 GTP command reference
get_owl_node_counter19.6 GTP command reference
get_random_seed19.6 GTP command reference
get_reading_node_counter19.6 GTP command reference
get_trymove_counter19.6 GTP command reference
gg-undo19.6 GTP command reference
gg_genmove19.6 GTP command reference
gGo3.3 Other Clients
glGo3.3 Other Clients
GMP3.6 The Go Modem Protocol and Go Text Protocol
GNU Go's GDB commands11.9 Debugging the reading code
go position11.2.1 Calculation of the hash value
grid optimization9.14 Implementation Details
GTP3.6 The Go Modem Protocol and Go Text Protocol
GTP5.5 GTP and GDB techniques
GTP command reference19.6 GTP command reference

H
half eye7.4 Half Eyes and False Eyes
half_eye_data19.6 GTP command reference
Hash node11.2.2 Organization of the hash table
Hashing of positions11.2 Hashing of Positions
help19.6 GTP command reference
helper functions in pattern matching9.4 Helper Functions
how GNU Go learns new joseki9.16 The Joseki Compiler
How to debug the reading code11.9 Debugging the reading code

I
implementation of pattern matching9.12 Implementation
implementation of pattern matching9.18 Corner Matcher
increase_depths19.6 GTP command reference
inessential string7.1 Worms
initial_influence19.6 GTP command reference
installation2.1 GNU/Linux and Unix
invincible worm7.1 Worms
invoking GNU Go3.9 Invoking GNU Go: Command line options
is_legal19.6 GTP command reference
is_surrounded19.6 GTP command reference

J
jago3.3 Other Clients
joseki9.16 The Joseki Compiler
joseki9.18 Corner Matcher

K
kgs-genmove_cleanup19.6 GTP command reference
known_command19.6 GTP command reference
komi19.6 GTP command reference

L
ladder_attack19.6 GTP command reference
last_move19.6 GTP command reference
level3.9.3 Other options affecting strength and speed
level19.6 GTP command reference
level of play3.9.1 Some basic options
liberties (worm)7.1 Worms
liberties, higher order (worm)7.1 Worms
licence, documentation (GFDL)How to Apply These Terms to Your New Programs
licence, program (GPL)A. Copying
limit_search19.6 GTP command reference
list_stones19.6 GTP command reference
loadsgf19.6 GTP command reference
lunch7.5 Dragons
lunch (worm)7.1 Worms

M
matchpat.c10. The DFA pattern matcher
move generation4.2 Move Generators
move generators4.2 Move Generators
move reasons4.2 Move Generators
move reasons6.2 Generation of move reasons
move_history19.6 GTP command reference
move_influence19.6 GTP command reference
move_probabilities19.6 GTP command reference
move_uncertainty19.6 GTP command reference
moyo13.2 Territory, Moyo and Area
moyo display5.8.3 Moyo Display

N
name19.6 GTP command reference
neighbor dragons7.5 Dragons
neighbor dragons7.5 Dragons

O
orientation19.6 GTP command reference
origin (worm)7.1 Worms
output file5.2 The Output File
owl_attack19.6 GTP command reference
owl_attack_certain7.5 Dragons
owl_attack_code7.5 Dragons
owl_attack_point7.5 Dragons
owl_connection_defends19.6 GTP command reference
owl_defend19.6 GTP command reference
owl_defense_certain7.5 Dragons
owl_defense_code7.5 Dragons
owl_defense_point7.5 Dragons
owl_does_attack19.6 GTP command reference
owl_does_defend19.6 GTP command reference
owl_second_attack_point7.5 Dragons
owl_second_defense_point7.5 Dragons
owl_substantial19.6 GTP command reference
owl_threaten_attack19.6 GTP command reference
owl_threaten_defense19.6 GTP command reference

P
pattern attributes9.2 Pattern Attributes
pattern database9.1 Overview
pattern database10. The DFA pattern matcher
pattern matching9.1 Overview
pattern matching10. The DFA pattern matcher
pattern matching optimization9.14 Implementation Details
pattern overview9.1 Overview
pattern.c9.1 Overview
pattern.h9.1 Overview
persistent cache11.3 Persistent Reading Cache
place_free_handicap19.6 GTP command reference
play19.6 GTP command reference
playwhite19.6 GTP command reference
popgo19.6 GTP command reference
position11.2.1 Calculation of the hash value
position struct17.2 Basic Data Structures in the Engine
potential cutting stone7.1 Worms
printsgf19.6 GTP command reference
product10. The DFA pattern matcher
protocol_version19.6 GTP command reference

Q
qGo3.3 Other Clients
quarry3.3 Other Clients
query_boardsize19.6 GTP command reference
query_orientation19.6 GTP command reference
quit19.6 GTP command reference

R
Read result11.2.2 Organization of the hash table
Reading code11. Tactical reading
Reading code debugging tools11.9 Debugging the reading code
reading DEPTH11. Tactical reading
Reading optimisation11.2 Hashing of Positions
Reading process11. Tactical reading
reading return codes11.1.2 Return Codes
reading shadow11.3 Persistent Reading Cache
reading.c11. Tactical reading
reading.c11.1.3 Reading cutoff and depth parameters
reading.h11. Tactical reading
reg_genmove19.6 GTP command reference
report_uncertainty19.6 GTP command reference
reset_connection_node_counter19.6 GTP command reference
reset_life_node_counter19.6 GTP command reference
reset_owl_node_counter19.6 GTP command reference
reset_reading_node_counter19.6 GTP command reference
reset_search_mask19.6 GTP command reference
reset_trymove_counter19.6 GTP command reference
restricted_genmove19.6 GTP command reference
return codes11.1.2 Return Codes

S
same_dragon19.6 GTP command reference
scoring5.7 Scoring the game
semeai7.5 Dragons
semeai_attack_certain7.5 Dragons
semeai_attack_point7.5 Dragons
semeai_defense_certain7.5 Dragons
semeai_defense_point7.5 Dragons
set_free_handicap19.6 GTP command reference
set_random_seed19.6 GTP command reference
set_search_diamond19.6 GTP command reference
set_search_limit19.6 GTP command reference
SGF (Smart Game Format)3.8 Smart Game Format
SGF files in memory16. Handling SGF trees in memory
shape attributes9.2 Pattern Attributes
showboard19.6 GTP command reference
Smart Game Format3.8 Smart Game Format
Speedup of reading process11.2 Hashing of Positions
start_sgftrace19.6 GTP command reference
string7. Worms and Dragons
superstring18.1 General Utilities
surround7.5 Dragons
surround_map19.6 GTP command reference
surround_size7.5 Dragons
surround_status7.5 Dragons
symmetry and transformations9.13 Symmetry and transformations
symmetry and transformations of shapes9.13 Symmetry and transformations

T
tactical_analyze_semeai19.6 GTP command reference
teaching josekis to GNU Go9.16 The Joseki Compiler
territory13.2 Territory, Moyo and Area
test_eyeshape19.6 GTP command reference
The Go Modem Protocol and Go Text Protocol3.6 The Go Modem Protocol and Go Text Protocol
the joseki compiler9.16 The Joseki Compiler
time_left19.6 GTP command reference
time_settings19.6 GTP command reference
timers18.1 General Utilities
traces5.1 Interpreting Traces
Transposition table11.2 Hashing of Positions
Trying hypothetical moves11. Tactical reading
tryko19.6 GTP command reference
trymove19.6 GTP command reference
tune_move_ordering19.6 GTP command reference
tuning GNU Go5.1 Interpreting Traces
tuning the pattern database9.11 Tuning the Pattern databases
tuning the shapes database9.11 Tuning the Pattern databases

U
unconditional_status19.6 GTP command reference
undo19.6 GTP command reference
Usage of the stack in reading11. Tactical reading

V
version19.6 GTP command reference

W
weakness7.5 Dragons
worm7. Worms and Dragons
worm7.1 Worms
worm_cutstone19.6 GTP command reference
worm_data19.6 GTP command reference
worm_stones19.6 GTP command reference

Z
Zobrist hashing algorithm11.2 Hashing of Positions

Jump to:   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   Z  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Functions Index

Jump to:   A   B   C   D   E   F   G   H   I   K   L   M   N   O   P   R   S   T   U   V   W  

Index Entry Section

A
abortgo18.2 Print Utilities
accuratelib18.3 Board Utilities
add_eyevalues8.11 Functions in `optics.c'
add_false_eye8.11 Functions in `optics.c'
add_stone18.3 Board Utilities
adjacent_strings18.3 Board Utilities
amalgamate_most_valuable_helper7.3 Connection
analyze_eyegraph8.11 Functions in `optics.c'
approxlib18.3 Board Utilities
atari_atari4.2 Move Generators
atari_atari6.3.10 Combination Attacks
atari_atari12.2 Combination reading
atari_atari_blunder_size12.2 Combination reading
atari_atari_confirm_safety12.2 Combination reading
attack11.1.3 Reading cutoff and depth parameters

B
block_off13.10 Break Ins
blunder_size18.1 General Utilities
break_in13.10 Break Ins

C
chainlinks18.3 Board Utilities
chainlinks218.3 Board Utilities
chainlinks318.3 Board Utilities
change_dragon_status18.1 General Utilities
clear_board18.3 Board Utilities
color_to_string18.2 Print Utilities
combinations12.2 Combination reading
compute_escape7.5 Dragons
compute_eyes8.11 Functions in `optics.c'
compute_eyes_pessimistic8.11 Functions in `optics.c'
compute_eyes_pessimistic12.1 The Owl Code
compute_influence18.4 Utilities from `engine/influence.c'
compute_surrounding_moyo_sizes7.5 Dragons
confirm_safety18.1 General Utilities
count_common_libs18.3 Board Utilities
countlib18.3 Board Utilities
countstones18.3 Board Utilities
cut_connect_callback9.10 Connections Functions

D
DEBUG18.2 Print Utilities
decrease_depth_values18.1 General Utilities
defend_against18.1 General Utilities
disconnect11.10 Connection Reading
does_attack18.1 General Utilities
does_capture_something18.3 Board Utilities
does_defend18.1 General Utilities
double_atari18.1 General Utilities
dragon_eye7.2 Amalgamation
draw_letter_coordinates18.2 Print Utilities
dump_stack18.3 Board Utilities

E
edge_distance18.3 Board Utilities
endgame_shapes4.2 Move Generators
estimate_territorial_value6.4.1 Territorial Value
extended_chainlinks18.3 Board Utilities
eyevalue_to_string8.11 Functions in `optics.c'

F
fastlib18.3 Board Utilities
fill_liberty4.2 Move Generators
find_common_libs18.3 Board Utilities
find_connections9.10 Connections Functions
find_cuts7.1 Worms
find_cuts9.10 Connections Functions
find_defense11.1.3 Reading cutoff and depth parameters
find_eye_dragons8.11 Functions in `optics.c'
find_half_and_false_eyes8.11 Functions in `optics.c'
find_neighbor_dragons7.5 Dragons
find_neighbor_dragons7.5 Dragons
find_origin18.3 Board Utilities
find_proper_superstring_liberties18.1 General Utilities
find_superstring18.1 General Utilities
find_superstring_liberties18.1 General Utilities
find_superstring_stones_and_liberties18.1 General Utilities
findlib18.3 Board Utilities
findstones18.3 Board Utilities
followup9.3 Pattern Attributes
fuseki4.2 Move Generators

G
gameinfo_clear17.5.1 Functions which manipulate a Gameinfo
gameinfo_load_sgfheader17.5.1 Functions which manipulate a Gameinfo
gameinfo_play_move17.5.1 Functions which manipulate a Gameinfo
gameinfo_play_sgftree17.5.1 Functions which manipulate a Gameinfo
gameinfo_play_sgftree_rot17.5.1 Functions which manipulate a Gameinfo
gameinfo_print17.5.1 Functions which manipulate a Gameinfo
get_kom_pos18.3 Board Utilities
get_komaster18.3 Board Utilities
gfprintf18.2 Print Utilities
gnugo_add_stone17.4 Functions which manipulate a Position
gnugo_attack17.4 Functions which manipulate a Position
gnugo_clear_board17.4 Functions which manipulate a Position
gnugo_estimate_score17.4 Functions which manipulate a Position
gnugo_examine_position17.4 Functions which manipulate a Position
gnugo_find_defense17.4 Functions which manipulate a Position
gnugo_genmove17.4 Functions which manipulate a Position
gnugo_get_board17.4 Functions which manipulate a Position
gnugo_get_boardsize17.4 Functions which manipulate a Position
gnugo_get_komi17.4 Functions which manipulate a Position
gnugo_get_move_number17.4 Functions which manipulate a Position
gnugo_is_legal17.4 Functions which manipulate a Position
gnugo_is_pass17.4 Functions which manipulate a Position
gnugo_is_suicide17.4 Functions which manipulate a Position
gnugo_placehand17.4 Functions which manipulate a Position
gnugo_play_move17.4 Functions which manipulate a Position
gnugo_play_sgfnode17.4 Functions which manipulate a Position
gnugo_play_sgftree17.4 Functions which manipulate a Position
gnugo_recordboard17.4 Functions which manipulate a Position
gnugo_remove_stone17.4 Functions which manipulate a Position
gnugo_set_komi17.4 Functions which manipulate a Position
gnugo_sethand17.4 Functions which manipulate a Position
gnugo_undo_move17.4 Functions which manipulate a Position
gnugo_who_wins17.4 Functions which manipulate a Position
gprintf18.2 Print Utilities

H
has_neighbor18.3 Board Utilities
hashnode_new_result11.2.2 Organization of the hash table
hashtable_enter_position11.2.2 Organization of the hash table
hashtable_enter_position11.2.2 Organization of the hash table
hashtable_search11.2.2 Organization of the hash table
have_common_lib18.3 Board Utilities

I
increase_depth_values18.1 General Utilities
influence_mark_non_territory18.4 Utilities from `engine/influence.c'
init_gnugo17.1 How to use the engine in your own program: getting started
init_gnugo17.4 Functions which manipulate a Position
is_corner_vertex18.3 Board Utilities
is_edge_vertex18.3 Board Utilities
is_eye_space8.11 Functions in `optics.c'
is_false_eye8.11 Functions in `optics.c'
is_halfeye8.11 Functions in `optics.c'
is_hoshi_point18.2 Print Utilities
is_illegal_ko_capture18.3 Board Utilities
is_ko18.3 Board Utilities
is_ko_point18.3 Board Utilities
is_legal4.5.1 Files in `engine/'
is_legal18.3 Board Utilities
is_marginal_eye_space8.11 Functions in `optics.c'
is_pass18.3 Board Utilities
is_proper_eye_space8.11 Functions in `optics.c'
is_self_atari18.3 Board Utilities
is_suicide18.3 Board Utilities

K
komaster_trymove15.4 Some Board Functions

L
liberty_of_string18.3 Board Utilities
location_to_buffer18.2 Print Utilities
location_to_string18.2 Print Utilities

M
make_domains7.1 Worms
make_domains8.11 Functions in `optics.c'
mark_string18.3 Board Utilities
max_eye_threat8.11 Functions in `optics.c'
max_eye_value8.11 Functions in `optics.c'
max_eyes8.11 Functions in `optics.c'
maxterri9.3 Pattern Attributes
maxvalue9.3 Pattern Attributes
min_eye_threat8.11 Functions in `optics.c'
min_eyes8.11 Functions in `optics.c'
minterri9.3 Pattern Attributes
minvalue9.3 Pattern Attributes
modify_depth_values18.1 General Utilities
modify_eye_spaces19.10 Connections Functions
modify_eye_spaces19.10 Connections Functions
move_in_stack18.3 Board Utilities
mprintf18.2 Print Utilities

N
neighbor_of_string18.3 Board Utilities

O
obvious_false_eye8.11 Functions in `optics.c'
OTHER_COLOR17.2 Basic Data Structures in the Engine
owl_attack12.1 The Owl Code
owl_defend12.1 The Owl Code
owl_reasons4.2 Move Generators
owl_reasons6.3.9 Attacking and Defending Dragons

P
partition_eyespaces8.11 Functions in `optics.c'
play_attack_defend2_n18.1 General Utilities
play_attack_defend_n18.1 General Utilities
play_break_through_n18.1 General Utilities
play_connect_n18.1 General Utilities
play_move15.4 Some Board Functions
popgo4.5.1 Files in `engine/'
popgo15.4 Some Board Functions
propagate_eye8.11 Functions in `optics.c'
proper_superstring_chainlingks18.1 General Utilities
purge_persistent_breakin_cache11.3 Persistent Reading Cache
purge_persistent_connection_cache11.3 Persistent Reading Cache
purge_persistent_owl_cache11.3 Persistent Reading Cache
purge_persistent_reading_cache11.3 Persistent Reading Cache

R
remove_stone18.3 Board Utilities
restore_board18.3 Board Utilities
restore_depth_values18.1 General Utilities
result_to_string18.2 Print Utilities
revise_semeai4.2 Move Generators
revise_thrashing_dragon4.2 Move Generators

S
safe_move11.1.3 Reading cutoff and depth parameters
safety_to_string18.2 Print Utilities
same_string18.3 Board Utilities
search_persistent_reading_cache11.3 Persistent Reading Cache
second_order_liberty_of_string18.3 Board Utilities
semeai4.2 Move Generators
set_depth_values18.1 General Utilities
set_eyevalue8.11 Functions in `optics.c'
shape9.3 Pattern Attributes
shapes4.2 Move Generators
shapes_callback9.1 Overview
showboard18.2 Print Utilities
simple_showboard18.2 Print Utilities
somewhere18.1 General Utilities
start_timer18.1 General Utilities
status_to_string18.2 Print Utilities
stones_on_board18.3 Board Utilities
store_board18.3 Board Utilities
store_persistent_reading_cache11.3 Persistent Reading Cache
store_persistent_reading_cache11.3 Persistent Reading Cache
string_connect11.10 Connection Reading
string_to_location18.2 Print Utilities
superstring_chainlinks18.1 General Utilities

T
terri9.3 Pattern Attributes
test_eyeshape8.11 Functions in `optics.c'
test_symmetry_after_move18.1 General Utilities
time_report18.1 General Utilities
topological_eye8.11 Functions in `optics.c'
tryko15.4 Some Board Functions
trymove4.5.1 Files in `engine/'
trymove15.4 Some Board Functions

U
unconditional_life7.1 Worms
unconditional_life18.1 General Utilities
undo_move15.4 Some Board Functions

V
value9.3 Pattern Attributes
value_move_reasons()6.4 Valuation of suggested moves

W
whose_area18.4 Utilities from `engine/influence.c'
whose_moyo18.4 Utilities from `engine/influence.c'
whose_territory18.4 Utilities from `engine/influence.c'
worm_reasons4.2 Move Generators

Jump to:   A   B   C   D   E   F   G   H   I   K   L   M   N   O   P   R   S   T   U   V   W  


[Top] [Contents] [Index] [ ? ]

Table of Contents

GNU GO
1. Introduction
1.1 About GNU Go and this Manual
1.2 Copyrights
1.3 Authors
1.4 Thanks
1.5 The GNU Go Task List
1.5.1 General
1.5.2 Smaller projects
1.5.3 Long term issues
1.5.4 Ideas
2. Installation
2.1 GNU/Linux and Unix
2.2 Configure Options
2.2.1 Ram Cache
2.2.2 Default Level
2.2.3 Other Options
2.3 Compiling GNU Go on Microsoft platforms
2.3.1 Windows 95/98, MS-DOS and Windows 3.x using DJGPP
2.3.2 Windows NT, 2000, XP, 95/98/ME using Cygwin
2.3.3 Windows NT, 2000, XP, 95/98/ME using MinGW32
2.3.4 Windows NT, Windows 95/98 using Visual C and project files
2.3.5 Running GNU Go on Windows NT and Windows 95/98
2.4 Macintosh
3. Using GNU Go
3.1 Getting Documentation
3.2 Running GNU Go via CGoban
3.3 Other Clients
3.4 Ascii Interface
3.5 GNU Go mode in Emacs
3.6 The Go Modem Protocol and Go Text Protocol
3.7 Computer Go Tournaments
3.8 Smart Game Format
3.9 Invoking GNU Go: Command line options
3.9.1 Some basic options
3.9.2 Other general options
3.9.3 Other options affecting strength and speed
3.9.4 Ascii mode options
3.9.5 Development options
3.9.6 Experimental options
4. GNU Go engine overview
4.1 Gathering Information
4.2 Move Generators
4.3 Move Valuation
4.4 Detailed Sequence of Events
4.5 Roadmap
4.5.1 Files in `engine/'
4.5.2 Files in `patterns/'
4.6 Coding styles and conventions
4.6.1 Coding Conventions
4.6.2 Tracing
4.6.3 Assertions
4.6.4 FIXME
4.7 Navigating the Source
5. Analyzing GNU Go's moves
5.1 Interpreting Traces
5.2 The Output File
5.3 Checking the reading code
5.4 Checking the Owl Code
5.5 GTP and GDB techniques
5.6 Debugging on a Graphical Board
5.7 Scoring the game
5.8 Colored Display
5.8.1 Dragon Display
5.8.2 Eye Space Display
5.8.3 Moyo Display
6. Move generation
6.1 Introduction
6.2 Generation of move reasons
6.3 Detailed Descriptions of various Move Reasons
6.3.1 Attacking and defending moves
6.3.2 Threats to Attack or Defend
6.3.3 Multiple attack or defense moves
6.3.4 Cutting and connecting moves
6.3.5 Semeai winning moves
6.3.6 Making or destroying eyes
6.3.7 Antisuji moves
6.3.8 Territorial moves
6.3.9 Attacking and Defending Dragons
6.3.10 Combination Attacks
6.4 Valuation of suggested moves
6.4.1 Territorial Value
6.4.2 Strategical Value
6.4.3 Shape Factor
6.4.4 Minimum Value
6.4.5 Secondary Value
6.4.6 Threats and Followup Value
6.5 End Game
7. Worms and Dragons
7.1 Worms
7.2 Amalgamation
7.3 Connection
7.4 Half Eyes and False Eyes
7.5 Dragons
7.6 Colored Dragon Display
8. Eyes and Half Eyes
8.1 Local games
8.2 Eye spaces
8.3 The eyespace as local game
8.4 An example
8.5 Graphs
8.6 Eye shape analysis
8.7 Eye Local Game Values
8.8 Topology of Half Eyes and False Eyes
8.9 Eye Topology with Ko
8.10 False Margins
8.11 Functions in `optics.c'
9. The Pattern Code
9.1 Overview
9.2 Pattern Attributes
9.2.1 Constraint Pattern Attributes
9.2.2 Action Attributes
9.3 Pattern Attributes
9.4 Helper Functions
9.5 Autohelpers and Constraints
9.6 Autohelper Actions
9.7 Autohelper Functions
9.8 Attack and Defense Database
9.9 The Connections Database
9.10 Connections Functions
9.11 Tuning the Pattern databases
9.12 Implementation
9.13 Symmetry and transformations
9.14 Implementation Details
9.15 The "Grid" Optimization
9.16 The Joseki Compiler
9.17 Ladders in Joseki
9.18 Corner Matcher
9.19 Emacs Mode for Editing Patterns
10. The DFA pattern matcher
10.1 Introduction to the DFA
10.2 What is a DFA
10.3 Pattern matching with DFA
10.4 Building the DFA
10.5 Incremental Algorithm
10.6 Some DFA Optimizations
11. Tactical reading
11.1 Reading Basics
11.1.1 Organization of the reading code
11.1.2 Return Codes
11.1.3 Reading cutoff and depth parameters
11.2 Hashing of Positions
11.2.1 Calculation of the hash value
11.2.2 Organization of the hash table
11.2.3 Hash Structures
11.3 Persistent Reading Cache
11.4 Ko Handling
11.5 A Ko Example
11.6 Another Ko Example
11.7 Alternate Komaster Schemes
11.7.1 Essentially the 2.7.232 scheme.
11.7.2 Revised 2.7.232 version
11.8 Superstrings
11.9 Debugging the reading code
11.10 Connection Reading
12. Pattern Based Reading
12.1 The Owl Code
12.2 Combination reading
13. Influence Function
13.1 Conceptual Outline of Influence
13.2 Territory, Moyo and Area
13.3 Where influence gets used in the engine
13.4 Influence and Territory
13.5 Details of the Territory Valuation
13.6 The Core of the Influence Function
13.7 The Influence Algorithm
13.8 Permeability
13.9 Escape
13.10 Break Ins
13.11 Surrounded Dragons
13.12 Patterns used by the Influence module
13.13 Colored display and debugging of influence
13.14 Influence Tuning with view.pike
14. Another approach to Moyos : Bouzy's 5/21 algorithm
14.1 Moyo history
14.2 Bouzy's 5/21 algorithm
15. The Board Library
15.1 Board Data structures
15.2 The Board Array
15.3 Incremental Board data structures
15.4 Some Board Functions
16. Handling SGF trees in memory
16.1 The SGFTree datatype
17. Application Programmers Interface to GNU Go
17.1 How to use the engine in your own program: getting started
17.2 Basic Data Structures in the Engine
17.3 The board_state struct
17.4 Functions which manipulate a Position
17.5 Game handling
17.5.1 Functions which manipulate a Gameinfo
18. Utility Functions
18.1 General Utilities
18.2 Print Utilities
18.3 Board Utilities
18.4 Utilities from `engine/influence.c'
19. The Go Text Protocol
19.1 The Go Text Protocol
19.2 Running GNU Go in GTP mode
19.3 GTP applications
19.4 The Metamachine
19.4.1 The Standalone Metamachine
19.4.2 GNU Go as a Metamachine
19.5 Adding new GTP commands
19.6 GTP command reference
20. Regression testing
20.1 Regression testing in GNU Go
20.2 Test suites
20.3 Running the Regression Tests
20.4 Running regress.pike
20.5 Viewing tests with Emacs
20.6 HTML Regression Views
20.6.1 Setting up the HTML regression Views
A. Copying
A.1 GNU GENERAL PUBLIC LICENSE
Preamble
How to Apply These Terms to Your New Programs
A.2 GNU FREE DOCUMENTATION LICENSE
ADDENDUM: How to use this License for your documents
A.3 The Go Text Protocol License
Concept Index
Functions Index

[Top] [Contents] [Index] [ ? ]

Short Table of Contents

GNU GO
1. Introduction
2. Installation
3. Using GNU Go
4. GNU Go engine overview
5. Analyzing GNU Go's moves
6. Move generation
7. Worms and Dragons
8. Eyes and Half Eyes
9. The Pattern Code
10. The DFA pattern matcher
11. Tactical reading
12. Pattern Based Reading
13. Influence Function
14. Another approach to Moyos : Bouzy's 5/21 algorithm
15. The Board Library
16. Handling SGF trees in memory
17. Application Programmers Interface to GNU Go
18. Utility Functions
19. The Go Text Protocol
20. Regression testing
A. Copying
Concept Index
Functions Index

[Top] [Contents] [Index] [ ? ]

About this document

This document was generated by using texi2html

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ < ] Back previous section in reading order 1.2.2
[ > ] Forward next section in reading order 1.2.4
[ << ] FastBack beginning of this chapter or previous chapter 1
[ Up ] Up up section 1.2
[ >> ] FastForward next chapter 2
[Top] Top cover (top) of document  
[Contents] Contents table of contents  
[Index] Index concept index  
[ ? ] About this page  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:



This document was generated by Build Daemon user on October, 25 2005 using texi2html