-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarterBot.java
More file actions
91 lines (76 loc) · 3.7 KB
/
Copy pathStarterBot.java
File metadata and controls
91 lines (76 loc) · 3.7 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import hlt.*;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
public class StarterBot {
public static void main(final String[] args) {
final Networking networking = new Networking();
final GameMap gameMap = networking.initialize("StarterBot");
final ArrayList<Move> moveList = new ArrayList<>();
for (;;) {
moveList.clear();
gameMap.updateMap(Networking.readLineIntoMetadata());
for (final Ship ship : gameMap.getMyPlayer().getShips().values()) {
/* If the ship is docked, we leave it */
if (ship.getDockingStatus() != Ship.DockingStatus.Undocked) {
continue;
}
/* Get the planets by distance */
Map<Double, Planet> planetsByDistance = gameMap.nearbyPlanetsByDistance(ship);
Boolean allPlanetsOwned = Boolean.TRUE;
/* Fill boolean */
for (final Planet planet : planetsByDistance.values()) {
if (planet.isOwned()) {
continue;
}
DebugLog.addLog("Not all planets are owned. Continuing macro");
allPlanetsOwned = Boolean.FALSE;
break;
}
/* Find new resources */
for (final Planet planet : planetsByDistance.values()) {
DebugLog.addLog("=Planet=");
if (planet.getOwner() == gameMap.getMyPlayerId()) {
DebugLog.addLog("==My Planet==");
DebugLog.addLog(String.format("==Docked ships: %d Docking spots %d", planet.getDockedShips().size(), planet.getDockingSpots()));
if (planet.getDockedShips().size() < planet.getDockingSpots()) {
if (ship.canDock(planet)) {
DebugLog.addLog("==Docking owned planet");
moveList.add(new DockMove(ship, planet));
break;
} else {
final ThrustMove newThrustMove = Navigation.navigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED);
if (newThrustMove != null) {
DebugLog.addLog("==Moving to dock to owned planet");
moveList.add(newThrustMove);
break;
}
DebugLog.addLog("==Thrustmove is null");
}
}
DebugLog.addLog("==Not docking to owned planet");
continue;
}
/* If we can dock, we dock */
if (!planet.isOwned() && ship.canDock(planet)) {
DebugLog.addLog("==Unowned Planet==");
if(ship.canDock(planet)) {
DebugLog.addLog("=Planet not owned - docking");
moveList.add(new DockMove(ship, planet));
break;
}
}
final ThrustMove newThrustMove = Navigation.navigateShipToDock(gameMap, ship, planet, Constants.MAX_SPEED);
if (newThrustMove != null) {
DebugLog.addLog("=Thrusting");
moveList.add(newThrustMove);
break;
}
break;
}
}
Networking.sendMoves(moveList);
}
}
}