Skip to content

Commit 328d605

Browse files
Added new mopper into s1dMixed
1 parent faf24eb commit 328d605

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

java/src/s1dMixed/RobotPlayer.java

+73-5
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,82 @@ public static void runSoldier(RobotController rc) throws GameActionException {
407407
* per turn.
408408
*/
409409
public static void runMopper(RobotController rc) throws GameActionException {
410-
// Move and attack randomly.
410+
System.out.println("Starting mopper logic...");
411+
412+
// Define all possible directions
413+
Direction[] directions = Direction.values();
414+
415+
// Initialize variables to track the best direction
416+
Direction bestDirection = null;
417+
int maxEnemiesInDirection = 0;
418+
419+
// Get the mopper's current location
420+
MapLocation curLoc = rc.getLocation();
421+
422+
// Scan for all enemies within the circle of radius 2 * sqrt(2)
423+
RobotInfo[] nearbyEnemies = rc.senseNearbyRobots(curLoc, 8, rc.getTeam().opponent());
424+
425+
// Count enemies in each direction based on their relative position
426+
for (Direction dir : directions) {
427+
int enemyCount = 0;
428+
429+
for (RobotInfo enemy : nearbyEnemies) {
430+
MapLocation enemyLoc = enemy.getLocation();
431+
432+
// Check if the enemy lies in the swing range for the current direction
433+
if (isInSwingRange(curLoc, enemyLoc, dir)) {
434+
enemyCount++;
435+
}
436+
}
437+
438+
System.out.println("Direction: " + dir + ", Enemies: " + enemyCount);
439+
440+
// Update the best direction if this one has more enemies
441+
if (enemyCount > maxEnemiesInDirection) {
442+
maxEnemiesInDirection = enemyCount;
443+
bestDirection = dir;
444+
}
445+
}
446+
447+
// Perform the mop swing in the best direction if enemies are found
448+
if (bestDirection != null && maxEnemiesInDirection > 0) {
449+
450+
rc.mopSwing(bestDirection);
451+
} else {
452+
453+
}
454+
455+
// If no enemies to mop swing, move randomly
411456
if (robot_dir_idx == -1) {
412457
robot_dir_idx = rng.nextInt(8);
413458
}
414-
diffuse.p(rc);
415-
// We can also move our code into different methods or classes to better
416-
// organize it!
417-
updateEnemyRobots(rc);
459+
diffuse.p(rc);
460+
// Try to paint beneath us as we walk to avoid paint penalties
461+
MapInfo currentTile = rc.senseMapInfo(rc.getLocation());
462+
if (!currentTile.getPaint().isAlly() && rc.canAttack(rc.getLocation())) {
463+
rc.attack(rc.getLocation());
464+
}
465+
466+
}
467+
468+
private static boolean isInSwingRange(MapLocation mopperLoc, MapLocation targetLoc, Direction swingDir) {
469+
// Get the relative position of the target
470+
int dx = targetLoc.x - mopperLoc.x;
471+
int dy = targetLoc.y - mopperLoc.y;
472+
473+
// Check based on direction and relative positions
474+
switch (swingDir) {
475+
case NORTH:
476+
return dx >= -1 && dx <= 1 && dy < 0 && dy >= -2;
477+
case SOUTH:
478+
return dx >= -1 && dx <= 1 && dy > 0 && dy <= 2;
479+
case EAST:
480+
return dy >= -1 && dy <= 1 && dx > 0 && dx <= 2;
481+
case WEST:
482+
return dy >= -1 && dy <= 1 && dx < 0 && dx >= -2;
483+
default:
484+
return false;
485+
}
418486
}
419487

420488

0 commit comments

Comments
 (0)