Browse Source

Update Implementation Methode AIGridGUI

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

31
src/main/java/BattleShip/AIGridGUI.java

@ -156,7 +156,6 @@ public class AIGridGUI extends JPanel {
return endGame; return endGame;
} }
public void go() { public void go() {
//Play a turn by making a guess at a cell. //Play a turn by making a guess at a cell.
@ -190,6 +189,36 @@ public class AIGridGUI extends JPanel {
guesses[randInt] = guesses[i]; guesses[randInt] = guesses[i];
guesses[i] = randGuess; guesses[i] = randGuess;
} }
int numCellsTried = 0;
//Test potential guesses and mark clear if criteria met.
while(!isClear && numCellsTried < guesses.length) {
guessLocation = guesses[numCellsTried];
numCellsTried++;
//If the cell has not already been guessed, test whether there are enough clear spaces in at least one direction.
if(!cellsGuessed[guessLocation]) {
int u = guessLocation;
int upCount = -1;
while(u >= 0 && !cellsHit[u]) {
u = moveUp(u);
upCount++;
}
}
}
}
}
//Return the location of a cell one space in the given direction, or return -1 if out of bounds.
public int moveUp(int u) {
int dirUp = u - columns;
if(dirUp < 0) {
return -1;
} else {
return dirUp;
} }
} }
} }
Loading…
Cancel
Save