Browse Source

Update Implementation Methode AIGridGUI

main
Thoumi Ngonga Brice 2 years ago
parent
commit
ca2a7838ab
  1. 27
      src/main/java/BattleShip/AIGridGUI.java

27
src/main/java/BattleShip/AIGridGUI.java

@ -226,8 +226,35 @@ public class AIGridGUI extends JPanel {
l = moveLeft(l);
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);
}
}
}
}

Loading…
Cancel
Save