Skip to content

Instantly share code, notes, and snippets.

@vingkan
Last active September 3, 2017 01:00
Show Gist options
  • Save vingkan/1d828a00b631c1bc2dbe30d8b0a2a2c6 to your computer and use it in GitHub Desktop.
Save vingkan/1d828a00b631c1bc2dbe30d8b0a2a2c6 to your computer and use it in GitHub Desktop.
Battleships: Sample Student Strategy
@Override
public void doTurn(Arena arena) {
//Fill in strategy here
this.move(arena, Direction.NORTH);
List<Ship> nearby = this.getNearbyShips(arena);
for (int i = 0; i < nearby.size(); i++)
{
Ship unknown = nearby.get(i);
boolean isOnMyTeam = this.isSameTeamAs(unknown);
if (isOnMyTeam) {
System.out.println("This ship is on my team!");
//Don't Shoot
}
else
{
System.out.println("This ship is an enemy.");
Coord location = this.getShipCoord(arena, unknown);
int x = location.getX();
int y = location.getY();
this.fire(arena, x, y);
System.out.println("Fired at: (" + x + "," + y + ")");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment