Week 11: Exercises

1. 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.

2. Bouncing Ball

Write an application that displays a bouncing ball. The ball should lose a bit of velocity each time it hits the ground, so that it eventually comes to a stop.

3. Bouncing Balls

Extend the previous application so that the user can create new balls by clicking the mouse. Each ball should have a random size and color. All the balls should bounce simultaneously.

4. Starfield

Write a program that displays a black background with 50 random stars, which appear as small white dots.

5. Spaceship

Extend the previous program so that a triangular spaceship appears at the center of the starfield. The user should be able to rotate the ship by holding down the left and right arrow keys.

6. Moving Spaceship

Extend the previous program so that the spaceship can move. If the user holds the up arrow key, the ship should accelerate forward in the direction that it's currently pointing. If they release it, the ship should decelerate until it comes to a halt.

7. 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.

8. Hex

Implement the game of Hex, with a user interface in GTK. Use a model-view architecture.

9. Hex AI

Implement an AI player for Hex.