Esempio n. 1
0
 // if soldier is in range of stuff but doesn't see it, sets it to null
 public static void resetLocations(RobotController rc) throws GameActionException {
   if (nearestTurretLocation != null
       && myLoc.distanceSquaredTo(nearestTurretLocation) <= 13
       && (rc.senseRobotAtLocation(nearestTurretLocation) == null
           || rc.senseRobotAtLocation(nearestTurretLocation).type != RobotType.TURRET
           || !rc.senseRobotAtLocation(nearestTurretLocation).team.equals(enemyTeam))) {
     if (nearestTurretLocation.equals(currentDestination)) currentDestination = null;
     nearestTurretLocation = null;
   }
   if (nearestEnemyLocation != null
       && myLoc.distanceSquaredTo(nearestEnemyLocation) <= 13
       && (rc.senseRobotAtLocation(nearestEnemyLocation) == null
           || !rc.senseRobotAtLocation(nearestEnemyLocation).team.equals(enemyTeam))) {
     if (nearestEnemyLocation.equals(currentDestination)) currentDestination = null;
     nearestEnemyLocation = null;
   }
   if (nearestDenLocation != null
       && rc.canSense(nearestDenLocation)
       && (rc.senseRobotAtLocation(nearestDenLocation) == null
           || rc.senseRobotAtLocation(nearestDenLocation).type != RobotType.ZOMBIEDEN)) {
     if (nearestDenLocation.equals(currentDestination)) currentDestination = null;
     nearestDenLocation = null;
   }
   if (nearestDistressedArchon != null
           && myLoc.distanceSquaredTo(nearestDistressedArchon) <= 13
           && (rc.senseRobotAtLocation(nearestDistressedArchon) == null
               || !rc.senseRobotAtLocation(nearestDistressedArchon).team.equals(enemyTeam))
       || distressedArchonTurns > 5) {
     if (nearestDistressedArchon != null && nearestDistressedArchon.equals(currentDestination))
       currentDestination = null;
     nearestDistressedArchon = null;
     distressedArchonTurns = 0;
   }
 }
Esempio n. 2
0
 static void activateCommon(RobotController rc, MapLocation loc) throws GameActionException {
   rc.activate(loc);
   lastBuiltLocation = loc;
   RobotInfo info = rc.senseRobotAtLocation(lastBuiltLocation);
   addInfo(info);
   lastBuiltId = info.ID;
 }
Esempio n. 3
0
 static void buildCommon(RobotController rc, Direction dir, RobotType robotType)
     throws GameActionException {
   rc.build(dir, robotType);
   lastBuiltLocation = rc.getLocation().add(dir);
   RobotInfo info = rc.senseRobotAtLocation(lastBuiltLocation);
   addInfo(info);
   lastBuiltId = info.ID;
 }
Esempio n. 4
0
 private static boolean isBlockingSomeone(RobotController rc, MapLocation target)
     throws GameActionException {
   Direction dir = myLoc.directionTo(target);
   MapLocation behind = myLoc.add(dir.opposite());
   MapLocation left = behind.add(dir.rotateLeft());
   MapLocation right = behind.add(dir.rotateRight());
   // There is someone behind us
   if (rc.senseRobotAtLocation(behind) != null) {
     // If there is stuff blocking on both sides, then blocking
     if (!rc.canMove(myLoc.directionTo(left)) && !rc.canMove(myLoc.directionTo(right))) {
       return true;
     }
   }
   return false;
 }
Esempio n. 5
0
 private static void removeTurretLocations(RobotController rc) throws GameActionException {
   MapLocation[] removedLocations = new MapLocation[turretLocations.size()];
   int removedLength = 0;
   for (MapLocation location : turretLocations) {
     if (rc.canSenseLocation(location)) {
       RobotInfo info = rc.senseRobotAtLocation(location);
       if (info == null) {
         removedLocations[removedLength++] = location;
       } else if (info.team != enemyTeam
           || (info.team == enemyTeam && info.type != RobotType.TURRET)) {
         removedLocations[removedLength++] = location;
       }
     }
   }
   for (int i = 0; i < removedLength; i++) {
     turretLocations.remove(removedLocations[i]);
   }
 }
Esempio n. 6
0
  private static void rushMicro(RobotController rc, RobotInfo[] hostiles)
      throws GameActionException {
    // Prioritizes attacking turrets.
    RobotInfo bestEnemy = null;
    boolean canAttackBestEnemy = false;
    int bestEnemyDist = 10000; // only care if can't hit
    for (RobotInfo hostile : hostiles) {
      // Can attack this enemy.
      int dist = myLoc.distanceSquaredTo(hostile.location);
      // Summary:
      // Prioritizes enemies over zombies.
      // Prioritizes turret enemies over other enemies.
      // Prioritizes lowest health enemy last
      if (dist <= attackRadius) {
        if (bestEnemy != null) {
          if (bestEnemy.team == enemyTeam) { // best is already enemy
            if (hostile.team == enemyTeam) { // found an enemy
              if (countsAsTurret(bestEnemy.type)) {
                if (countsAsTurret(hostile.type)) {
                  // Take lowest health
                  if (bestEnemy.health > hostile.health) bestEnemy = hostile;
                }
              } else {
                if (countsAsTurret(hostile.type)) {
                  bestEnemy = hostile;
                } else {
                  // Take lowest health
                  if (bestEnemy.health > hostile.health) bestEnemy = hostile;
                }
              }
            }
          } else { // best is not an enemy!
            if (hostile.team == enemyTeam) { // found an enemy
              bestEnemy = hostile;
            } else {
              // Take lowest health
              if (bestEnemy.health > hostile.health) bestEnemy = hostile;
            }
          }
        } else {
          bestEnemy = hostile;
        }
        canAttackBestEnemy = true;
      } else {
        // Only update best enemy if you can't attack best enemy
        if (!canAttackBestEnemy) {
          if (bestEnemy != null) {
            // Pick the closest one
            if (bestEnemyDist > dist) {
              bestEnemyDist = dist;
              bestEnemy = hostile;
            }
          } else {
            bestEnemyDist = dist;
            bestEnemy = hostile;
          }
        }
      }
    }
    rc.setIndicatorString(0, "Round: " + rc.getRoundNum() + ", Best enemy: " + bestEnemy);
    if (rc.isCoreReady()) {
      // If there is a best enemy, attack him.
      if (bestEnemy != null) {
        // Move closer only if blocking someone.
        if (rc.canAttackLocation(bestEnemy.location)) {
          if (isBlockingSomeone(rc, bestEnemy.location)) {
            Direction desired = myLoc.directionTo(bestEnemy.location);
            Direction dir = Movement.getBestMoveableDirection(desired, rc, 2);
            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 can't attack it, move closer!
        else {
          Direction desired = myLoc.directionTo(bestEnemy.location);
          Direction dir = Movement.getBestMoveableDirection(desired, rc, 2);
          if (dir != Direction.NONE) {
            rc.move(dir);
          } else if (shouldMine(rc, desired)) {
            rc.clearRubble(desired);
          } else if (shouldMine(rc, desired.rotateLeft())) {
            rc.clearRubble(dir.rotateLeft());
          } else if (shouldMine(rc, desired.rotateRight())) {
            rc.clearRubble(desired.rotateRight());
          }
        }
      }
      // Otherwise move closer to destination
      else {
        if (currentDestination != null) {
          RobotInfo info = null;
          if (rc.canSenseLocation(currentDestination)) {
            info = rc.senseRobotAtLocation(currentDestination);
          }
          if (info != null) {
            // If can attack it, just only move closer if blocking someone behind.
            if (rc.canAttackLocation(info.location)) {
              if (isBlockingSomeone(rc, currentDestination)) {
                Direction desired = myLoc.directionTo(currentDestination);
                Direction dir = Movement.getBestMoveableDirection(desired, rc, 2);
                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 can't attack it, move closer!
            else {
              Direction desired = myLoc.directionTo(currentDestination);
              Direction dir = Movement.getBestMoveableDirection(desired, rc, 2);
              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 not there, just move closer.
          else {
            Direction desired = myLoc.directionTo(currentDestination);
            Direction dir = Movement.getBestMoveableDirection(desired, rc, 2);
            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());
            }
          }
        }
      }
    }

    // Attack whenever you can.
    if (bestEnemy != null) {
      if (rc.isWeaponReady()) {
        if (rc.canAttackLocation(bestEnemy.location)) {
          broadcastingAttack(rc, bestEnemy);
        }
      }
    }
  }