Prof. Reed, CS 102, Spring '09
Due Tuesday 12/1 at 2:00 p.m.
Description
Repeat program 4, except that moves can now be undone, back to the beginning of the game. Attempting to undo a move at the beginning of the game displays an error message, but allows continuing to play. Since this is a two-player game, selecting undo reverts the board back to the previous configuration, with the other user getting to retry their move.
Moves and the board configuration at each step should be stored on a linked list. The user interface is again text-based. Input needs to be a character rather than an integer. An entry of '1' through '9' corresponds to the move position, however the input of 'u' triggers the undoing of a move. See the video below for an example of what this program looks like when it is running.
Run this on its YouTube page. You can also run this program from within your UIC CS account by typing:
~i102/KaosLinkedList
You need to know the following concepts in order to write this program:
How to write a basic program in C, with the addition of C++ cin and cout, C++ reference parameters, and structs in C to implement a linked list. You may not use C++ classes (or Strings or template libraries). You may use the C++ style of constants.
Notes:
Eliminate all global variables. You can start with my solution if you would like, but either way, you will simplify your life if you declare the board and # of X and # of O variables in main(), and then pass them as parameters everywhere. You don't have to do this, but it might save you some trouble later.
Review the code to manipulate a linked list (see web site). You need to thoroughly go through at least one example before you try to write your own code. See sample code from the RicoRobots program #5 some years ago. If the rest of your program is already working (or you are using my solution from program #4), you shouldn't need to change it hardly at all. Mostly you will add the struct Node and the functions described below, then modify the code inside main that handles what to do when 'u' for undo is given as user input.
Start by creating the struct in your program (e.g. struct Node...). Note that this needs to be global.
Parameterize your displayBoard function. This way you can use it in debugging. Note that at this point you should not have any global variables, so in order to get your program to work you would *have* to do this anyway.
Write the function to add a node to the *front* of the linked list, e.g. function addNode(....)
Write the function to remove a node from the front of the linked list, making that board (etc.) the current board, e.g. function removeNode(...)
In main initialize the linked list head pointer to be NULL.
In your main loop after prompting for user input, check and see if 'u' for "undo" was entered. If 'u' was entered, then check if there is a node on the list. If not, give an error message. If there is one or more nodes on the list, then call your function to remove a node from the list, updating the list head pointer.
After a valid move, after the move number has been updated, add the current node to the front of the linked list by calling your addNode(...) function.
Turnin your program electronically using the "turnin" command from your CS account as follows:
turnin -c cs102 -p prog5 KaosList.cpp
where the file containing your solution is called KaosList.cpp.