Last active
September 3, 2017 01:21
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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