-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyBot2.js
43 lines (35 loc) · 1.64 KB
/
MyBot2.js
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
const hlt = require('./hlt');
const { Direction } = require('./hlt/positionals');
const logging = require('./hlt/logging');
const game = new hlt.Game();
game.initialize().then(async () => {
// 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.
await game.ready('2');
logging.info(`My Player ID is ${game.myId}.`);
while (true) {
await game.updateFrame();
const { gameMap, me } = game;
const commandQueue = [];
for (const ship of me.getShips()) {
if (ship.haliteAmount > hlt.constants.MAX_HALITE / 1.1) {
const destination = me.shipyard.position;
const safeMove = gameMap.naiveNavigate(ship, destination);
commandQueue.push(ship.move(safeMove));
}
else if (gameMap.get(ship.position).haliteAmount < hlt.constants.MAX_HALITE / 10) {
const direction = Direction.getAllCardinals()[Math.floor(4 * Math.random())];
const destination = ship.position.directionalOffset(direction);
const safeMove = gameMap.naiveNavigate(ship, destination);
commandQueue.push(ship.move(safeMove));
}
}
if (game.turnNumber < 0.75 * hlt.constants.MAX_TURNS &&
me.haliteAmount >= hlt.constants.SHIP_COST &&
!gameMap.get(me.shipyard).isOccupied) {
commandQueue.push(me.shipyard.spawn());
}
await game.endTurn(commandQueue);
}
});