From ca2a7838abac8216157303b81e10168b6e0a72b1 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 23:43:51 +0100 Subject: [PATCH] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 984fd96..e67f2de 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/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); + } + } + } }