diff --git a/java/src/s2/Mopper.java b/java/src/s2/Mopper.java index 2e11511..12ee371 100644 --- a/java/src/s2/Mopper.java +++ b/java/src/s2/Mopper.java @@ -8,64 +8,96 @@ public class Mopper implements GenericRobotContoller { RobotController rc; Pathing pathing_engine; - public Mopper(RobotController handler) throws GameActionException{ + public Mopper(RobotController handler) throws GameActionException { rc = handler; pathing_engine = new Pathing(handler); } - public void run() throws GameActionException{ + public void run() throws GameActionException { System.out.println("Starting mopper logic..."); - + + MapInfo currentTile = rc.senseMapInfo(rc.getLocation()); + if (currentTile.getPaint() != null && currentTile.getPaint().isEnemy() && rc.canAttack(rc.getLocation())) { + System.out.println("Attacking enemy paint under itself.OVERRIDE.########################################"); + rc.attack(rc.getLocation(), false); // Use primary paint color + return; // Exit this turn after attacking the square under itself + } + + // Reset variables + Direction bestDirection = null; // Redeclared here - causing the error + int maxEnemiesInDirection = 0; // Redeclared here - causing the error + // Define all possible directions Direction[] directions = Direction.values(); - - // Initialize variables to track the best direction - Direction bestDirection = null; - int maxEnemiesInDirection = 0; - + // Get the mopper's current location MapLocation curLoc = rc.getLocation(); - + // Scan for all enemies within the circle of radius 2 * sqrt(2) RobotInfo[] nearbyEnemies = rc.senseNearbyRobots(curLoc, 8, rc.getTeam().opponent()); - + // Count enemies in each direction based on their relative position for (Direction dir : directions) { int enemyCount = 0; - + for (RobotInfo enemy : nearbyEnemies) { MapLocation enemyLoc = enemy.getLocation(); - + // Check if the enemy lies in the swing range for the current direction if (isInSwingRange(curLoc, enemyLoc, dir)) { enemyCount++; } } - - System.out.println("Direction: " + dir + ", Enemies: " + enemyCount); - + // Update the best direction if this one has more enemies if (enemyCount > maxEnemiesInDirection) { maxEnemiesInDirection = enemyCount; bestDirection = dir; } } - - // Perform the mop swing in the best direction if enemies are found + if (bestDirection != null && maxEnemiesInDirection > 0) { - - rc.mopSwing(bestDirection); + // Check if the robot can perform the mop swing + if (rc.isActionReady() && rc.canMopSwing(bestDirection)) { + rc.mopSwing(bestDirection); + } else { + // Handle invalid swing or cooldown + if (!rc.canMopSwing(bestDirection)) { + System.out.println("Mop swing skipped: Can't swing in direction " + bestDirection); + } else { + System.out.println("Mop swing skipped: Action cooldown not expired."); + } + // Pass onto the else block or fallback + } } else { - + bestDirection = findEnemyPaintDirection(curLoc, directions); + + if (bestDirection != null) { + if (rc.isActionReady()) { // Check if the robot is ready to act + System.out.println("Clearing enemy paint in direction: " + bestDirection); + + // Declare and reset targetLoc + MapLocation targetLoc = null; + + // Calculate the target location based on the best direction + targetLoc = curLoc.add(bestDirection); + + // Check if attack is possible and perform the attack + if (rc.canAttack(targetLoc)) { + rc.attack(targetLoc, false); // Use primary paint color to clear the tile + } + } else { + System.out.println("Attack skipped: Action cooldown not expired."); + } + } else { + pathing_engine.Move(); + } } - - // If no enemies to mop swing, move randomly - pathing_engine.Move(); // Try to paint beneath us as we walk to avoid paint penalties - MapInfo currentTile = rc.senseMapInfo(rc.getLocation()); + currentTile = rc.senseMapInfo(rc.getLocation()); if (!currentTile.getPaint().isAlly() && rc.canAttack(rc.getLocation())) { - rc.attack(rc.getLocation()); + rc.attack(rc.getLocation(), false); // Use primary paint color } } @@ -73,7 +105,7 @@ private boolean isInSwingRange(MapLocation mopperLoc, MapLocation targetLoc, Dir // Get the relative position of the target int dx = targetLoc.x - mopperLoc.x; int dy = targetLoc.y - mopperLoc.y; - + // Check based on direction and relative positions switch (swingDir) { case NORTH: @@ -88,4 +120,37 @@ private boolean isInSwingRange(MapLocation mopperLoc, MapLocation targetLoc, Dir return false; } } + + private Direction findEnemyPaintDirection(MapLocation curLoc, Direction[] directions) throws GameActionException { + Direction bestDirection = null; + int maxEnemyPaintCount = 0; + + // Check each direction for enemy paint + for (Direction dir : directions) { + int enemyPaintCount = 0; + + // Scan adjacent tiles in the direction + MapLocation targetLoc = curLoc.add(dir); + + // Ensure the target location is on the map + if (rc.onTheMap(targetLoc)) { + MapInfo targetTile = rc.senseMapInfo(targetLoc); + + // Count tiles with enemy paint + if (targetTile.getPaint() != null && targetTile.getPaint().isEnemy() && targetTile.isPassable()) { + enemyPaintCount++; + } + + + // Update the best direction if this one has more enemy paint + if (enemyPaintCount > maxEnemyPaintCount) { + maxEnemyPaintCount = enemyPaintCount; + bestDirection = dir; + } + } + } + + return bestDirection; + } } + diff --git a/java/src/s2/Tower.java b/java/src/s2/Tower.java index 817b87b..f8ea2d3 100644 --- a/java/src/s2/Tower.java +++ b/java/src/s2/Tower.java @@ -64,7 +64,7 @@ public void run() throws GameActionException { if (spawn_count[rtype] >= target_count[rtype]) { rtype++; } - if (rtype == 2) { + if (rtype > 2) { rtype = 0; spawn_count[0] = 0; spawn_count[1] = 0; @@ -74,11 +74,12 @@ public void run() throws GameActionException { if (chipCount > 10_000) { target_count[0] = 5; target_count[1] = 2; + target_count[2] = 1; // Add this line for Moppers } if (chipCount < 650) { target_count[0] = 3; target_count[1] = 1; - // target_count[2] = 1; + target_count[2] = 1; } // Attack logic for Tower