From 3cb5fbb44835c7e877e20c839b13e803febaa7e8 Mon Sep 17 00:00:00 2001 From: CoffeeCoder1015 Date: Sun, 19 Jan 2025 21:00:11 +1300 Subject: [PATCH 1/2] Obtain tower patterns at the start --- java/src/s2/Soldier.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/java/src/s2/Soldier.java b/java/src/s2/Soldier.java index 1122949..083b093 100644 --- a/java/src/s2/Soldier.java +++ b/java/src/s2/Soldier.java @@ -9,6 +9,8 @@ public class Soldier implements GenericRobotContoller { boolean SRP_built = false; int cant_find_tower_for = 0; boolean[][] SRP_pattern; + boolean[][] MoneyPattern; + boolean[][] PaintPattern; RobotController rc; Pathing pathing_engine; boolean buildPaintTowerNext = false; @@ -19,6 +21,8 @@ public Soldier(RobotController handler) throws GameActionException { rc = handler; pathing_engine = new Pathing(handler); SRP_pattern = rc.getResourcePattern(); + MoneyPattern = rc.getTowerPattern(UnitType.LEVEL_ONE_MONEY_TOWER); + PaintPattern = rc.getTowerPattern(UnitType.LEVEL_ONE_PAINT_TOWER); } public void run() throws GameActionException { From 125715162b504c0ee19820aa5a86f0c81c1916fc Mon Sep 17 00:00:00 2001 From: CoffeeCoder1015 Date: Sun, 19 Jan 2025 22:27:28 +1300 Subject: [PATCH 2/2] Tower building without markers --- java/src/s2/Soldier.java | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/java/src/s2/Soldier.java b/java/src/s2/Soldier.java index 083b093..5685006 100644 --- a/java/src/s2/Soldier.java +++ b/java/src/s2/Soldier.java @@ -65,7 +65,7 @@ public void run() throws GameActionException { private boolean buildRuins() throws GameActionException { isBuildingRuin = false; // Sense information about all visible nearby tiles. - MapInfo[] nearbyTiles = rc.senseNearbyMapInfos(); + MapInfo[] nearbyTiles = rc.senseNearbyMapInfos(-1); // Search for a nearby ruin to complete. MapInfo curRuin = null; int curDist = 100000000; @@ -80,7 +80,6 @@ private boolean buildRuins() throws GameActionException { } } - if (curRuin != null) { MapLocation targetLoc = curRuin.getMapLocation(); Direction dir = currentLocation.directionTo(targetLoc); @@ -88,33 +87,36 @@ private boolean buildRuins() throws GameActionException { rc.move(dir); // Mark the pattern we need to draw to build a tower here if we haven't already. // Decide tower type based on logic - UnitType towerToBuild; + UnitType towerToBuild = UnitType.LEVEL_ONE_MONEY_TOWER; + boolean[][] PatternToUse = MoneyPattern; // If chips exceed 3000, always build paint towers - if (rc.getChips() > 3000) { + if (rc.getChips() > rc.getMapWidth()*rc.getMapHeight()*2.3) { towerToBuild = UnitType.LEVEL_ONE_PAINT_TOWER; - } else { - // Alternate between paint and money towers - if (buildPaintTowerNext) { - towerToBuild = UnitType.LEVEL_ONE_PAINT_TOWER; - } else { - towerToBuild = UnitType.LEVEL_ONE_MONEY_TOWER; - } - buildPaintTowerNext = !buildPaintTowerNext; // Toggle for the next tower - } + PatternToUse = PaintPattern; + } - MapLocation shouldBeMarked = curRuin.getMapLocation().subtract(dir); - if (rc.senseMapInfo(shouldBeMarked).getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(towerToBuild, targetLoc)) { - rc.markTowerPattern(towerToBuild, targetLoc); - System.out.println("Trying to build a tower at " + targetLoc); - } - // Fill in any spots in the pattern with the appropriate paint. - for (MapInfo patternTile : rc.senseNearbyMapInfos(targetLoc, 8)) { - if (patternTile.getMark() != patternTile.getPaint()) { - if (patternTile.getMark() != PaintType.EMPTY) { - boolean useSecondaryColor = patternTile.getMark() == PaintType.ALLY_SECONDARY; - if (rc.canAttack(patternTile.getMapLocation())) - rc.attack(patternTile.getMapLocation(), useSecondaryColor); + for (MapInfo mapInfo : nearbyTiles) { + MapLocation tileLocation = mapInfo.getMapLocation(); + if (tileLocation == targetLoc) { + continue; + } + if (!rc.canAttack(tileLocation)) { + continue; + } + MapLocation relative_loc = tileLocation.translate(-targetLoc.x, -targetLoc.y); + boolean x_in = -2 <= relative_loc.x && relative_loc.x <= 2; + boolean y_in = -2 <= relative_loc.y && relative_loc.y <= 2; + if (x_in && y_in) { + rc.setIndicatorDot(tileLocation, 12, 111, 250); + boolean color = PatternToUse[relative_loc.x + 2][-(relative_loc.y - 2)]; + PaintType correct_paint = PaintType.ALLY_PRIMARY; + if (color) { + correct_paint = PaintType.ALLY_SECONDARY; + } + if (mapInfo.getPaint() != correct_paint) { + rc.attack(mapInfo.getMapLocation(), color); + break; } } }