Skip to content

Instantly share code, notes, and snippets.

@vingkan
Last active September 3, 2017 01:21
Show Gist options
  • Save vingkan/36070a173893bb0b1f46bf88ef2d175b to your computer and use it in GitHub Desktop.
Save vingkan/36070a173893bb0b1f46bf88ef2d175b to your computer and use it in GitHub Desktop.
Battleships: Searching for an enemy ship with the lowest health to fire at.
@Override
public void doTurn(Arena arena) {
// Fill in your strategy here
int minHealth = 100;
this.move(arena, Direction.EAST);
Ship target = null;
List<Ship> nearby = this.getNearbyShips(arena);
for (int i = 0; i < nearby.size(); i++) {
Ship ship = nearby.get(i);
String myTeam = this.getTeam();
String theirTeam = ship.getTeam();
if (theirTeam.equals(myTeam)) {
// Don't shoot!
} else {
if (ship.getHealth() < minHealth) {
target=ship;
minHealth = ship.getHealth();
}
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment