IN3013/INM173 - Object-Oriented Programming in C++
This coursework involves defining and using a template class. The application is to extend a simple text-based solitaire game. It is due on Tuesday 2nd March, and counts for 10% of the marks for the module.
Copy the file pegs.cc into a new directory and compile it. If you run the program, it will display the output
1 2 3 4 5 6 7 8 9
1 * * *
2 * * *
3 * * *
4 * * * * * * * * *
5 * * * * - * * * *
6 * * * * * * * * *
7 * * *
8 * * *
9 * * *
and wait for input.
This represents a classic solitaire game played with pegs in a board.
An asterisk (*) indicates a peg,
while a hyphen (-) indicates an empty hole.
There are 9 rows and columns, each numbered 1-9.
A move consists of moving a peg over an adjacent peg to a vacant hole on the other side. This continues until no move is possible. For example, in the initial configuration above, there are 4 possible moves:
r 5 3
(move right from row 5, column 3)
and the program will respond by printing the new configuration
1 2 3 4 5 6 7 8 9
1 * * *
2 * * *
3 * * *
4 * * * * * * * * *
5 * * - - * * * * *
6 * * * * * * * * *
7 * * *
8 * * *
9 * * *
Each command consists of a direction
(l, r, u or d)
and a row and column number of the peg to move.
The program will carry out the move if it is legal,
and object if it is not.
You are to add to this program the ability to back out of moves, and to redo them.
For an intuition into this structure, check the way the history works in your favourite web browser. Abstractly, a history is a sequence of items, with a current position in this sequence. Undo and redo involves moving the current position back and forwards. Adding an item discards everything forwards of the current position. You will probably also need methods to return the current item, and to test whether is it possible to move back or forwards.
Your first task is to implement a history as a generic container.
If you wish, you may work on and submit this coursework in pairs. Undeclared pairs will be referred to the academic misconduct procedure - ``We worked together'' will not be an excuse.
A pair should submit a single solution, with both names on it. A pair submission will obtain approximately 95% of the marks that an identical single submission would have obtained, so pairs are expected to do slightly more work than singles:
Individuals should not do this extra task.
You don't have to what you did last time, and submitting as a pair (or a single) for this coursework does not commit you for the remaining coursework.