Browse Source

Update Implementation AIGridGUI class

main
Thoumi Ngonga Brice 2 years ago
parent
commit
599ce9dde8
  1. 13
      src/main/java/BattleShip/AIGridGUI.java

13
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<Direction> {
public int compare(Direction one, Direction two) {
return ((Integer) two.getCount()).compareTo((Integer) one.getCount());
}
}
}
Loading…
Cancel
Save