-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyBot.java
More file actions
120 lines (97 loc) · 5.21 KB
/
Copy pathMyBot.java
File metadata and controls
120 lines (97 loc) · 5.21 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import hlt.*;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
public class MyBot {
public static void main(final String[] args) {
final Networking networking = new Networking();
final GameMap gameMap = networking.initialize("MyBot");
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 (Map.Entry<Double, Entity> entityEntry : gameMap.nearbyEntitiesByDistance(ship).entrySet()) {
if (entityEntry.getValue() instanceof Ship) {
Ship otherShip = (Ship) entityEntry.getValue();
if (otherShip.getOwner() != gameMap.getMyPlayerId()) {
if (entityEntry.getKey() < 5) {
break;
} else if(entityEntry.getKey() > Constants.MAX_SPEED) {
int thrust = Constants.MAX_SPEED;
} else {
int thrust = (int) entityEntry.getKey().intValue()/2;
}
final ThrustMove newThrustMove = Navigation.navigateShipTowardsTarget(gameMap, ship, otherShip.getPosition(), Constants.MAX_SPEED, Boolean.TRUE, Constants.MAX_NAVIGATION_CORRECTIONS, Math.PI/180.0);
if (newThrustMove != null) {
DebugLog.addLog("==Moving to dock to owned planet");
moveList.add(newThrustMove);
break;
}
DebugLog.addLog("==Thrustmove is null");
}
}
if (entityEntry.getValue() instanceof Planet) {
DebugLog.addLog("=Planet=");
Planet planet = (Planet) entityEntry.getValue();
if (!planet.isOwned()) {
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;
}
}
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;
}
continue;
}
}
}
Networking.sendMoves(moveList);
}
}
}