Week 13: Exercises

1. Button Game

Consider the following game. There is a row of N squares, each containing some positive integer. A button begins on the leftmost square. On each player's turn, they can move the button right either (a) one square or (b) by k squares, where k is the number currently under the button. The winner is the player who first moves the button past the rightmost square. Write a method that takes an array containing the numbers on the board, and returns a boolean which is true if the first player can always win.

2. Coin Game

Consider the following game. There is a row of N coins on the table, with values V1, V2, ... VN. On each player's turn, they can take either the first coin in the row or the last coin in the row. Write a method that takes an array with the values of the coins, and returns the maximum amount of money that the first player can win if both players play optimally.

3. Wythoff's Game

A certain game is played as follows. A chess queen is placed on a 8 x 8 chessboard, one square below the upper left corner. Two players alternate moves. On each player's turn, they must move the queen by any number of squares in one of three directions: either rightward, downward, or diagonally down and to the right. The first player to move the queen into the lower-right corner wins.

With perfect play, will the first player win or lose? Write a program to determine the answer.

4. Visual Wythoff

Write a Windows Forms program that displays an 8 x 8 chessboard. Each square should be colored red if the player whose turn it is to move can always win from that square, blue otherwise.

5. Ghost

Consider the following game. Let W be a set of words, each containing only lowercase letters from 'a' to 'z'. Two players take turns adding a letter to a string S, which is initially empty. A player loses if after their turn either

  1. they have made a word (i.e. S is a word in W), or

  2. no more words are possible (i.e. S is not a prefix of any word in W).

For example, suppose that W = { "chirp", "cat", "dark", "dog", "donate", "donut" }. The game might proceed as follows:

  1. A chooses d

  2. B chooses o

  3. A chooses n

  4. B chooses u

Now A has lost: if he chooses 't' he has made the word 'donut', and he cannot choose any other letter since then no other word will be possible.

Write a method that takes an array of strings (the set W) and returns a boolean which is true if the first player can always win the game.

6. Hexapawn

The game of Hexapawn is played on an N x N chessboard. Each player starts with N pawns on one side of the board. Like in chess, a pawn can move forward one square, or capture by moving forward and diagonally left or right. Unlike in chess, a pawn cannot move two squares forward on its first move. A player loses if they have no legal moves or the other player's pawn reaches the end of the board.

With perfect play, will the first player win or lose if N = 3? If N = 4? Write a program to determine the answer.

7. Visual Hexapawn

Write a Windows Forms program that lets a player play Hexapawn versus the computer.