Prog 6 Mancala List
Modify your solution to the previous Mancala program (or mine if you didn't get it finished) to have the following additional features:
Undo moves using a linked list:
Store the human's moves on a linked list. User input of 'u' to undo a move resets the board back to the previous move, allowing the human to retry that move. I suggest you look at linked list solutions I have posted for similar previous semester assignments, such as the Fall '11 crossword puzzle.
User input handling:
Also add handling user input of 'x' to exit your program. Add error checking so that only valid characters ('A'..'F' or 'U' or 'X') are accepted for user input. Your program should accept both upper and lower case input. Undo and exit can only be chosen at the beginning of a user move.
Implement command line parameters
Use argc argv inside the parenthesis of main( ) so that you can more easily test your program by starting off the game with any board configuration you would like. See this sample program.
Samples of the above steps are given below. Also included as attachments to this page are executable versions of the program, for PC (585K, reset extension to .exe) and for Mac (20K OS X 10.8.2 on Intel processor).
Undoing moves using a linked list
Author: Dale Reed Program 5: Mancala TA: Susan Rice, Wed 7am Nov 27, 2012 Welcome to the game of Mancala, where you are playing against a computer opponent. You may enter 'u' to undo a move or 'x' to exit. Your holes are on the bottom row and you get to go first. A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 3 |---- | | | | ----| 3 | 3 | 3 | 3 | 3 | 3 |---- ----------------------------- A B C D E F ------------------------------------------- 1. Select a move (A..F)-> e A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 4 |---- | | | 1 | ----| 3 | 3 | 3 | 3 | | 4 |---- ----------------------------- A B C D E F ---------------------------------------- Computer chooses C A B C D E F ----------------------------- ----| 4 | 4 | | 3 | 3 | 4 |---- | 1 | | 1 | ----| 3 | 3 | 3 | 3 | | 4 |---- ----------------------------- A B C D E F Computer gets another move Computer chooses A A B C D E F ----------------------------- ----| | 4 | | 3 | 3 | 4 |---- | 2 | | 1 | ----| 4 | 4 | 4 | 3 | | 4 |---- ----------------------------- A B C D E F ------------------------------------------- 2. Select a move (A..F)-> u Undo was selected. Restoring game back to previous move. A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 3 |---- | | | | ----| 3 | 3 | 3 | 3 | 3 | 3 |---- ----------------------------- A B C D E F ------------------------------------------- 1. Select a move (A..F)-> u Undo was selected. Restoring game back to previous move. Sorry, you cannot undo past the beginning of the game. Please retry move. A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 3 |---- | | | | ----| 3 | 3 | 3 | 3 | 3 | 3 |---- ----------------------------- A B C D E F ------------------------------------------- 1. Select a move (A..F)->
User input handling
Author: Dale Reed Program 5: Mancala TA: Susan Rice, Wed 7am Nov 27, 2012 Welcome to the game of Mancala, where you are playing against a computer opponent. You may enter 'u' to undo a move or 'x' to exit. Your holes are on the bottom row and you get to go first. A B C D E F ----------------------------- ----| 3 | 3 | 3 | 3 | 3 | 3 |---- | | | | ----| 3 | 3 | 3 | 3 | 3 | 3 |---- ----------------------------- A B C D E F ------------------------------------------- 1. Select a move (A..F)-> g Invalid input. Please retry. 1. Select a move (A..F)-> 2 Invalid input. Please retry. 1. Select a move (A..F)-> x Exiting program before end of game...
Command Line parameters
Dales-iMac:Mancala reed$ ./Mancala -b 00000102222220 Author: Dale Reed Program 5: Mancala TA: Susan Rice, Wed 7am Nov 27, 2012 Welcome to the game of Mancala, where you are playing against a computer opponent. You may enter 'u' to undo a move or 'x' to exit. Your holes are on the bottom row and you get to go first. A B C D E F ----------------------------- ----| 2 | 2 | 2 | 2 | 2 | 2 |---- | | | | ----| | | | | | 1 |---- ----------------------------- A B C D E F ------------------------------------------- 1. Select a move (A..F)-> f A B C D E F ----------------------------- ----| 2 | 2 | 2 | 2 | 2 | 2 |---- | | | 1 | ----| | | | | | |---- ----------------------------- A B C D E F Game is over. Remaining pieces are being placed into the store. A B C D E F ----------------------------- ----| | | | | | |---- | 12 | | 1 | ----| | | | | | |---- ----------------------------- A B C D E F Computer wins! Thanks for playing! Goodbye... Dales-iMac:Mancala reed$