|
|
@ -156,4 +156,33 @@ public class AIGridGUI extends JPanel { |
|
|
|
|
|
|
|
return endGame; |
|
|
|
} |
|
|
|
|
|
|
|
public void go() { |
|
|
|
//Play a turn by making a guess at a cell. |
|
|
|
|
|
|
|
int guessLocation = 0; |
|
|
|
boolean gameOver = true; |
|
|
|
numOfGuesses++; |
|
|
|
BSButton b = null; |
|
|
|
Ship s = null; |
|
|
|
boolean killed = false; |
|
|
|
boolean isClear = false; |
|
|
|
|
|
|
|
if(randomGuess) { |
|
|
|
//Find out the maximum ship length of the surviving ships. |
|
|
|
int minClearSpace = 0; |
|
|
|
for(Ship sh : allShips) { |
|
|
|
if(!sh.isKilled() && sh.getLength() > minClearSpace) { |
|
|
|
minClearSpace = sh.getLength(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//Create an array of all possible cells and shuffle the order of the cells. Potential guesses are drawn from this array. |
|
|
|
|
|
|
|
int[] guesses = new int[(rows * columns)]; |
|
|
|
for(int i = 0; i < rows * columns; i++) { |
|
|
|
guesses[i] = i; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |