Prog 6: Vexed Undo
Implement a text-based version of Vexed, similar to program4. Use a linked list to implement infinite undo back to the beginning of the game.
Note no late submissions will be accepted for program 6! Grading will be done on only the Codio assessments, with no grading for programming style. We will still run the MOSS program comparison program, to compare the parts of code that you do write.
Run my solution within Codio, and see the Codio guide for the input used in the assessments. Below is a 2.5 minute video showing what the program looks like when it runs:
Note how a representation of the linked list is shown after each move. This will help you debug your program, and provides evidence that your linked list implementation is working correctly.
The starter code supplied for you within Codio already does everything you need, except for implementing undo using a linked list. As explained in the comments in the starter code, you will need to do the following:
Create the data structures and operations used for the linked list:
//------------------------------------------------------------------------------------- // Node declaration to implement a linked list to store moves, used to implement // undo within a level. You should store the old board, the old score, the old boardIndex, // and a pointer to the next Node.class Node { // ... }; //-------------------------------------------------------------------------------- // Display the move numbers on the linked listvoid displayList( Node *pTemp) { // ... } // end displayList()//-------------------------------------------------------------------------------- // Delete the front node on the list and restore current game values from the // next node that reflects the previous move. // Parameters should be: // pointer to the head of the list, which could change, so should be a Node * reference. // the Board, which should also be a reference parameter, and is the game board to be restored from the list // the score, which should be restored from the list // the currentBoardIndex, which should be restored from the listvoid deleteNodeFromList( ) { // ... } //end deleteNodeFromList()//-------------------------------------------------------------------------------- // Create a new node and prepend it to the beginning of the list. // Parameters should be: // pointer to the head of the list, which could change, so should be a Node * reference. // the Board, which should also be a reference parameter, and is the game board to be restored from the list // the score, which should be restored from the list // the currentBoardIndex, which should be restored from the listvoid addNodeToList() { // Create a new node and store current values into it // ... // Prepend it onto the front of the list // ... }
Declare pHead to be a Node pointer, and initialize it to NULL. pHead will be used to keep track of the head of the list. Also declare pTemp to be a Node pointer. pTemp will be used in allocating new memory for new Nodes.
Immediately after creating the initial board, store it onto the linked list. Do this immediately after the comment: // Add a new Node with theBoard onto the list
This first node should always be on the list. When checking to see if the user attempts to undo a move at the beginning of the game, you will need to check to see if there is only this single node on the list.