OpenGo: Architecture of a Go Programming Environment
Jeffrey Greenberg
Last Revision: February 20, 1998
Abstract

The requirements for and the architecture of a programming environment that facilitates the research and development of a strong Go playing program are described. The environment has been successfully developed and is in use.

Table of Contents

1. Requirements *

2. Highest Level Classes *

2.1. Referees and Players *

2.2. User Interfaces and GUIs *

3. The Referee and Players * 3.1. Referee Class *

3.2. Supported Player Classes *

4. Portability Classes * 4.1. Operating System (OS) Portability *

4.2. GUI Portability *

5. Conclusions *
Table of Figures

Figure 1 - Top Level Classes *

Figure 2 : Board, Piece, String, and Related Classes *

Figure 3 - Portability Classes *

Table of Authorities


Architecture of a Go Programming Environment

This paper describes the software organization, class hierarchies, of an environment that facilitates the development of and research in a program capable of playing the game of Go.

  1. Requirements

  2. The program must be able to communicate with both programs and people, located locally and remotely.

    The program must be able to play a game of go with a person at superior strength.

    The program is to be used as a vehicle for experimenting with techniques to play go well. Such techniques as machine learning, genetic programming and other techniques are to be easily facilitated. This work should not interfere with the rest of the program, and much effort should be spent to make available components of one part of the program to another: such things as game display code, scoring code, go game format code, etc.

    It should be capable of running completely automated against other programs or remote users. This will be done through support of the Go-Modem protocol, the Internet Go Server protocol (IGS), and the No Name Go Server protocol (NNGS).

    The code should be portable to UNIX AIX, UNIX Solaris, Windows NT and Windows 95.

    The code should be extensible to any operating system that supports threads.

    The code should be capable of using different user interfaces or GUIs with little or no work.

  3. Highest Level Classes

  4. To meet these requirements, the program is put together in a way that operating system dependencies are encapsulated in a set of generic service classes, such as a Thread class. These operating system primitives are combined with a set of sized types (signed 8 bit = S8BIT, unsigned 16 bit = U16BIT), instead of the C++ sizeless native types (short, long, char, int, etc) that help give portability over the compiler and hardware. Together these provide a high level of portability.

    From these building blocks is built the following high level abstraction that address the different kinds of player support that are required:
     


    Figure 1 - Top Level Classes

    1. Referees and Players

    2. The environment is composed of a single Referee object. A Referee can create players that play each other. The players can be people playing on the same computer, or players that are remote Ė playing via the Internet or via a modem connection. Players can be a person or a program. To accomplish all these different kinds of connections, the Referee creates two PlayerProxy classes, each of which mediates the connections between the actual players, wherever and whatever they may be. The Referee then monitors the game and can interrupt it and record it as necessary.

      It would be possible to have multiple Referees each with a pair of Players. For some kinds of experimentation, such as Genetic Programming, it is beneficial to support multiple, simultaneous games especially on computers with multiple CPUs as a way to more efficiently evolve populations. The point being that this architecture could be easily elaborated to support this.

      Both PlayerProxys and the Referee are (subclassed from) AsyncMsgHandlers, meaning that they can rapidly be posted a message containing a command or a response, and then, sometime later, they will run and process that message. This allows for each player to operate seemingly at the same time. The AsyncMsgHandler class uses portable thread and semaphore classes in its implementation.

      This design allows adding different kinds of clients as they come alongÖ For example, a Player that interfaced with a Java or Netscape browser plug-in could be added simply. Or a database client that could look up moves in databases could be added.

    3. User Interfaces and GUIs
    The Referee provides a console or GUI interface, depending on the platform that the program is running on. (Currently only a console interface is implemented.) The Referee user interface controls which kind of competitor will play against each other. Each type of competitor then provides itís own interface. Note that Players are interface specific: there is a console type interface and a GUI type of interface.

    It would be best to de-couple the interface from the Referee as it is from the Player. This is not yet done.

  5. The Referee and Players
    1. Referee Class
Provides a uniform interface to:
    1. PlayerProxy - Each of these front-ends a player. Any two can play each other.
    2. GameDisplay - The view of the game from the refereeís perspective.
    3. DataBoard - The state of the game and board.
The referee has a display for the state of the connection between the two players, while the game board itself and the move history is displayed separately by the GameDisplay class.

The Referee class creates and uses PlayerProxy classes, and encapsulates the DataBoard and GameDisplay classes. There are only two PlayerProxys at any one time, one for each opponent. For the convenience of the Players, a read-only instance of the DataBoard, which contains the rules and state of the game, is made available to them. Each may make a copy of the DataBoard for their particular purpose. In this way, a formal division is made between the rules and procedure of the game, and the strategic and tactical knowledge developed in the computer opponent to win.

      1. PlayerProxy Class

      2. This class is the base-class of all players. Each player is assumed to be operating asynchronously from each other; this is the general case. A player on the Internet playing someone linked via a modem. Each player is operating independent of the other. The actions of each player are transmitted via the common functions of the PlayerProxy class to the Referee class. In this way, different kinds of players can be implemented and can all play against each other as a measure of each opponentís progress. This class provides a uniform interface between the Referee and a particular player.

      3. GameDisplay

      4. This is an abstract representation of a displayable board that represents the referees view of the game including the history of moves and current status.

      5. DataBoard

      6. The DataBoard provides enough basic information to play and track the state of the game. The referee uses it to do itís job. All the information necessary to obey the rules of the game including setting the board size, detecting and preventing Ko, allowing or preventing suicide, removing killed stones, scoring a game, and determining when the score is final (game over) are stored in the DataBoard and in the classes it uses. The DataBoard provides the means to add, examine, remove and takeback pieces from the board.

        Super Ko checking is provided via a hashing scheme.

        Fully Enclosed areas are detected. Ponukiís are detected and used to estimate controlled space. No influence function is provided. The DataBoard can detect if the game is over by determining that all the board space is occupied or contained by ponuki. This means that the game must be played out to the very end, if such automatic game scoring is to be used. Humans will not stand for it, but for some computer go algorithms, this is sufficient.

        A copy of the board is available to players as a way for them to work the game.

        Figure 2 : Board, Piece, String, and Related Classes

        The board and the related important classes are noted below.

        1. BoardCell

        2. A board is composed of an array of BoardCells. The non-empty ones point to the GoStrings which contain them. A BoardCell also contains a Piece, which contains the color of the cell and itís location. Thus the Piece can locate the BoardCell itís in and vica-versa.

        3. GoStrings

        4. Are a collection of contiguous BoardCells. The GoString can report the number of stones in it, the number of liberties around those stones. GoStrings can be used to store lists of liberties as well. GoStrings suport invisible marks on the board to faciliate liberty counting and other operations. GoStrings can be added to GoStrings as is the case when they are joined.

        5. GoStringCollections

        6. There are collections of white and black GoStrings. GoStrings can be added or removed from a GoStringCollection. These collections can be used to store related GoStrings, such as armies or blocks. They can report the number of strings in them and the total liberties of the collection. GoStrings can remove dead GoStrings in it..

        7. HistoryElement

        8. Each move and pieces killed by the move are stored here. This is used by the DataBoard to support taking back a move.

        9. History

        10. A collection of HistoryElements comprising the moves of the game in order. This is used by the DataBoard to support recording the entire game and in taking back moves. In addition, this can be used to support pushing and popping moves when searching.

        11. Enclosure

        12. A contiguous chain of empty BoardCells. Includes information about the enclosing GoStrings. In other words liberties and potential eyes.

        13. Enclosures
Each Enclosure is stored here.
    1. Supported Player Classes

    2. Each of these is a (subclass of) PlayerProxy class. The PlayerProxy class provides a uniform, asynchronous, message based, callback interface between a player and the referee.

      Players are specialized versions (subclasses) of a PlayerProxy. Each player implements a different kind of Go opponent. Some are merely interfaces to the human player at the computer, others might interface to people playing over the Internet or by modem, and others might interface to a local or remote computer opponent.

      1. Computer Go Prototype: Circlet.

      2. This encapsulates the computer Go program that is the heart of the project. The results of this class are detailed in [Greenberg 97].

      3. Human: Console Interface

      4. This is a command-line style interface. It is completely scrolling, lacking even a UNIX "curses" style interface. A "curses" style interface could be implemented in a similar class.

      5. Modem: Go Modem Protocol

      6. This protocol is commonly implemented by Go programs and is used in Go program competitions. The standard is publicly available. [Ref].

      7. Wally Public Domain Go Program

      8. This is an interface to the public domain Go playing program, Wally. Wally plays very poorly but better than randomly. [Ref]

      9. Human: Windows Interface(*)

      10. This is a Microsoft Foundation Class (MFC) based Windows interface for playing Go. ((This is planned - not implemented yet))

      11. Random

      12. Plays randomly. The Referee rejects all illegal moves. Thus if Random makes a bad move, it is rejected by the Referee and then solicited to make another move. After a fixed consecutive number of failed attempts, it passes.

      13. IGS/Internet Go Server and the No Name Go Server (*)

      14. These are two related interfaces for playing Go on the Internet. Both humans and programs can play here with players world-wide, their scores maintained, and rankings made available. ((This is planned - not implemented yet))

      15. Go Database(*)
This player compares incoming moves with and takes responses from a database of games. The following game formats are supported:
    1. ISHI
    2. Smart Go Format (SGF) [Muller]
    3. (etc.)
  1. Portability Classes

  2. There are classes providing portability across various operating systems. The system is currently runs on Sun Solaris, UNIX AIX, and Windows NT.

    Classes have not yet been provided to abstract the GUI, yet.

    Figure 3 - Portability Classes

    1. Operating System (OS) Portability

    2. These are classes that provide an abstract OS capability. For a given operating system, there is a particular implementation of these classes that provide the concrete capability. For example, there is an abstract Modem class that applications can use, and for Windows NT an NT_Modem class that implements the interface. The abstract classes are described below.

      The build environment and makefiles control the operating system target, compiling the concrete classes that are specific to a given operating system.

      This approach assumes that the number of such targets, and thus class implementation, is small.

      1. AsyncMsgHandler Pattern

      2. This operating system pattern provides a kind of messaging interface. The application can post a command to another thread of execution and continue on its way. Meanwhile, a separate thread will receive the command via a callback and handle it. This operation is portably provided across operating systems. The pattern is built on other abstract classes that follow.

      3. Sized, Base Types

      4. These are set of sized types that provide hardware level characterization of memory in terms of sized types: signed 8 bit, unsigned 16 bit, etc.

      5. Standard Template (STL) and Standard C Library

      6. These are a standard ANSI set of container classes, algorithms, iterators, file access capabilities, math functions and other primitives.

      7. Abstract Thread and Synchronization Classes

      8. An OS independent thread class is provided. Synchronization of the threads and control over sharing of resources is provided through abstract Semapahore, Mutex, and Trigger classes (OSThread, OSSemaphore, OSMutex, OSTrigger).

      9. Abstract Modem, Abstract Go Modem Protocol
      These classes provide a standardized modem interface and Go Modem Protocol that runs over a modem. The Go Modem Protocol allows go programs and go players to compete over phone lines.
    3. GUI Portability
GUI portability will be provided by these means: Further abstractions of windows or specific controls has not been done in this implementation.

Much work remains to be done here, or a 3rd party solution adopted. The current implementation is not windows based.

  1. Conclusions
This architecture was implemented and runs on AIX 4.1, Solaris 2.x, Window NT. It successfully provides an environment for Go programming development and exploration primarily through the ability to quickly add different sorts of opponents to serve as a baseline for measuring progress.

It successfully encapsulates interfaces to all the current Go game playing interfaces, local or remote, human or program, GUI or not.