Last active
September 3, 2017 01:00
-
-
Save vingkan/1d828a00b631c1bc2dbe30d8b0a2a2c6 to your computer and use it in GitHub Desktop.
Battleships: Sample Student Strategy
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 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