Prog 2: Peg Jump
1/30 Clarifications made are shown in blue.
1/31 Turn-in naming conventions are similar to that of program 1, and are shown at the bottom in red.
Write a program to play a peg jumping game (examples can be played online here and here). Running the program looks like what is shown below, where the boldfaced text is something that you type in.
Author: Dale Reed Assignment: 2, PegJump TA: Karla Templar, Tues 10 Jan 25, 2017 This program represents the peg jumping puzzle. The board starts out with a single blank position, represented by the 'O'. To make a move, select the letter of the peg to be moved, then the letter of the destination position. (e.g. the first move might be: d a, meaning we move peg ‘d’ into blank position ‘a’.) A peg must be able to jump over an adjacent peg into a blank for a move to be valid. The jumped peg is then removed from the board. The game is over when there are no valid moves left to be made, or when there is a single peg left. At any point enter 'x' to exit the program. ----------------------- Board Positions o A + + B C + + + D E F + + + + G H I J + + + + + K L M N O 1. Enter your move: D a ----------------------- Board Positions + A o + B C o + + D E F + + + + G H I J + + + + + K L M N O 2. Enter your move: K D ----------------------- Board Positions + A o + B C + + + D E F o + + + G H I J o + + + + K L M N O 3. Enter your move: i g ----------------------- Board Positions + A o + B C + + + D E F + o o + G H I J o + + + + K L M N O 4. Enter your move: n p *** Invalid destination. Please retry **** 4. Enter your move: q n *** Invalid source. Please retry **** 4. Enter your move: j h *** Must jump a piece. Please retry. *** 4. Enter your move: b i *** Source must have a piece. Please retry. *** 4. Enter your move: l n *** Destination must be empty. Please retry. *** 4. Enter your move: g b ----------------------- Board Positions + A + + B C o + + D E F o o o + G H I J o + + + + K L M N O 5. Enter your move: a d ----------------------- Board Positions o A o + B C + + + D E F o o o + G H I J o + + + + K L M N O 6. Enter your move: c h ----------------------- Board Positions o A o o B C + o + D E F o + o + G H I J o + + + + K L M N O 7. Enter your move: l e ----------------------- Board Positions o A o o B C + + + D E F o o o + G H I J o o + + + K L M N O 8. Enter your move: j c ----------------------- Board Positions o A o + B C + + o D E F o o o o G H I J o o + + + K L M N O 9. Enter your move: c h ----------------------- Board Positions o A o o B C + o o D E F o + o o G H I J o o + + + K L M N O 10. Enter your move: n l ----------------------- Board Positions o A o o B C + o o D E F o + o o G H I J o + o o + K L M N O 11. Enter your move: d m ----------------------- Board Positions o A o o B C o o o D E F o o o o G H I J o + + o + K L M N O 12. Enter your move: l n ----------------------- Board Positions o A o o B C o o o D E F o o o o G H I J o o o + + K L M N O 13. Enter your move: o m ----------------------- Board Positions o A o o B C o o o D E F o o o o G H I J o o + o o K L M N O # left Rating ------ --------------- >4 Dufus 4 Poor 3 Mediocre 2 Good Job 1 Awesome Genius! You had 1 left. Awesome Genius! Thanks for playing. Exiting...
You need to know the following concepts in order to write this program:
Variables, assignment statements, loops, if statements, functions, parameters
Notes:
You may not use arrays for this program. You may use functions, along with reference parameters (a.k.a. pointer parameters in Zyante).
Giving input of 'x' as the first input for every move must result in displaying the ratings table and then exiting the program.
As illustrated above, either lower case or upper case should be accepted for input. You may assume that the user gives exactly one character, one space, then a second character on two alphabetic characters on each input line (unless they enter 'x' for exit).
I suggest you write the program in the following stages, compiling it and running your code at each stage. The number of run-time points (out of 55 total) for an otherwise perfect program are shown below. Note that unless your program doesn't run substantially according to program requirements, you don't get any points at all (score of 0 for the entire program.)
(0 points) Create 15 char variables (e.g. char p1,p2,p3,p4,p5,.... all the way up to 15), all (except p1) initialized to '+' (e.g. p2=p3=p4...=p15='+';). Initialize p1 to 'o'. Write the code to display the board and the positions.
(0 points) Create the two char variables that will store the user move positions.
(15 points) Write the code to make a single move, which consists of:
Placing an 'o' in the variable corresponding to the position we are moving from.
Place an 'o' in the variable corresponding to the position we are jumping over
Place an '+' in the variable corresponding to the destination position
(10 points) Place the code that displays the board and prompts for a move into a loop. The loop should continue while the number of pieces remaining is greater than 1.
(10 points) Write the code to display the table at the end of the program. Add a variable to your program to count how many pegs are remaining on the board. Write the "if" statement(s) or switch-case statements to display the correct ending message, depending on how many pieces are remaining. Also change the code that displays a message when the user selects 'x' to exit. Rather than just displaying a message, write the code to have it now break out of the loop, which should have the effect of branching down to the code that displays the Ratings table.
(20 points) Write the input verification code, with the appropriate error message for each different kind of input error, as shown in move #4 in the sample program run above. You must verify:
The source is a valid character (between 'a' and 'o')
The destination is a valid character (between 'a' and 'o')
The source has a peg (is '+')
The destination is blank (is 'o')
The piece being jumped has a peg (is '+')
Note that you do not need to verify that the source, piece being jumped and destination are adjacent and co-linear. You can just trust the user for that!
Turning in your program:
The name of the program you will turn in should be pegJump followed by your netid and the .c file extension. In other words, if your netid is reed then your program would be called pegJumpreed.c
You must also zip up the file you turn in, which typically is done by right-clicking on it and choosing the "compress" option. After zipping your program (e.g. pegJumpreed.c), you will likely end up with a file called something like pegJumpreed.zip. Only turn in this single file, turning it in on Blackboard into the assignment Program 1. Please do not put it into a folder before zipping it, rather zip the one file by itself.
Failing to follow these naming conventions and failure to turn in a zip file will result in a 5 point deduction, even if everything else is perfect in your program.