private static void moveSoldier(RobotController rc) throws GameActionException { // if we have a real current destination rc.setIndicatorString(1, "moving somewhere " + currentDestination + rc.getRoundNum()); if (currentDestination != null) { // if bugging is never initialized or we are switching destinations, reinitialize bugging if (!currentDestination.equals(storedDestination) || bugging == null) { bugging = new Bugging(rc, currentDestination); storedDestination = currentDestination; } // if we are trying to move towards a turret, stay out of range if (rc.isCoreReady()) { if (currentDestination.equals(nearestTurretLocation)) { bugging.turretAvoidMove(turretLocations); } else // if core is ready, then try to move towards destination if (nearestTurretLocation != null) { bugging.turretAvoidMove(turretLocations); } else { bugging.move(); } } } else if (nearestArchonLocation != null) { // we don't actually have a destination, so we want to try to move towards the // closest archon rc.setIndicatorString( 0, "moving to nearest archon " + nearestArchonLocation + rc.getRoundNum()); if (!nearestArchonLocation.equals(storedDestination)) { bugging = new Bugging(rc, nearestArchonLocation); storedDestination = nearestArchonLocation; } // if core is ready, try to move if (rc.isCoreReady() && bugging != null) { if (nearestTurretLocation != null) { bugging.turretAvoidMove(turretLocations); } else if (nearestArchonLocation.equals(bugging.destination) && myLoc.distanceSquaredTo(nearestArchonLocation) > 13) { // if soldier is far, move towards archon bugging.move(); } else if (nearestArchonLocation.equals(bugging.destination) && myLoc.distanceSquaredTo(nearestArchonLocation) < 13) { // if soldier is too close, move towards archon // try to move away from nearest archon if (rc.canMove(nearestArchonLocation.directionTo(myLoc))) { rc.move(nearestArchonLocation.directionTo(myLoc)); } } } } else { // if we literally have nowhere to go rc.setIndicatorString(1, "bugging around friendly " + rc.getRoundNum()); bugAroundFriendly(rc); } }
public static void zombieMicro(RobotController rc) throws GameActionException { boolean thereIsNonKitableZombie = false; RobotInfo closestEnemy = null; int closestDist = 10000; for (RobotInfo hostile : nearbyEnemies) { if (hostile.type == RobotType.FASTZOMBIE || hostile.type == RobotType.RANGEDZOMBIE) { thereIsNonKitableZombie = true; } int dist = myLoc.distanceSquaredTo(hostile.location); if (dist < closestDist) { closestDist = dist; closestEnemy = hostile; } } Direction d = myLoc.directionTo(closestEnemy.location); // if we're too close, move further away if (myLoc.distanceSquaredTo(closestEnemy.location) < 5 && rc.isCoreReady()) { Direction desired = d.opposite(); Direction dir = Movement.getBestMoveableDirection(desired, rc, 1); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, desired)) { rc.clearRubble(desired); } else if (shouldMine(rc, desired.rotateLeft())) { rc.clearRubble(desired.rotateLeft()); } else if (shouldMine(rc, desired.rotateRight())) { rc.clearRubble(desired.rotateRight()); } } if (!thereIsNonKitableZombie) { // Only move in closer if there is no non-kitable zombie if (myLoc.distanceSquaredTo(closestEnemy.location) > attackRadius && rc.isCoreReady()) { // if we are too far, we want to move closer // Desired direction is d. Direction dir = Movement.getBestMoveableDirection(d, rc, 1); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, d)) { rc.clearRubble(d); } else if (shouldMine(rc, d.rotateLeft())) { rc.clearRubble(d.rotateLeft()); } else if (shouldMine(rc, d.rotateRight())) { rc.clearRubble(d.rotateRight()); } else { // probably meaning you are blocked by allies if (closestEnemy.type == RobotType.ZOMBIEDEN) { // It is likely that we wanted to go to that den, but possibly coincidence // If not a coincidence, bug there. if (bugging != null) { if (bugging.destination.equals(closestEnemy.location)) { bugging.turretAvoidMove(turretLocations); // If coincidence, set new bugging. } else { bugging = new Bugging(rc, closestEnemy.location); bugging.turretAvoidMove(turretLocations); } } else { bugging = new Bugging(rc, closestEnemy.location); bugging.turretAvoidMove(turretLocations); } } } } } if (rc.isWeaponReady() && rc.canAttackLocation(closestEnemy.location)) { broadcastingAttack(rc, closestEnemy); } }
private static void luringMicro(RobotController rc) throws GameActionException { boolean thereIsNonKitableZombie = false; RobotInfo closestEnemy = null; MapLocation closestOpponent = null; int closestDist = 10000; for (RobotInfo hostile : nearbyEnemies) { if (hostile.type == RobotType.FASTZOMBIE || hostile.type == RobotType.RANGEDZOMBIE) { thereIsNonKitableZombie = true; } int dist = myLoc.distanceSquaredTo(hostile.location); if (dist < closestDist) { closestDist = dist; closestEnemy = hostile; } } // try to get the closest place to lure zombie for (MapLocation loc : turretLocations) { if (closestOpponent == null) closestOpponent = loc; else if (myLoc.distanceSquaredTo(loc) < myLoc.distanceSquaredTo(closestOpponent)) closestOpponent = null; } if (closestOpponent == null) closestOpponent = nearestEnemyLocation; Direction d = null; if (closestOpponent != null) d = myLoc.directionTo(closestOpponent); else d = myLoc.directionTo(rc.getInitialArchonLocations(enemyTeam)[0]); // if we are moving directly into the zombie, try to move to the side Direction temp = myLoc.directionTo(closestEnemy.location); if (d.equals(temp)) d = d.rotateLeft().rotateLeft(); else if (d.equals(temp.rotateLeft())) d = d.rotateLeft(); else if (d.equals(temp.rotateRight())) d = d.rotateRight(); // if we're too close, move further away towards the closest turret location or the closest // enemy if (myLoc.distanceSquaredTo(closestEnemy.location) < 10 && rc.isCoreReady()) { Direction desired = d; Direction dir = Movement.getBestMoveableDirection(desired, rc, 1); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, desired)) { rc.clearRubble(desired); } else if (shouldMine(rc, desired.rotateLeft())) { rc.clearRubble(desired.rotateLeft()); } else if (shouldMine(rc, desired.rotateRight())) { rc.clearRubble(desired.rotateRight()); } } if (!thereIsNonKitableZombie) { // Only move in closer if there is no non-kitable zombie if (myLoc.distanceSquaredTo(closestEnemy.location) > attackRadius && rc.isCoreReady()) { // if we are too far, we want to move closer // Desired direction is d. Direction dir = Movement.getBestMoveableDirection(d, rc, 1); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, d)) { rc.clearRubble(d); } else if (shouldMine(rc, d.rotateLeft())) { rc.clearRubble(d.rotateLeft()); } else if (shouldMine(rc, d.rotateRight())) { rc.clearRubble(d.rotateRight()); } else { // probably meaning you are blocked by allies if (closestEnemy.type == RobotType.ZOMBIEDEN) { // It is likely that we wanted to go to that den, but possibly coincidence // If not a coincidence, bug there. if (bugging != null) { if (bugging.destination.equals(closestEnemy.location)) { bugging.turretAvoidMove(turretLocations); // If coincidence, set new bugging. } else { bugging = new Bugging(rc, closestOpponent); bugging.turretAvoidMove(turretLocations); } } else { bugging = new Bugging(rc, closestOpponent); bugging.turretAvoidMove(turretLocations); } } } } } if (rc.isWeaponReady() && rc.canAttackLocation(closestEnemy.location)) { broadcastingAttack(rc, closestEnemy); } }