University of Arizona, Department of Computer Science

CSc 120: Battleship: Example

An Example

The following example shows how this program is supposed to behave. The placement of ships is shown below. The column labeled "Input" shows the input read by the program; the column labeled "Output" shows the output produced by the program.

The input files for this example are: example-placement.txt and example-guess.txt.

worked example

File Input   Output
Placement A 0 7 4 7    
P 4 2 5 2    
D 7 5 7 3    
B 2 2 2 5    
S 9 9 9 7    
 
Guess 1 7   hit
0 7   hit
4 3   miss
9 4   miss
2 7   hit
97 63   illegal guess
2 3   hit
3 7   hit
4 7   A sunk
1 1   miss
2 2   hit
6 4   miss
7 4   hit
2 4   hit
2 5   B sunk
4 2   hit
5 2   P sunk
7 3   hit
3 8   miss
7 5   D sunk
7 7   miss
20 3   illegal guess
9 7   hit
7 6   miss
9 8   hit
9 9   S sunk
    all ships sunk: game over