Due: At midnight, December 1, 2000, submit is turned off automatically. Work turned in after that time will not be accepted for grading.
For this assignment you will implement the game "Gold Digger" (known to many of you as battleship). This is a two player game. Each player has a 10 x 10 grid. A player cannot see the opponents grid.
To start the game, each player places several "gold bars" somewhere on their board. Each bar is represented by a contiguous sequence of horizontal or vertical grid locations of varying lengths. Specifically each player places one bar that is 5 cells long, one bar that is 4 cells long, TWO bars that are 3 cells long and one bar that is 2 cells long.
The object is to find all of your opponents gold before they find all of yours. You attempt to find their gold by asking them if there is any gold in a specific cell. The players take turns guessing the possible locations of their opponent's gold.
Each player, when it is there turn, names FIVE possible locations for a gold bar. After naming all five locations, the opponent then indicates which, if any of the five locations contained part of a gold bar. If only part of a gold bar is found the opponent does not indicate how big the bar is that has been partially found.
The players take turns until one player has found all of the other player's gold.
For this program, the computer will be one of the players, and the human will always get to move first.
script sampleOutput
then run your program. When your program has finished, type exit at the unix prompt.
At that point, the file sampleOutput in your current directory will contain everything
that appeared on your computer screen from the time you started script. You can
view this file with any text editor.
As with the Video Poker assignment, I am providing you with some starter code. In this case, instead of a package of classes that you simply use, I am instead giving you some source code that you can use (just click the link to view the code - then use "Save As" to get a copy).
I will go over this code in class on Tuesday, November 21st.
java SampleGoldDigger
The following is an excerpt from an execution of SampleGoldDigger.
Notice that the program refuses to accept an illegal placement (the
second 3 cell long gold bar. A partially discovered bar is shown
with a $. A guess that didn't find any thing is shown with a +.
A dot represents an unknown cell. The player's own board also shows
the placement of the gold bars, with digits corresponding to the size of
the bar.
os-prompt>java SampleGoldDigger The current board is: 0123456789 0.......... 1.......... 2.......... 3.......... 4.......... 5.......... 6.......... 7.......... 8.......... 9.......... Enter row and col of upper left end for the 5 long gold bar. 1 1 Enter the direction, 0 for horizontal, 1 for vertical. 1 The current board is: 0123456789 0.......... 1.5........ 2.5........ 3.5........ 4.5........ 5.5........ 6.......... 7.......... 8.......... 9.......... Enter row and col of upper left end for the 4 long gold bar. 3 3 Enter the direction, 0 for horizontal, 1 for vertical. 0 The current board is: 0123456789 0.......... 1.5........ 2.5........ 3.5.4444... 4.5........ 5.5........ 6.......... 7.......... 8.......... 9.......... Enter row and col of upper left end for the 3 long gold bar. 5 5 Enter the direction, 0 for horizontal, 1 for vertical. 1 The current board is: 0123456789 0.......... 1.5........ 2.5........ 3.5.4444... 4.5........ 5.5...3.... 6.....3.... 7.....3.... 8.......... 9.......... Enter row and col of upper left end for the 3 long gold bar. 8 2 Enter the direction, 0 for horizontal, 1 for vertical. 1 Can't put it there. The current board is: 0123456789 0.......... 1.5........ 2.5........ 3.5.4444... 4.5........ 5.5...3.... 6.....3.... 7.....3.... 8.......... 9.......... Enter row and col of upper left end for the 3 long gold bar. 8 2 Enter the direction, 0 for horizontal, 1 for vertical. 0 The current board is: 0123456789 0.......... 1.5........ 2.5........ 3.5.4444... 4.5........ 5.5...3.... 6.....3.... 7.....3.... 8..333..... 9.......... Enter row and col of upper left end for the 2 long gold bar. 1 5 Enter the direction, 0 for horizontal, 1 for vertical. 1 Your final board is: 0123456789 0.......... 1.5...2.... 2.5...2.... 3.5.4444... 4.5........ 5.5...3.... 6.....3.... 7.....3.... 8..333..... 9.......... numberExposed = 0 numberExposed = 0 Player board is now: 0123456789 0.......... 1.5...2.... 2.5...2.... 3.5.4444... 4.5........ 5.5...3.... 6.....3.... 7.....3.... 8..333..... 9.......... Computer board is now: 0123456789 0.......... 1.......... 2.......... 3.......... 4.......... 5.......... 6.......... 7.......... 8.......... 9.......... Enter your guesses. 1 1 2 2 3 3 4 4 5 5 numberExposed = 1 numberExposed = 1 Player board is now: 0123456789 0.+........ 1+5...2.... 2.5...2.... 3.5.4444... 4.5.....+.. 5.5...3.... 6.....3.... 7....+3.... 8..3$3..... 9.......... Computer board is now: 0123456789 0.......... 1.+........ 2..+....... 3...$...... 4....+..... 5.....+.... 6.......... 7.......... 8.......... 9.......... Enter your guesses. 2 3 3 2 3 4 4 3 8 5 numberExposed = 2 numberExposed = 2 Player board is now: 0123456789 0.+........ 1+5...2.... 2.$...2.... 3+5.4444... 4.5.....+.. 5.5...3..+. 6.....3.+.. 7....+3.... 8..3$3..... 9....+..... Computer board is now: 0123456789 0.......... 1.+........ 2..++...... 3..+$+..... 4...$+..... 5.....+.... 6.......... 7.......... 8.....+.... 9.......... Enter your guesses.