diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 59ffb6a..3ae73be 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -279,6 +279,12 @@ public class AIGridGUI extends JPanel { } left.setCell(l); left.setCount(leftCount); + + //Determine which direction had the most consecutive hits and try to continue in that direction. + + DirectionCompare dc = new DirectionCompare(); + Collections.sort(directions, dc); + guessLocation = directions.get(0).getCell(); } } @@ -320,4 +326,11 @@ public class AIGridGUI extends JPanel { return dirLeft; } } + //Implement comparator to compare directions. + + class DirectionCompare implements Comparator { + public int compare(Direction one, Direction two) { + return ((Integer) two.getCount()).compareTo((Integer) one.getCount()); + } + } }