Acro-Nim

Bart Massey
bart@cs.pdx.edu

1 The Game Of Acro-Nim

Acro-Nim (from the Latin acro, heights, hence ``High Nim'') is a Nim variant with some interesting rules.

The basic game is 1-3-5-7 Nim, with the winner taking the last stone. To review the Nim rules: Nim is a game played with (unordered) piles of stones. Players alternate in taking one or more stones from a single pile and discarding them. The player that takes the last stone from the board wins. 1-3-5-7 Nim is the variant where there are four initial piles, of size 1, 3, 5 and 7.

Acro-Nim has four specific rules that alter the basic Nim game.

Pass Rule: Anytime a player takes three or more stones from a pile, the player receives a pass token. On any turn, a player with a pass token may turn in a pass token rather than taking any stones. If both players pass in succession, the game is terminated and scored a draw.
Poison Stone: One of the stones in the initial pile of seven stones is the poison stone. Any player taking the poison stone, without taking at least one other stone from the pile, immediately loses the game (even if the poison stone is the last available stone).
Equalizer Rule: Once per game, a player may on their turn choose to equalize the piles rather than taking any stones. To equalize the piles, the player rearranges the stones in the piles so that all piles are as even in size as possible. If the poison stone is present, and the arrangement is uneven, the poison stone should be part of one of the larger piles.
Split Rule: Once per game, a player may on their turn choose to split a pile of two or more stones rather than taking any stones. To split a pile, it is split into two piles, with the stones divided as evenly as possible. A pile containing the poison stone may not be split.

2 A Z Specification Of Acro-Nim

The Z formal specification notation is described elsewhere. In this section, it will be used to formalize the rules of Acro-Nim.

The state of a game of Acro-Nim consists of the state of the board and of two players. We will call these players North and South, and let South move first.

The Acro-Nim board consists of piles of stones. We will model these piles using schema. There are no empty piles: a pile ceases to exist when its last stone is removed. Our board design urges to keep track of whether a pile contains poison stones or not as part of the pile state. While the rules given above mention only one poison stone, it is convenient to generalize the specification to handle other initial positions.
\begin{schema}{Pile}
stones: \nat_1 \\
poisoned: \nat
\where
poisoned \leq stones
\end{schema}
The board is a set of piles.
\begin{schema}{Board}
piles: \power Pile
\end{schema}

The initial board is the 1-3-5-7 board with the 7 pile containing one poisoned stone, described above. A helper function is useful to generate the piles.
\begin{axdef}
make\_pile: \nat_1 \cross \nat \fun Pile
\where
\forall n: \nat_...
...ake\_pile(n,np) = p \iff \\
\t2 p.stones = n \land p.poisoned = np
\end{axdef}

\begin{schema}{InitBoard}
Board
\where
piles = \{ make\_pile(1,0), make\_pile(3,0), \\
\t1 make\_pile(5,0), make\_pile(7,1) \}
\end{schema}

The player state consists of the set of resources available to the player. While the game as described above only allows a single equalizer or split, it is convenient to generalize the specification to allow other initial states and/or rules.
\begin{schema}{Player}
equalizes, splits, passes: \nat
\end{schema}
The initial player state is as described.
\begin{schema}{InitPlayer}
Player
\where
equalizes = 1
\also
splits = 1
\also
passes = 0
\end{schema}

It will be necessary to have a record of move types, and of the state of play. It is also necessary to name the players.
\begin{zed}
MOVE ::= move\_take \ldata Pile \cross \nat_1 \cross \nat \rdata \v...
...game\_continues \vert game\_won \ldata PLAYER \rdata \vert game\_drawn
\end{zed}
The game state consists of the board state, the state of each player, a record of the last move type (for the draw rule), and an indication of the state of play.
\begin{schema}{GameState}
Board \\
player: PLAYER \fun Player \\
to\_move: PLAYER \\
last\_move: MOVE \\
play: PLAY
\end{schema}
The initial state is as described above.
\begin{schema}{InitGameState}
GameState
\where
InitBoard
\also
\ran player = ...
... south
\also
last\_move = move\_none
\also
play = game\_continues
\end{schema}

The moves in Acro-Nim are all transformations on the game state. The player on move alternates.
\begin{schema}{Move}
\Delta GameState
\where
play = game\_continues
\also
to\_move' = OPPONENT~to\_move
\also
player'~to\_move' = player~to\_move'
\end{schema}
There are four distinct types of move.

To conveniently annotate the various types of moves, it is useful to formalize the notion of a player state adjustment.
\begin{axdef}
adjust\_player: Player \fun (\nat \cross \nat \cross \nat) \fun P...
... p'.splits = p.splits + ns \land \\
\t2 p'.passes = p.passes + np)
\end{axdef}

A take move takes a selected number of (poisoned and/or non-poisoned) stones from a selected pile according to the rules of Nim. A pile disappears when its last stone is taken. The poison stone has to be handled carefully.
\begin{schema}{MoveTake}
Move \\
p?: Pile \\
n?, np?: \nat
\where
p?.stone...
...\ELSE game\_continues
\also
last\_move' = move\_take~(p?, n?, np?)
\end{schema}

If the player has a pass token, they may pass. If the previous move was a pass, then the game is drawn. Otherwise, play continues in the same board state.
\begin{schema}{MovePass}
Move
\where
piles' = piles
\also
(player'~to\_move)....
...rawn \\
\t1 \ELSE game\_continues
\also
last\_move' = move\_pass
\end{schema}

A sensible way to handle split and equalizer moves is to construct a function that levels a set of piles. This function proceeds in two phases. First, the set of piles is combined into a single big pile containing all the stones.
\begin{axdef}
pile\_up: \power Pile \fun Pile
\where
\forall p: Pile @ \\
\t...
...nes + q.stones \land \\
\t2 p'.poisoned = p.poisoned + q.poisoned)
\end{axdef}
Next, the big pile is split into the requested number of smaller piles. The piles are split as evenly as possible, as are the poison stones: the poison stones are placed in the larger piles if possible.
\begin{axdef}
level\_piles: \nat_1 \fun \power Pile \fun \power Pile
\where
\f...
... level\_piles~(n-1)~\{q\}) \implies \\
\t2 ps' = level\_piles~n~ps
\end{axdef}

If the player has not consumed all of their splits, they may select a pile of two or more stones containing no poison stones and split it as evenly as possible.
\begin{schema}{MoveSplit}
Move \\
p?: Pile
\where
p?.stones \geq 2
\also
p?...
...ayer~(player~to\_move)~(0,-1,0)
\also
last\_move' = move\_split~p?
\end{schema}

Finally, if the player has not consumed all of their equalizes, they may pile up all the stones and split them as evenly as possible into the same number of piles they started with.
\begin{schema}{MoveEqualize}
Move
\where
piles' = level\_piles~(\char93  piles...
...ayer~(player~to\_move)~(-1,0,0)
\also
last\_move' = move\_equalize
\end{schema}

A legal game of Acro-Nim consists simply of those moves described above that are legal in the given state.
\begin{zed}
InitGame \defs InitGameState
\also
Game \defs MoveTake \lor MovePass \lor \\
\t1 MoveSplit \lor MoveEqualize
\end{zed}
The terminal states are those which have no successor because the game is over.



Bart Massey 2002-05-05