Week 12: Exercises

1. Wythoff's Game

A certain game is played as follows. A chess queen is placed on a 8 x 8 chessboard, two squares 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.

a) Write a graphical program that displays an 8 x 8 chessboard. The program should allow two players to play Wythoff's Game. A player should be able to click a square to move to that square. Animate the motion of the queen between squares. The chessboard should look roughly like this:

Use this image of a queen, which is 80 x 80 pixels with a transparent background:

b) Extend your program so that if the user holds down the space bar, show which squares are winning: each square should be colored red if the player whose turn it is to move can always win from that square, blue otherwise.

2. Moving Squares

a) Write a GTK program that displays 10 colored squares in random positions. When the user presses the spacebar, all squares should move to a new random position. Animate the movement of the squares. All squares should arrive at their destination positions at the same time.

b) Modify your program so that each square accelerates and decelerates as it moves, rather than moving at a constant velocity.