Write a program that plays Marienbad. Assigned 31 May 2002
Start with the following configuration of sticks: | | | | | | | | | There are two players. Each turn, a player can take one or more sticks from a single row. The player cannot take sticks from different row during the same turn. The player taking the last stick wins. (Traditionally, the player taking the last stick loses, but in this case, the winning strategy is harder to describe.) First player takes 3 sticks from the top row: | | | | | | Second player takes 3 sticks from middle row: | | | First player takes 1 stick form last row: | | Second player takes all the remaining sticks and wins.
Proceed in three phases:
(3) | | | | | (2) | | | (1) | move? 3 2 (3) | | (2) | | | (1) | move?Here is a sketch of the file Board.java which you will implement:
class Board { private final static int BOARD_SIZE = 3 ; // BOARD_SIZE is 3 or 4. int [] board = new int [BOARD_SIZE] ; Board( ) { // initialize the array board. } void printBoard() { } boolean move( int row, int number ) { // returns true on legal move and updates board // returns false of illegal and leaves board unchanged } boolean isDone() { // returns true if there are no more sticks } }
Add the method void playSimpleStrategy() to the class.
Write the method void playWinningStrategy() which implements a winning strategy. One such strategy was given in class. For this strategy, the methods needed are: method int -> int[] e.g. 5 -> {1,0,1} method int [] -> int, eg. {1,0,1} -> 5 method int [], int [] -> int [] e.g. {1,1,0}, {1,0,1} -> {0,1,1} method int [] -> boolean , return true only when {0,0,0}, else false - method evalute which returns boolean, using all these things, if you are "on" strategy - method to enumerate all possible moves starting from the current game - method using both to find a winning move; if fails, use previous arbitrary move method.