Skip to content

Commit ec5db44

Browse files
Merge pull request #12 from CoffeeCoder1015/dynamicBuilds, Closes #6
Dynamic builds aka No marker builds
2 parents ecdd1b1 + 1257151 commit ec5db44

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

java/src/s2/Soldier.java

+31-25
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Soldier implements GenericRobotContoller {
99
boolean SRP_built = false;
1010
int cant_find_tower_for = 0;
1111
boolean[][] SRP_pattern;
12+
boolean[][] MoneyPattern;
13+
boolean[][] PaintPattern;
1214
RobotController rc;
1315
Pathing pathing_engine;
1416
boolean buildPaintTowerNext = false;
@@ -19,6 +21,8 @@ public Soldier(RobotController handler) throws GameActionException {
1921
rc = handler;
2022
pathing_engine = new Pathing(handler);
2123
SRP_pattern = rc.getResourcePattern();
24+
MoneyPattern = rc.getTowerPattern(UnitType.LEVEL_ONE_MONEY_TOWER);
25+
PaintPattern = rc.getTowerPattern(UnitType.LEVEL_ONE_PAINT_TOWER);
2226
}
2327

2428
public void run() throws GameActionException {
@@ -61,7 +65,7 @@ public void run() throws GameActionException {
6165
private boolean buildRuins() throws GameActionException {
6266
isBuildingRuin = false;
6367
// Sense information about all visible nearby tiles.
64-
MapInfo[] nearbyTiles = rc.senseNearbyMapInfos();
68+
MapInfo[] nearbyTiles = rc.senseNearbyMapInfos(-1);
6569
// Search for a nearby ruin to complete.
6670
MapInfo curRuin = null;
6771
int curDist = 100000000;
@@ -76,41 +80,43 @@ private boolean buildRuins() throws GameActionException {
7680
}
7781
}
7882

79-
8083
if (curRuin != null) {
8184
MapLocation targetLoc = curRuin.getMapLocation();
8285
Direction dir = currentLocation.directionTo(targetLoc);
8386
if (rc.canMove(dir))
8487
rc.move(dir);
8588
// Mark the pattern we need to draw to build a tower here if we haven't already.
8689
// Decide tower type based on logic
87-
UnitType towerToBuild;
90+
UnitType towerToBuild = UnitType.LEVEL_ONE_MONEY_TOWER;
91+
boolean[][] PatternToUse = MoneyPattern;
8892

8993
// If chips exceed 3000, always build paint towers
90-
if (rc.getChips() > 3000) {
94+
if (rc.getChips() > rc.getMapWidth()*rc.getMapHeight()*2.3) {
9195
towerToBuild = UnitType.LEVEL_ONE_PAINT_TOWER;
92-
} else {
93-
// Alternate between paint and money towers
94-
if (buildPaintTowerNext) {
95-
towerToBuild = UnitType.LEVEL_ONE_PAINT_TOWER;
96-
} else {
97-
towerToBuild = UnitType.LEVEL_ONE_MONEY_TOWER;
98-
}
99-
buildPaintTowerNext = !buildPaintTowerNext; // Toggle for the next tower
100-
}
96+
PatternToUse = PaintPattern;
97+
}
10198

102-
MapLocation shouldBeMarked = curRuin.getMapLocation().subtract(dir);
103-
if (rc.senseMapInfo(shouldBeMarked).getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(towerToBuild, targetLoc)) {
104-
rc.markTowerPattern(towerToBuild, targetLoc);
105-
System.out.println("Trying to build a tower at " + targetLoc);
106-
}
107-
// Fill in any spots in the pattern with the appropriate paint.
108-
for (MapInfo patternTile : rc.senseNearbyMapInfos(targetLoc, 8)) {
109-
if (patternTile.getMark() != patternTile.getPaint()) {
110-
if (patternTile.getMark() != PaintType.EMPTY) {
111-
boolean useSecondaryColor = patternTile.getMark() == PaintType.ALLY_SECONDARY;
112-
if (rc.canAttack(patternTile.getMapLocation()))
113-
rc.attack(patternTile.getMapLocation(), useSecondaryColor);
99+
for (MapInfo mapInfo : nearbyTiles) {
100+
MapLocation tileLocation = mapInfo.getMapLocation();
101+
if (tileLocation == targetLoc) {
102+
continue;
103+
}
104+
if (!rc.canAttack(tileLocation)) {
105+
continue;
106+
}
107+
MapLocation relative_loc = tileLocation.translate(-targetLoc.x, -targetLoc.y);
108+
boolean x_in = -2 <= relative_loc.x && relative_loc.x <= 2;
109+
boolean y_in = -2 <= relative_loc.y && relative_loc.y <= 2;
110+
if (x_in && y_in) {
111+
rc.setIndicatorDot(tileLocation, 12, 111, 250);
112+
boolean color = PatternToUse[relative_loc.x + 2][-(relative_loc.y - 2)];
113+
PaintType correct_paint = PaintType.ALLY_PRIMARY;
114+
if (color) {
115+
correct_paint = PaintType.ALLY_SECONDARY;
116+
}
117+
if (mapInfo.getPaint() != correct_paint) {
118+
rc.attack(mapInfo.getMapLocation(), color);
119+
break;
114120
}
115121
}
116122
}

0 commit comments

Comments
 (0)