forked from battlecode/battlecode-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
38 lines (32 loc) · 1.57 KB
/
Copy pathPlayer.java
File metadata and controls
38 lines (32 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// import the API.
// See xxx for the javadocs.
import bc.*;
public class Player {
public static void main(String[] args) {
// MapLocation is a data structure you'll use a lot.
MapLocation loc = new MapLocation(Planet.Earth, 10, 20);
System.out.println("loc: "+loc+", one step to the Northwest: "+loc.add(Direction.Northwest));
System.out.println("loc x: "+loc.getX());
// One slightly weird thing: some methods are currently static methods on a static class called bc.
// This will eventually be fixed :/
System.out.println("Opposite of " + Direction.North + ": " + bc.bcDirectionOpposite(Direction.North));
// Connect to the manager, starting the game
GameController gc = new GameController();
// Direction is a normal java enum.
Direction[] directions = Direction.values();
while (true) {
System.out.println("Current round: "+gc.round());
// VecUnit is a class that you can think of as similar to ArrayList<Unit>, but immutable.
VecUnit units = gc.myUnits();
for (int i = 0; i < units.size(); i++) {
Unit unit = units.get(i);
// Most methods on gc take unit IDs, instead of the unit objects themselves.
if (gc.isMoveReady(unit.id()) && gc.canMove(unit.id(), Direction.Southeast)) {
gc.moveRobot(unit.id(), Direction.Southeast);
}
}
// Submit the actions we've done, and wait for our next turn.
gc.nextTurn();
}
}
}