-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRetreater.js
More file actions
40 lines (35 loc) · 1.45 KB
/
Retreater.js
File metadata and controls
40 lines (35 loc) · 1.45 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
const hlt = require('./hlt');
const constants = require('./constants');
let Retreater = class {
shouldReturnToBase(ship, dropOffId, game) {
return (ship.id !== dropOffId &&
ship.haliteAmount > hlt.constants.MAX_HALITE * (constants.RETREAT_PERCENTAGE / 100)) ||
(ship.id !== dropOffId &&
game.turnNumber > 0.94 * hlt.constants.MAX_TURNS &&
ship.haliteAmount > 90) ||
(ship.id !== dropOffId &&
game.turnNumber > 0.90 * hlt.constants.MAX_TURNS &&
ship.haliteAmount > hlt.constants.MAX_HALITE * (constants.RETREAT_PERCENTAGE / 200));
}
retreat(gameMap, player, ship) {
let shipyardDistance = gameMap.calculateDistance(player.shipyard.position, ship.position);
let dropOffDistance = 100000;
let dropOffId = 0;
if (player.getDropoffs().length > 0) {
for(let i = 0; i < player.getDropoffs().length; i++) {
let currentDistance = gameMap.calculateDistance(player.getDropoffs()[i].position, ship.position);
if(currentDistance < dropOffDistance) {
dropOffDistance = currentDistance;
dropOffId = i;
}
}
}
const destination = shipyardDistance < dropOffDistance ? player.shipyard.position :
player.getDropoffs()[dropOffId].position;
const safeMove = gameMap.naiveNavigate(ship, destination);
return ship.move(safeMove);
}
}
module.exports = {
Retreater
};