|
@ -226,8 +226,35 @@ public class AIGridGUI extends JPanel { |
|
|
l = moveLeft(l); |
|
|
l = moveLeft(l); |
|
|
leftCount++; |
|
|
leftCount++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if((upCount + downCount + 1) >= minClearSpace || (rightCount + leftCount + 1) >= minClearSpace) { |
|
|
|
|
|
isClear = true; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
//If nonrandom guess (locked onto a particular ship that has been hit but not killed), determine where to guess. |
|
|
|
|
|
|
|
|
|
|
|
int attempts = 1; |
|
|
|
|
|
|
|
|
|
|
|
while(!isClear) { |
|
|
|
|
|
attempts++; |
|
|
|
|
|
|
|
|
|
|
|
if(attempts == 1) { |
|
|
|
|
|
|
|
|
|
|
|
//Starting from the location of the first hit on the ship, test each direction to determine how many consecutive hits have been made in that direction. |
|
|
|
|
|
|
|
|
|
|
|
int u = f; |
|
|
|
|
|
int upCount = -1; |
|
|
|
|
|
while(u >= 0 && cellsHit[u] && !cellsKilled[u]) { |
|
|
|
|
|
u = moveUp(u); |
|
|
|
|
|
upCount++; |
|
|
|
|
|
} |
|
|
|
|
|
up.setCell(u); |
|
|
|
|
|
up.setCount(upCount); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|