CS 107 (Spring '09)
[Schedule]
[Programs]
[Notes
& Reference] [Examples][Syllabus]
[Lab & TA] [Tests]
[Grades]
Prof. Reed, CS 107, Spring '09
Due Monday 2/16 at 1:00 PM
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: Englebert Humperdink, Mon 1:00-1:05
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...
Variables, assignment statements, loops, if statements, copying your program into your CS account, using turnin on your CS account.
turnin -c cs107 -p program2 PegJump.java
where the single file containing the solution for this project
is called PegJump.java. Do not turn in a directory containing the file, only turn in that one file. Failure to follow this instruction will result in a 5 point deduction. See the instructions given at the end of program1 to see how you can verify that the turned in program is in the CS107 course account.
[CS Dept] [UIC]
[Prof. Reed]