-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarterBot.java
More file actions
54 lines (44 loc) · 1.86 KB
/
StarterBot.java
File metadata and controls
54 lines (44 loc) · 1.86 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This Java API uses camelCase instead of the snake_case as documented in the API docs.
// Otherwise the names of methods are consistent.
import hlt.*;
import java.util.ArrayList;
import java.util.Random;
public class StarterBot {
public static void main(final String[] args) {
final long rngSeed;
if (args.length > 1) {
rngSeed = Integer.parseInt(args[1]);
} else {
rngSeed = System.nanoTime();
}
final Random rng = new Random(rngSeed);
Game game = new Game();
// At this point "game" variable is populated with initial map data.
// This is a good place to do computationally expensive start-up pre-processing.
// As soon as you call "ready" function below, the 2 second per turn timer will start.
game.ready("StarterBot");
Log.log("Successfully created bot! My Player ID is " + game.myId + ". Bot rng seed is " + rngSeed + ".");
for (;;) {
game.updateFrame();
final Player me = game.me;
final GameMap gameMap = game.gameMap;
final ArrayList<Command> commandQueue = new ArrayList<>();
for (final Ship ship : me.ships.values()) {
if (gameMap.at(ship).halite < Constants.MAX_HALITE / 10 || ship.isFull()) {
final Direction randomDirection = Direction.ALL_CARDINALS.get(rng.nextInt(4));
commandQueue.add(ship.move(randomDirection));
} else {
commandQueue.add(ship.stayStill());
}
}
if (
game.turnNumber <= 200 &&
me.halite >= Constants.SHIP_COST &&
!gameMap.at(me.shipyard).isOccupied())
{
commandQueue.add(me.shipyard.spawn());
}
game.endTurn(commandQueue);
}
}
}