A Networked Gothello Referee: Specification

Bart Massey

August 13, 2003

Gothello is a game of skill created by the author for educational purposes. It is played on an ordinary checkerboard, and has something of the feel of Othello or Go. In this document, we will describe a networked server to which human and computer Gothello players can connect to play the game in a refereed fashion.

1 The Game Of Gothello

The rules of Gothello are intended to capture some of the feel of Go, while being more amenable to adversary search. Gothello is a two player game, played by players conventionally designated as black and white.

PLAYER ::= black | white

opponent : PLAYER \underrightarrow{↣} PLAYER

opponent white = black opponent black = white

The board, shown in figure 1, is an ordinary checkerboard or go board: black and white stones are placed on intersections (conventionally designated using standard algebraic notation). For the purposes of this document, the game will be played with a 5x5 array of intersections.

DIGIT == 1 . . 5 SQUARE == DIGIT × DIGIT

At any given point in the game, the board position can be given by noting whether each square is blank or contains a colored stone.

SQUAREVAL ::= stone⟨⟨PLAYER⟩⟩ | blank BOARD == SQUARE → SQUAREVAL

GothelloPosition board : BOARD to move : PLAYER

The board begins empty, and black moves first.

e d a b c 5 4 3 2 1

Figure 1: Gothello Board In Initial Configuration

InitGothelloPosition GothelloPosition′

board′ = SQUARE × {blank} to move′ = black

The players alternate in placing stones of their own color on blank spaces on the board. Stones of the same color which are connected horizontally and/or vertically are neighbors.

relation ( adjoins )

adjoins : SQUARE ↔ SQUARE

( adjoins ) = {d, d_{1}, d_{2} : DIGIT | d_{2} = d_{1} + 1 • ((d_{1}, d), (d_{2}, d))} ∪

{d, d_{1}, d_{2} : DIGIT | d_{2} = d_{1} + 1 • ((d, d_{1}), (d, d_{2}))}

neighbor : BOARD → (SQUARE ↔ SQUARE)

∀ board : BOARD •

neighbor board = {s_{1}, s_{2} : SQUARE | s_{1} adjoins s_{2} ∧

board s_{1} ≠ blank ∧ board s_{1} = board s_{2}}

A maximal set of mutual neighbors is a group. It is most useful to talk about the group containing some specific board position in a given board.

group : BOARD → SQUARE → ℙ SQUARE

∀ board : BOARD; s : SQUARE | board s ≠ blank • group board s = (neighbor board)^{+}(|{s}|)

The other key concept in the rules is the concept of liberties of a group. These are the blank squares immediately surrounding the group. The liberties of a position are the liberties of the group at that position.

adjoining squares : ℙ SQUARE → ℙ SQUARE group liberties : BOARD → ℙ SQUARE → ℙ SQUARE liberties : BOARD → SQUARE → ℙ SQUARE

∀ ss : ℙ SQUARE •

adjoining squares ss = ( adjoins )(|ss|) \ ss ∀ board : BOARD; ss : ℙ SQUARE •

group liberties board ss = adjoining squares ss ∩ board^{∼}(|{blank}|) ∀ board : BOARD •

liberties board = (group liberties board) ∘ (group board)

There are a number of possible outcomes of a player’s turn.

RESULT ::= win⟨⟨PLAYER⟩⟩ | draw | not done | illegal move

A player may pass on any turn, and must pass if no legal move is available. The game is over when both players have passed in succession. This is a function of the immediate history of the game (i.e., the sequence of moves that have been made recently).

MOVE ::= move⟨⟨SQUARE⟩⟩ | pass HISTORY == seq MOVE

GothelloGame GothelloPosition history : HISTORY

InitGothelloGame InitGothelloPosition history′ : HISTORY

history′ = ∅

In short, when the Gothello referee receives an action, it gets a move, records it in the history, and report the result.

GothelloAction ΔGothelloGame move? : MOVE result! : RESULT

history′ = ⟨move?⟩ ⌢ history

A move is illegal if it is to an occupied space,

GothelloIllegalMoveNonblank GothelloAction ΞGothelloPosition

result! = illegal move ∃ s : SQUARE •

move? = move s ∧ board s ≠ blank

or if the stone placed becomes part of a group with no remaining liberties.

GothelloIllegalMoveBlocked GothelloAction ΞGothelloPosition

result! = illegal move ∃ s : SQUARE; cboard : BOARD •

move? = move s ∧

cboard = board ⊕ {s ↦ (stone to move)} ∧

#(liberties cboard s) = 0

Otherwise, a non-pass move will capture any opposing groups which have their last liberty removed, changing the color of these groups.

GothelloMove GothelloAction cboard : BOARD capture at, captures : SQUARE → SQUARE \underrightarrow{}SQUAREVAL

result! = not done ∀ s : SQUARE •

capture at s = if #(liberties cboard s) = 0 then(group cboard s) × {stone to move} else ∅

∀ s : SQUARE • captures s = ⋃(capture at(|(neighbor cboard)(|{s}|)|))

∃ s : SQUARE • move? = move s ∧ board s = blank ∧ cboard = board ⊕ {s ↦ (stone to move)} ∧ #(liberties cboard s) > 0 ∧ board′ = cboard ⊕ (captures s)

to move′ = opponent to move

For a pass, there are two possible outcomes. If the opponent did not also just pass, the game continues.

GothelloPass GothelloAction ΞGothelloPosition

result! = not done move? = pass history 1 ≠ pass to move′ = opponent to move

Otherwise, the game is over, with the result determined simply by which player has the most stones on the board.

GothelloGameOver GothelloAction ΞGothelloPosition black stones, white stones : ℕ

result! = if black stones > white stones then win black else if white stones > black stones then win white else draw

move? = pass history 1 = pass black stones = #(board ▷ {stone black}) white stones = #(board ▷ {stone white})

A Gothello turn consists of any one of the five possible transitions

GothelloTurn ˆ= GothelloIllegalMoveNonblank ∨ GothelloIllegalMoveBlocked ∨ GothelloMove ∨ GothelloPass ∨ GothelloGameOver

The proof that these rules are well-founded remains to be completed. The initial state is well-defined. The five possible transitions in a Gothello turn are disjoint. It seems straightforward to show that one of the five transitions applies in every situation, and that the definition of each transition is well-founded and deterministic, which would essentially complete the proof.

Table 1: Greeting

name  response  meaning ; greeting 000 Gothello ⟨version-number⟩ Greeting message

Table 2: Initial Requests

name request meaning
want white ⟨version⟩ player white ⟨optional-name⟩ Will play white
want black ⟨version⟩ player black ⟨optional-name⟩ Will play black
want side ⟨version⟩ player ? ⟨optional-name⟩  Will play either
want observe ⟨version⟩ observer ⟨optional-name⟩  Will observe

2 Server

The Gothello server listens on a port in the range 29068 … 29077 for a connection.^{1} All input to the server will be in the form of ASCII text lines, terminated with a CR character (ASCII code 13). All server responses will be in the form of ASCII text lines, terminated with a CR and then an LF character (ASCII code 10). Responses will begin with a 3-digit numerical code, and be followed by whitespace and a (non-standard) explanatory text message. Requests and responses not currently implemented by the server will have their identifier in italics: those implemented will have boldface identifiers.

Any number of observers may connect to the server, as well as the two players. The server will always be in a state determined by the input it has seen. This state will determine which messages it will accept, and which responses it will return. The server may be in different states for different connections: it must synchronize the connections at key points.

STATE ::= initial | seated | playing | done

ENTITY ::= player⟨⟨PLAYER⟩⟩ | observer⟨⟨ℕ_{1}⟩⟩

observer ∈ seq ENTITY

cstate : ENTITY \underrightarrow{}STATE

Upon connection to the server, an entity will receive a greeting in the form indicated by Table 1. The version number is a pair of integers separated by a decimal point. This document describes version 0.9.

The initial message sent to the server must be as shown in Table 2. Responses are shown in Table 3. The ⟨optional-name⟩ is an optional double-quoted string (with the convention that two consecutive double-quotes ”” inside the string escape to a single double-quote ”) of up to 31 characters used to identify the entity. The version number is as above, and is used to identify the client version. The client version must be no greater (under the usual ordering) than the server version. If both players indicate “player ?”, the server will randomly select a white and black player.

Once both a white player and a black player have connected, the setup phase will be over. The server may indicate to each entity the other entities involved, by sending messages as shown in Table 4. ⟨name⟩ and ⟨optional-name⟩ are double-quoted strings as described below. ⟨number⟩ is a decimal number. (All entities should be prepared to deal with numbers up to 3 decimal digits, and to discard an arbitrary number).

The server will then signal the start of game by sending a message to each connected entity, as shown in Table 5.

After this, the server will accept moves from players in alternation, of the form shown in Table 6, where the ⟨move number⟩ is a standard decimal number indicating the ply of the move, the ⟨ellipses-if-white⟩ will be the string ... for a move by white and the empty string for a move by black, and ⟨move⟩ will be a move

1All numbers in this section will be base 10 (decimal) unless otherwise stated.

Table 3: Initial Responses

name response meaning
seat granted 100  Request accepted
seat granted tc 101 ⟨secs⟩ ⟨opp-secs⟩ Request accepted with time controls
19x  Request not accepted
seat taken 191  Other player holds requested side
seat full 192  There are already two players
seat private 193  Cannot observe
seat illegal 198  Illegal version number
seat garbled 199  Request not understood

Table 4: Configuration Messages

name response meaning
config white 341 ⟨name⟩  White player is ⟨name⟩
config black 342 ⟨name⟩  Black player is ⟨name⟩
config observer 343 ⟨number⟩ ⟨name⟩ Observer ⟨number⟩ is ⟨name⟩
config nobserver 344 ⟨number⟩  There are ⟨number⟩ observers

in algebraic notation.

Instead of a move, the following inputs may also be accepted as shown in Table 7. Responses to actions are shown in Table 8.

After each accepted action, a message will be sent to each connected entity, as shown in Table 9. Upon termination of the game, the server will close all connections.

If the participant is an observer, every status message will be followed by two state display messages showing the current state of the game, as in Table 10. The times will be in seconds, and the ⟨to-move⟩ value will be either “b”, “w”, or “.” indicating Black, White, or the game is over. The sdisp board message will be immediately followed by 5 lines of 5 printable characters indicating the board state. Each character will be as above: “b”, “w”, or “.” indicating a blank square.

Table 5: Starting Messages

name response meaning
role white 351  You will play white
role black 352  You will play black
role observer 353  You will observe

Table 6: Move Syntax

name  request  meaning ; action move ⟨move number⟩ ⟨ellipses-if-white⟩ ⟨move⟩ Make a move

Table 7: Alternatives To Moving

name request meaning
action resign resign  Player resigns
action pass pass  Player passes

Table 8: Responses To Actions

name response meaning
20x  Action accepted
result continue 200  Continue playing
result continue 207 ⟨secs⟩ Continue with time left
result win 201  You win
result lost 202  You lose
result drawn 203  You draw
result resigned 204  Resignation accepted
29x  Action not accepted
result illegal 291  Illegal request
result garbled 299  Request not understood

Table 9: Status Messages

name response meaning
31x  Game continues
status moves black 311 ⟨move-number⟩ ⟨move⟩  Black move
status moves white 312 ⟨move-number⟩ ... ⟨move⟩  White move
status moves black tc 313 ⟨move-number⟩ ⟨move⟩ ⟨secs⟩  Black move and time
status moves white tc 314 ⟨move-number⟩ ... ⟨move⟩ ⟨secs⟩ White move and time
status passes black 315 ⟨move-number⟩ pass  Black passes
status passes white 316 ⟨move-number⟩ ... pass  White passes
status passes black tc 317 ⟨move-number⟩ pass ⟨secs⟩  Black pass and time
status passes white tc 318 ⟨move-number⟩ ... pass ⟨secs⟩  White pass and time
32x, 36x  Game over
status winsmove black 321 ⟨move-number⟩ ⟨move⟩  Black wins by move
status losesmove black 322 ⟨move-number⟩ ⟨move⟩  Black loses by move
status winsmove white 323 ⟨move-number⟩ ... ⟨move⟩  White wins by move
status losesmove white 324 ⟨move-number⟩ ... ⟨move⟩  White loses by move
status drawsmove black 325 ⟨move-number⟩ ⟨move⟩  Drawn by Black move
status drawsmove white 326 ⟨move-number⟩ ... ⟨move⟩  Drawn by White move
status resigns white 327  Black wins by resignation
status resigns black 328  White wins by resignation
status flagfell white 361  Black wins by White time expiring
status flagfell black 362  White wins by Black time expiring
34x  (see above)
35x  (see above)
39x  Bad status
status disconnect black 391  Black disconnected
status disconnect white 392  White disconnected
status garble 399  Unknown problem

Table 10: State Display Messages

name response meaning
38x  state display
sdisp status 380 ⟨move-number⟩ ⟨to-move⟩  state
sdisp status tc 381 ⟨move-number⟩ ⟨time-b⟩ ⟨time-w⟩ ⟨to-move⟩ state and time
sdisp board 382  board