-
Notifications
You must be signed in to change notification settings - Fork 0
/
DropOffCreator.js
38 lines (33 loc) · 1.21 KB
/
DropOffCreator.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
const hlt = require('./hlt');
const constants = require('./constants');
let DropOffCreator = class {
shouldCreateDropOff(game, player) {
return game.turnNumber > constants.START_DROPOFF_TURN &&
game.turnNumber < (constants.STOP_BUILDING_TURN / 100) * hlt.constants.MAX_TURNS &&
player.haliteAmount >= hlt.constants.DROPOFF_COST &&
player.getShips().length > 0 &&
player.getDropoffs().length < constants.MAXIMUM_NUM_DROPOFFS
}
makeDropOff(gameMap, player) {
let distance = 0;
let dropOffId = -1;
let ships = player.getShips();
let dropOffs = player.getDropoffs();
dropOffs.push(player.shipyard);
for (let i = 0; i < ships.length; i++) {
for (let j = 0; j < dropOffs.length; j++) {
let entityOne = ships[i];
let entityTwo = dropOffs[j];
let current = gameMap.calculateDistance(entityOne.position, entityTwo.position);
if (current > distance) {
dropOffId = ships[i].id;
distance = gameMap.calculateDistance(entityOne.position, entityTwo.position);
}
}
}
return {dropOffId: dropOffId, command: player.getShip(dropOffId).makeDropoff()};
}
}
module.exports = {
DropOffCreator
};