Prog 6: Undo
Using either your solution or my solution to program 5 (available on Piazza), now store all game information after each move, allowing undoing moves back to the beginning of the game, as long as the player is still alive. Once the player in the game dies, the program exits and moves cannot be undone. This must be implemented using a linked list.
Suggestions
Create a struct (or a class) Node to store the game component information along with a pointer to the next node.
At the beginning of the game when you first create the list, you add node to the list containing the starting configuration. This node should always be on the list.
In the program main loop, at the end, once you increment the move number, then add a new node to the list.
When user input is 'u' to undo, restore the game information from the most recent list node, and then remove that node from the list. Attempting to undo when at move 1 should not be allowed and should display the error message: "
User input of 'R' to reset board component positions should also result in those new positions also being stored on the current list Node (not a new Node).
Note that for this program we will not be grading on programming style, and will only be grading on correct program execution. No late submissions will be accepted.
Running the program should like like the following:
You are in room 13. You smell a stench. 1. Enter your move (or 'D' for directions): p ______18______ / | \ / _9__ \ / / \ \ / / \ \ 17 8 10 19 | \ / \ / \ / | | \ / \ / \ / | | 7 1---2 11 | | | / \ | | | 6----5 3---12 | | | \ / | | | \ 4 / | | \ | / | \ 15---14---13 / \ / \ / \ / \ / 16---------------20 You are in room 13. You smell a stench. 1. Enter your move (or 'D' for directions): R (Remember arrow value of -1 means it is with the person.) Enter the 7 room locations (1..20) for player, wumpus, bats1, bats2, pit1, pit2, and arrow: 1 2 4 12 6 10 -1 You are in room 1. You smell a stench. 1. Enter your move (or 'D' for directions): u Sorry, you can't undo past the beginning of the game. Please retry. You are in room 1. You smell a stench. 1. Enter your move (or 'D' for directions): m 5 You are in room 5. You feel a draft. You hear rustling of bat wings. 2. Enter your move (or 'D' for directions): u You are in room 1. You smell a stench. 1. Enter your move (or 'D' for directions): m 8 You are in room 8. 2. Enter your move (or 'D' for directions): m 9 You are in room 9. You feel a draft. 3. Enter your move (or 'D' for directions): u You are in room 8. 2. Enter your move (or 'D' for directions): u You are in room 1. You smell a stench. 1. Enter your move (or 'D' for directions): u Sorry, you can't undo past the beginning of the game. Please retry. You are in room 1. You smell a stench. 1. Enter your move (or 'D' for directions): m 5 You are in room 5. You feel a draft. You hear rustling of bat wings. 2. Enter your move (or 'D' for directions): m 6 Aaaaaaaaahhhhhh.... You fall into a pit and die. Exiting Program ...