Week 13: Exercises

1. Polynomials

Design and implement a C# class Polynomial representing a polynomial of a single variable. Your class should include the following:

2. Double-Ended Queue

Design and implement a C# class Deque<T> that implements a deque (i.e. a double-ended queue) using a doubly-linked list. Your class should include the following:

3. Counting Dequeue

Also write a subclass CountingDeque<T> that keeps track of the total number of values that have ever been pushed to a deque. The subclass should include a read-only property totalPushes that returns this value.

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

5. Box Stacking

You are given a set of N boxes. Each box i has height hi, width wi and depth di. Write a program that determines the maximum possible height of any stack of boxes, assuming that you can place box b on box c only if wb > wc and hb > hc.

6. Drawing Squares

Write an application that lets the user draw squares by dragging the mouse. Each square should have a random color. If the user clicks on an existing square, they can drag it to a new position, and it should rise to the top of the Z-order.

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

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

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

10. Visual Hexapawn

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