@@ -13,78 +13,21 @@ public class Soldier implements GenericRobotContoller {
13
13
Pathing pathing_engine ;
14
14
boolean buildPaintTowerNext = false ;
15
15
16
+ MapLocation currentLocation ;
17
+
16
18
public Soldier (RobotController handler ) throws GameActionException {
17
19
rc = handler ;
18
20
pathing_engine = new Pathing (handler );
19
21
SRP_pattern = rc .getResourcePattern ();
20
22
}
21
23
22
24
public void run () throws GameActionException {
23
- if (SRP_built == false && cant_find_tower_for > 40 ) {
24
- boolean early_exit = false ;
25
- if (!rc .canMarkResourcePattern (rc .getLocation ())) {
26
- early_exit = true ;
27
- }
28
- if (rc .getChips () < 700 ) {
29
- early_exit = true ;
30
- }
31
- if (!isBuildingSRP && early_exit == false ) {
32
- MapInfo [] info = rc .senseNearbyMapInfos ();
33
- for (MapInfo mapInfo : info ) {
34
- if (mapInfo .isResourcePatternCenter ()) {
35
- early_exit = true ;
36
- break ;
37
- }
38
-
39
- // Locations within SRP range
40
- boolean noRobot = rc .senseRobotAtLocation (mapInfo .getMapLocation ()) == null ;
41
- boolean in_range = mapInfo .getMapLocation ().isWithinDistanceSquared (rc .getLocation (), 1 );
42
- if (in_range ) {
43
- // boolean isPaintedbyAlly =mapInfo.getPaint().isAlly();
44
- boolean hasTower = mapInfo .hasRuin () && !noRobot ;
45
- if (mapInfo .isWall () || hasTower ) {
46
- early_exit = true ;
47
- break ;
48
- }
49
- }
50
-
51
- boolean noTower = mapInfo .hasRuin () && noRobot ;
52
- if (noTower ) {
53
- early_exit = true ;
54
- break ;
55
- }
56
- }
57
- }
58
- if (!early_exit && rc .isActionReady ()) {
59
- isBuildingSRP = true ;
60
- MapLocation curr_loc = rc .getLocation ();
61
- MapInfo [] key_squares = rc .senseNearbyMapInfos (8 );
62
- if (rc .senseMapInfo (rc .getLocation ()).getPaint () != PaintType .ALLY_SECONDARY ) {
63
- rc .attack (curr_loc , true );
64
- }else {
65
- for (MapInfo mapInfo : key_squares ) {
66
- MapLocation relative_loc = mapInfo .getMapLocation ().translate (-curr_loc .x , -curr_loc .y );
67
- rc .setIndicatorDot (curr_loc , 0 ,0 ,255 );
68
- // System.out.println(relative_loc);
69
- boolean color = SRP_pattern [relative_loc .x +2 ][-(relative_loc .y -2 )];
70
- PaintType correct_paint = PaintType .ALLY_PRIMARY ;
71
- if (color ) {
72
- correct_paint = PaintType .ALLY_SECONDARY ;
73
- }
74
- if (mapInfo .getPaint () != correct_paint ) {
75
- rc .attack (mapInfo .getMapLocation (),color );
76
- break ;
77
- }
78
- }
79
- }
80
- if (rc .canCompleteResourcePattern (curr_loc )) {
81
- rc .completeResourcePattern (curr_loc );
82
- rc .setTimelineMarker ("Built SRP" , 255 ,0 ,0 );
83
- SRP_built = true ;
84
- isBuildingSRP = false ;
85
- }
86
- }
25
+ //get our current location at the start of each run
26
+ currentLocation = rc .getLocation ();
27
+ if (shouldBuildSRP ()) {
28
+ buildSRP ();
87
29
}
30
+
88
31
boolean found = false ;
89
32
if (!isBuildingSRP ) {
90
33
found = buildRuins ();
@@ -125,7 +68,7 @@ private boolean buildRuins() throws GameActionException {
125
68
for (MapInfo tile : nearbyTiles ) {
126
69
// Make sure the ruin is not already complete (has no tower on it)
127
70
if (tile .hasRuin () && rc .senseRobotAtLocation (tile .getMapLocation ()) == null ) {
128
- int checkDist = tile .getMapLocation ().distanceSquaredTo (rc . getLocation () );
71
+ int checkDist = tile .getMapLocation ().distanceSquaredTo (currentLocation );
129
72
if (checkDist < curDist ) {
130
73
curDist = checkDist ;
131
74
curRuin = tile ;
@@ -136,7 +79,7 @@ private boolean buildRuins() throws GameActionException {
136
79
137
80
if (curRuin != null ) {
138
81
MapLocation targetLoc = curRuin .getMapLocation ();
139
- Direction dir = rc . getLocation () .directionTo (targetLoc );
82
+ Direction dir = currentLocation .directionTo (targetLoc );
140
83
if (rc .canMove (dir ))
141
84
rc .move (dir );
142
85
// Mark the pattern we need to draw to build a tower here if we haven't already.
@@ -185,4 +128,71 @@ private boolean buildRuins() throws GameActionException {
185
128
return false ;
186
129
}
187
130
131
+ private boolean shouldBuildSRP () throws GameActionException {
132
+ /* early exit conditions */
133
+ if (SRP_built || cant_find_tower_for < 40 || !rc .canMarkResourcePattern (currentLocation ) || rc .getChips () < 700 || !rc .isActionReady ()) {
134
+ return false ;
135
+ }
136
+ /* bad location exit */
137
+ if (!isBuildingSRP ) { // not already doing it
138
+ MapInfo [] info = rc .senseNearbyMapInfos (-1 );
139
+ for (MapInfo mapInfo : info ) {
140
+ MapLocation tileLocation = mapInfo .getMapLocation ();
141
+ if (mapInfo .isResourcePatternCenter ()) { // will overlap already built SRP
142
+ // Resource centers at the very edge of the vision radius
143
+ // that are on the same x or y axis as the current are overlappable without issue
144
+ // relative locations (0,4) (-4,0) (0,-4) (4,0)
145
+ MapLocation relativeLocation = tileLocation .translate (-currentLocation .x , -currentLocation .y );
146
+ int x = relativeLocation .x ;
147
+ int y = relativeLocation .y ;
148
+ boolean case1 = x == 0 && (y == 4 || y == -4 );
149
+ boolean case2 = y == 0 && (x == 4 || x == -4 );
150
+ if (!(case1 || case2 )) {
151
+ return false ;
152
+ }
153
+ }
154
+
155
+ // Has wall or tower blocking
156
+ // Locations within SRP range
157
+ boolean noRobot = rc .senseRobotAtLocation (tileLocation ) == null ;
158
+ // cant build if there is uncompleted ruin
159
+ // this makes sure SRPs wont overlap onto TowerPatterns
160
+ boolean noTower = mapInfo .hasRuin () && noRobot ;
161
+ if (noTower ) {
162
+ return false ;
163
+ }
164
+ }
165
+ }
166
+ return true ;
167
+ }
168
+
169
+ private void buildSRP () throws GameActionException {
170
+ isBuildingSRP = true ;
171
+ MapInfo [] key_squares = rc .senseNearbyMapInfos (8 );
172
+ if (rc .senseMapInfo (currentLocation ).getPaint () != PaintType .ALLY_SECONDARY ) {
173
+ rc .attack (currentLocation , true );
174
+ } else {
175
+ for (MapInfo mapInfo : key_squares ) {
176
+ MapLocation relative_loc = mapInfo .getMapLocation ().translate (-currentLocation .x , -currentLocation .y );
177
+ rc .setIndicatorDot (currentLocation , 0 , 0 , 255 );
178
+ // System.out.println(relative_loc);
179
+ boolean color = SRP_pattern [relative_loc .x + 2 ][-(relative_loc .y - 2 )];
180
+ PaintType correct_paint = PaintType .ALLY_PRIMARY ;
181
+ if (color ) {
182
+ correct_paint = PaintType .ALLY_SECONDARY ;
183
+ }
184
+ if (mapInfo .getPaint () != correct_paint ) {
185
+ rc .attack (mapInfo .getMapLocation (), color );
186
+ break ;
187
+ }
188
+ }
189
+ }
190
+ if (rc .canCompleteResourcePattern (currentLocation )) {
191
+ rc .completeResourcePattern (currentLocation );
192
+ rc .setTimelineMarker ("Built SRP" , 255 , 0 , 0 );
193
+ SRP_built = true ;
194
+ isBuildingSRP = false ;
195
+ }
196
+ }
197
+
188
198
}
0 commit comments