# Wari Game

### The Game

Wari is a game played on a board that consists of 12 cups placed in two parallel rows of six cups and a large cup at each end. The game is for two players; each player has a row of six cups and one large cup for prisoners. If you want to play the game then you can try WariGame.jar.  It’s not tested and will go into stale mate but maybe you can test it for me! Initially, there are four marbles in each small cup, as shown below.

Player A uses cups 1 to 6 and player B uses cups 7 to 12.

The players decide who is to go first, and the first player takes all the marbles from one of his cups and places them one at a time into successive cups in an anticlockwise direction starting with the cup immediately to the right of the emptied cup and continues round his opponent’s cups if necessary.

The second player then takes all the marbles from one of his cups and distributes them similarly in an anticlockwise direction.

Play continues until one of the players places his last marble in an opponent’s cup that contains one or two marbles (i.e. two or three marbles after distribution). The player is entitled to all the marbles in this cup as prisoners. The player removes the marbles and places them in his large cup at the end of the board. If there are also two or three marbles in the preceding cup and this cup belongs to his opponent, the player is entitled to these also. This continues until a cup is encountered, on the opponent’s side, that does not contain two or three marbles.

Now consider an example. Suppose player A goes first and removes the four marbles from cup 5 and distributes them into cups 6, 7, 8 and 9. Cup 9 does not contain two or three marbles so the turn ends. This can be represented by A(5,4).

Now suppose the following moves take place.

B(7,5), A(2,4) and B(12,5).

The position is now as shown below:

Which can also be represented as:

B’s last play was into A’s cup 5 which now has two marbles in it. These are now removed and are B’s prisoners. B places these marbles in the cup labelled B.

If twelve or more marbles are in a cup and are distributed, the twelfth marble is placed into the cup after the one from which the marbles were removed. That is, the cup from which the marbles were removed remains empty.

A player may not empty or leave empty all the cups on the opponent’s side. The player must play to leave at least one marble on the opponent’s side. If this is not possible, the player removes all the marbles from his side of the board and adds them to his prisoners and the game is over. The winner is the player with the most prisoners.

Sometimes it happens that no player can win. For example, player A has a marble in cup 3 and player B has a marble in cup 9; in this case the marbles simply follow one another round the board. In this case the players remove the marbles and add them to their prisoners and the game is over.

You are advised to play the example game using the rules given.

### The Challenge

You are to write a program that will decide the winner (if any) of a game of Wari. To do this:

• You must use a high level language. State the language and the version you use.
• You are expected to provide full annotation of your program code and to use meaningful names throughout.
• You must complete the following tasks, each of which must be presented separately, in your final submission.

(a) Write annotated code that will create data structures that will represent the board and initialise their contents.  You should include a listing of this code. [6]

(b) Design and implement an interface that will show the players the number of marbles in each cup, including the large cups. You should use the data structures from (a). A screen shot of the interface is acceptable. You should include a listing of this code. [5]

(c) Write annotated code that will get the identity of the player that is to go first or allow the game to be terminated. You should include a listing of this code and any testing that you have done. [4]

(d) Write annotated code that will get the identity of the cup that is to be emptied or an indication that the player wishes to surrender. The code should fully validate the input. You should include a listing of this code and any testing that you have done. [5]

(e) Write annotated code that will distribute the marbles when a move has been made. This code should identify and empty the cups according to the rules. The number of marbles in each cup, including the large ones, after the move is completed should be displayed ready for the next player. You should include a listing of this code and any testing that you have done. [5]

(f) Write annotated code that allows two players to play a game of Wari. The game should continue automatically until a winner is found or a player surrenders. You should include a listing of your complete code. [7]

This task was worth 32 Marks and should take ~22.5 hours.  This is a software development task and an implementation task that originally appeared in OCR 2507 Task 3 Jun 2008.  All rights and copyright to OCR.  Please refer to the OCR Copyright Statement for further information.