A Networked Awari Referee: Specification

Bart Massey

August 10, 2000

The many variants of the African game Awari are among the oldest known games of intellectual skill. In this document, we will describe a networked server to which human and computer players can connect to play the game in a refereed fashion.

1 The Game Of Awari

The rules of awari are complicated and have many variants. This discussion is based on the excellent summary of Schaeffer et al. [3].

Awari is a two player game, played by players conventionally designated as north and south.

PLAYER ::= north | south

opponent : PLAYER \underrightarrow{↣} PLAYER

opponent north = south opponent south = north

The board, shown in figure 1, consists of 12 pits into which a number of stones are placed. In addition, two end pits, or awari, contain stones captured by the two sides during play. Starting from the NE corner and moving counterclockwise, the pits are named by the letters a through f , first in lowercase and then in uppercase. This convention is sensible, since the fundamental sowing operation described below moves counterclockwise.

PIT ::= a | b | c | d | e | f | A | B | C | D | E | F

pit order : seq PIT next : PIT \underrightarrow{↣} PIT prev : PIT \underrightarrow{↣} PIT

pit order = ⟨a, b, c, d, e, f , A, B, C , D, E, F ⟩

∀ p : PIT • next p = pit order(((pit order^{∼}) p) mod 12 + 1)

prev = next^{∼}

The board starts with 48 stones, and stones are never lost from the game: all 48 must always be somewhere. It is thus useful to talk about the the total contents of a set of pits: more generically, about the total sum over the range of some relation.

a f  e  b d c A B C D E F

Figure 1: Awari Board In Initial Configuration

[X ]

Σ : (X ↔ ℕ) → ℕ

Σ∅ = 0 ∀ r : X ↔ ℕ; x : X ; n : ℕ | (x ↦ n) ∈ r •

Σr = n + Σ(r \ {x ↦ n})

The state of the board at any given time is essentially just the number of stones in each pit. The players alternate moves.

BOARD == PIT → ℕ SCORE == PLAYER → ℕ

AwariBoard board : BOARD score : SCORE to move : PLAYER

Σboard + Σscore = 48

Each pit initially contains 4 stones, as shown in figure 1. The south player moves first.

InitAwariBoard AwariBoard′

board′ = PIT × {4} score′ = PLAYER × {0} to move′ = south

The players alternate in sowing the stones in a pit of their choice on their side of the board. (north owns pits a–f , and south pits A–F .)

side : PLAYER \underrightarrow{↣} ℙ PIT

side north = ran((1 . . 6) ◁ pit order) side south = PIT \ (side north)

A pit may be sown if it contains one or more stones: the stones are removed from the pit, and placed one at a time into subsequent pits, moving around the board in counterclockwise order. The original pit is skipped whenever it is encountered.

next skip : PIT → PIT → PIT

∀ p : PIT • next skip p = next ⊕ {prev p ↦ next p}

Thus, the sequence of pits to be sown is a prefix of the infinite cyclic sequence of pits which repeats every 11 elements after skipping the sown pit. We call this infinite sequence the trace of the sown pit.

trace : PIT → seq PIT

∀ p : PIT • trace p = (λ n : ℕ_{1} • (iter n (next skip p)) p)

Thus we can sow the stones by emptying the pit to be sown and adding a stone to each other pit for each time it is hit by sowing. The last pit filled is the first pit we will examine for possible capture below.

Sow ΔAwariBoard move : PIT to capture : PIT

∀ p : PLAYER • score p < 25 move ∈ side to move board move > 0 to capture = (trace move)(board move) board′ =

let emptied == board ⊕ {move ↦ 0};

sown == (1 . . (board move)) ◁ (trace move) •

(λ p : PIT • (emptied p) + #(sown ▷ {p}))

score′ = score to move′ = to move

When sowing a pit, if the last pebble placed makes a group of two or three, then that pit’s stones are captured and scored by placing in the capturing player’s awari. If the previous pit then contains a group of two or three stones, these stones are also captured, and so forth. Thus, the set of pits which are captured is the set of pits on the opponent’s side of the board reachable by captures from the last pit sown: This set is given by by the range of the transitive closure of the next relation restricted to the capturable elements.

[X ]

reachable : (X ↔ X ) → ℙ X → ℙ X

∀ r : X ↔ X ; xs : ℙ X • reachable r xs = ran(xs ◁ (r^{∗}))

Capture ΔAwariBoard to capture : PIT captures : ℙ PIT

captures =

let vul == dom(board ▷ {2, 3}) ∩ side(opponent to move) •

reachable (vul ◁ prev ▷ vul) {to capture}

board′ = board ⊕ (captures × {0}) score′ to move = score to move + Σ(captures ◁ board) score′(opponent to move) = score(opponent to move) to move′ = to move

The sowing of stones to capture all stones on the opponent’s side of the board is known as a grand slam, clean sweep, or grand coup. Normally, a grand slam ends the game, capturing all stones remaining on the board. The rules governing the grand slam vary widely, however: Schaeffer et. al. [3] lists a number of variations:

a) Stones may not be sown for a grand slam (unless no other move is possible).

b) The stones may be sown for a grand slam, but no capture results.

c) The stones may be sown for a grand slam, but the last pit is not captured.

d) The stones may be sown for a grand slam, but only the first pit is captured.

e) The stones may be sown for a grand slam, and all captures happen: the remaining stones on the board are awarded to the opponent.

This paper will consider only variant (e), which will be used in the August 2000 Mind Sports Olympiad [2] computer competition. The 1990–1992 Computer Olympiads [1] used variation (a). Many human players prefer the simpler version.

There are a number of possible outcomes of a (attempt to) move.

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

winner : SCORE → RESULT

∀ s : SCORE • winner s =

if s north > s south then win north else if s south > s north then win south

else draw

A game may be ended by a player being unable to move, in which case the remaining stones on the board belong to the opponent.

ClaimStones score, score′ : SCORE board : BOARD

∀ p : PLAYER • score′ p = score p + Σ(side p ◁ board)

However, a player must leave the opponent with a legal move at the start of their turn, if it is possible to do so.

A game will also be ended by repetition of position. (This is generally only true of computer play. In human play, it is more common to end by agreement of both sides.) The most common rule here is that each player captures the stones on their side of the board. One popular variant, used in the 1990–1992 Computer Olympiad, is to not count the stones left on the board at the end. To keep track of repetitions, it is necessary to keep track of the set of positions seen so far.

Positions positions : ℙ AwariBoard

To summarize the variant of interest here: a move in the game consists of altering the board and recording the resulting board position. Moves alternate between players.

AwariMove ΔAwariBoard ΔPositions opp stones : BOARD → ℕ result : RESULT

positions′ = positions ∪ {θAwariBoard} ∀ b : BOARD • opp stones b = Σ((side(opponent to move)) ◁ b)

If either player has 25 or more stones at the start of their turn, the player with the most stones wins, and the game is over.

WinMargin AwariMove

∃ p : PLAYER • score p ≥ 25 score′ = score result = winner score′

If the sowing is impossible, or the position is a repetition of a previous one, each player claims the stones on their side of the board, and the game is over.

NoMove AwariMove ClaimStones

∀ p : PLAYER • score p < 25 θAwariBoard ∈ positions ∨ Σ(side to move ◁ board) = 0 result = winner score′

If the opponent’s pits are all empty, the player must sow a pit which leaves the opponent a move if possible.

NormalMove AwariMove Sow ^{o}_{9} Capture

∀ b : BOARD • opp stones board = 0 ⇒ opp stones board′ > 0 result = not done

A grand slam capture forfeits all stones still on the board at the end of the turn.

ForfeitStones score, score′ : SCORE board : BOARD

∀ p : PLAYER • score′ p = score p + Σ(side(opponent p) ◁ board)

A grand slam is the capture the rest of the opponent’s stones.

GrandSlam AwariMove Sow ^{o}_{9} Capture ^{o}_{9} ForfeitStones

opp stones board > 0 opp stones board′ = 0 result = winner score′

A move can only be illegal if a move is available and neither side has won. An illegal move is from a pit on the wrong side of the board, a pit with no stones, or fails to feed an opponent with stones when necessary. (Note that this schema does not assume NormalMove is deterministic for a given move, although we know it to be.)

IllegalMove AwariMove

∀ p : PLAYER • score p < 25 ∃ p : side to move • board p > 0

move ∉ side to move ∨ board move = 0 ∨ opp stones board = 0 ∧

(∀ m : NormalMove | m.move = move • opp stones m.board′ = 0) ∧ (∃ m : NormalMove | m.move ≠ move • opp stones m.board′ > 0)

result = illegal move

The referee reports whether a move continues the game, ends the game, or is illegal.

AwariRef ˆ= NormalMove ∨ WinMargin ∨ NoMove ∨ GrandSlam ∨ IllegalMove

The game starts with the initial board, and no positions yet seen.

Table 1: Greeting

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

Table 2: Initial Requests

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

InitAwari InitAwariBoard Positions′

positions′ = ∅

2 Server

The Awari server listens on a port in the range 29046 … 29056 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 north and south player.

Once both a north player and a south 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

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 north 341 ⟨name⟩  North player is ⟨name⟩
config south 342 ⟨name⟩  South player is ⟨name⟩
config observer 343 ⟨number⟩ ⟨name⟩ Observer ⟨number⟩ is ⟨name⟩
config nobserver 344 ⟨number⟩  There are ⟨number⟩ observers

⟨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-north⟩ will be the string ... for a move by north and the empty string for a move by south, and ⟨move⟩ will be a move in the notation described above.

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.

The draw protocol is as one would expect: a draw may be offered by a player whose turn it is to move. If it is rejected by the other player, it may not be offered again until the next move.

References

[1] D. Levy and D. Beal, editors. Heuristic Programming in Artificial Intelligence 3: The Third Computer Olympiad. Ellis-Horwood, 1992.

[2] Mind Sports Olympiad. Web document, 2000. URL http://www.msoworld.com/mindsports.html.

[3] Jonathan Schaeffer et al. The Rules Of Awari. Web document, 1998. URL http://www.cs.ualberta.

   ca/awari/rules.html.

Table 5: Starting Messages

name response meaning
role north 351  You will play north
role south 352  You will play south
role observer 353  You will observe

Table 6: Move Syntax

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

Table 7: Alternatives To Moving

name request meaning
action resign resign  Player resigns
action draw req draw?  Player offers a draw
action draw ack draw  Player accepts a draw
action draw nak nodraw Player refuses a draw

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
result drawreq 205  Received draw request
result drawnak 206  Received draw refusal
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 south 311 ⟨move-number⟩ ⟨move⟩  South move
status moves north 312 ⟨move-number⟩ ... ⟨move⟩  North move
status moves south tc 313 ⟨move-number⟩ ⟨move⟩ ⟨secs⟩  South move and time
status moves north tc 314 ⟨move-number⟩ ... ⟨move⟩ ⟨secs⟩ North move and time
32x, 36x  Game over
status winsmove south 321 ⟨move-number⟩ ⟨move⟩  South wins by move
status losesmove south 322 ⟨move-number⟩ ⟨move⟩  South loses by move
status winsmove north 323 ⟨move-number⟩ ... ⟨move⟩  North wins by move
status losesmove north 324 ⟨move-number⟩ ... ⟨move⟩  North loses by move
status drawsmove south 325 ⟨move-number⟩ ⟨move⟩  Drawn by South move
status drawsmove north 326 ⟨move-number⟩ ... ⟨move⟩  Drawn by North move
status resigns north 327  South wins by resignation
status resigns south 328  North wins by resignation
status draw agreed 329  Draw accepted
status flagfell north 361  South wins by North time expiring
status flagfell south 362  North wins by South time expiring
33x  Draw protocol
status reqsdraw south 331  Draw requested by South
status reqsdraw north 332  Draw requested by North
status refsdraw south 333  Draw refused by South
status refsdraw north 334  Draw refused by North
34x  (see above)
35x  (see above)
39x  Bad status
status disconnect south 391  South disconnected
status disconnect north 392  North disconnected
status garble 399  Unknown problem