public static void run(RobotController theRC) {
    rc = theRC;

    // These don't change so get them once and use the local variable (performance)
    myType = rc.getType();
    myTeam = rc.getTeam();
    enemyTeam = myTeam.opponent();
    myHQ = rc.senseHQLocation();
    myLoc = rc.getLocation();
    senseRange = myType.sensorRadiusSquared;
    attackRange = myType.attackRadiusSquared;
    maxRounds = rc.getRoundLimit();

    if (myType == RobotType.MISSILE) runMissile();

    if (myType.canMove()) {
      bfs = new Bfs(rc); // We need to check the breadth first search results to move optimally
    }
    threats = new Threats(rc);

    if (myType == RobotType.HQ) runHQ();
    else if (myType == RobotType.TOWER) runTower();
    else if (myType.isBuilding) runBuilding();
    else if (myType.canBuild()) runBeaver();
    else if (myType.canMine()) runMiner(); // Includes Beavers
    else if (myType == RobotType.DRONE) runDrone();
    else if (myType.canAttack() || myType == RobotType.LAUNCHER) runCombat();
    else runOther();
  }
  // Factories and supply depots
  private static void runBuilding() { // Most builds spawn units
    if (myType.canSpawn()) strategy = new BuildStrategy(rc);

    while (true) {
      if (rc.isCoreReady() && myType.canSpawn()) {
        threats.update();
        RobotType build = strategy.getBuildOrder();
        if (build != null) trySpawn(rc.getLocation().directionTo(threats.enemyHQ), build);
      }

      doTransfer();

      rc.yield();
    }
  }
Example #3
0
  /**
   * Attempts to build a robot of the given type in a random direction (attempts all directions).
   * Only attempts building if rc has no core delay and has more parts than the threshold.
   *
   * @param rc RobotController from which to build
   * @param buildType type of robot to build
   * @return true if buildType is built else false
   * @throws GameActionException
   */
  private static boolean tryToBuild(RobotController rc, RobotType buildType)
      throws GameActionException {
    if (rc.isCoreReady()) {
      Direction buildDir = getRandomDirection();
      for (int i = 0; i < 8; i++) {
        if (rc.canBuild(buildDir, buildType)) {
          rc.build(buildDir, buildType);
          rc.broadcastMessageSignal(SENDING_MODE, currentMode, ONE_SQUARE_RADIUS);

          if (!turtleCorner.equals(LOCATION_NONE)) {
            rc.broadcastMessageSignal(SENDING_TURTLE_X, turtleCorner.x, ONE_SQUARE_RADIUS);
            rc.broadcastMessageSignal(SENDING_TURTLE_Y, turtleCorner.y, ONE_SQUARE_RADIUS);
          }

          if (buildType.equals(RobotType.SCOUT)) {
            for (MapLocation scoutKitingLoc : SCOUT_KITING_LOCATIONS) {
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_X, scoutKitingLoc.x, ONE_SQUARE_RADIUS);
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_Y, scoutKitingLoc.y, ONE_SQUARE_RADIUS);
            }
          }
          return true;
        }
        buildDir = buildDir.rotateRight(); // try all directions clockwise
      }
    }
    return false;
  }
Example #4
0
 static void init(RobotController rc) {
   int roundLimit = rc.getRoundLimit();
   Common.rc = rc;
   rand = new Random(rc.getID());
   id = rc.getID();
   myTeam = rc.getTeam();
   enemyTeam = myTeam.opponent();
   history = new MapLocation[roundLimit];
   robotType = rc.getType();
   enrollment = rc.getRoundNum();
   if (robotType != RobotType.ARCHON) birthday = enrollment - robotType.buildTurns - BUILD_LAG;
   hometown = rc.getLocation();
   sightRadius = robotType.sensorRadiusSquared;
   straightSight = (int) Math.sqrt(sightRadius);
   canMessageSignal = robotType.canMessageSignal();
   Signals.buildTarget = new MapLocation[roundLimit];
   Signals.buildStrategy = new SignalStrategy[roundLimit];
   try {
     addInfo(rc.senseRobot(id));
     myArchonHometowns = rc.getInitialArchonLocations(myTeam);
     enemyArchonHometowns = rc.getInitialArchonLocations(enemyTeam);
     int coordinates[] = new int[MAP_MAX];
     int x = 0;
     int y = 0;
     for (int i = enemyArchonHometowns.length - 1; i >= 0; --i) {
       MapLocation loc = enemyArchonHometowns[i];
       twiceCenterX += loc.x;
       twiceCenterY += loc.y;
       coordinates[loc.y] *= MAP_MAX;
       coordinates[loc.y] += loc.x + 1;
     }
     for (int i = 0; i < myArchonHometowns.length; ++i) {
       MapLocation loc = myArchonHometowns[i];
       twiceCenterX += loc.x;
       twiceCenterY += loc.y;
       x += loc.x;
       y += loc.y;
     }
     twiceCenterX /= myArchonHometowns.length;
     twiceCenterY /= myArchonHometowns.length;
     x /= myArchonHometowns.length;
     y /= myArchonHometowns.length;
     for (int i = 0; i < myArchonHometowns.length; ++i) {
       MapLocation loc = myArchonHometowns[i];
       int xCoord = coordinates[loc.y] - 1;
       coordinates[loc.y] /= MAP_MAX;
       if (loc.x != twiceCenterX - xCoord) rotation = true;
     }
     Archon.center = new MapLocation(x, y);
     myBase = new MapLocation(twiceCenterX / 2, twiceCenterY / 2).directionTo(Archon.center);
     enemyBase = myBase.opposite();
   } catch (Exception e) {
     System.out.println(e.getMessage());
     e.printStackTrace();
   }
 }
Example #5
0
  public void newUnit(int senderID, MapLocation location, String robotType) {
    if (RobotType.valueOf(robotType).isBuilding()) {
      if (sensing.knownAlliedTowerLocations == null) sensing.senseAlliedTowerLocations();

      if (!sensing.knownAlliedTowerLocations.containsKey(senderID)) {
        sensing.knownAlliedTowerLocations.put(new Integer(senderID), location);
        sensing.knownAlliedTowerIDs.put(location.getX() + "," + location.getY(), senderID);
      }
    }
  }
  // Computers
  private static void runOther() {
    int numTowers = -1;
    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      // Move if we can and want to
      if (rc.isCoreReady() && myType.canMove()) {
        if (shouldRetreat()) doRetreatMove(); // Pull back if in range of the enemy guns
        else doAdvanceMove(); // Move towards our HQ
      }

      doTransfer();

      // Perform a background breadth first search to the enemy HQ
      if (myType == RobotType.COMPUTER && Clock.getBytecodesLeft() > 1000) {
        bfs.work(threats.enemyHQ, Bfs.PRIORITY_HIGH, 1000, numTowers != threats.enemyTowers.length);
      }
      numTowers = threats.enemyTowers.length;
      rc.yield();
    }
  }
  // Move towards enemy HQ if we can attack
  private static void doAdvanceMove() {
    try {
      if (myType == RobotType.COMMANDER
          && rc.hasLearnedSkill(CommanderSkillType.FLASH)
          && rc.getFlashCooldown() == 0) flashTowards(threats.enemyHQ, false);
    } catch (GameActionException e) {
      System.out.println("Flash exception");
      // e.printStackTrace();
    }

    if (rc.isCoreReady()) {
      Direction dir = null;

      if (myType.canAttack() || (myType == RobotType.LAUNCHER && Clock.getRoundNum() > 550)) {
        if (myType != RobotType.DRONE) dir = bfs.readResult(myLoc, threats.enemyHQ);
        if (dir == null) dir = myLoc.directionTo(threats.enemyHQ);
        rc.setIndicatorString(2, "Advancing " + dir);
      } else {
        dir = myLoc.directionTo(myHQ);
        rc.setIndicatorString(2, "HQ Defensive unit " + dir);
      }
      tryMove(dir, false);
    }
  }
 @Override
 public int hashCode() {
   return type.ordinal() + 561 * team.ordinal();
 }
 static boolean canDamage(RobotType r) {
   return r.canAttack() || r == RobotType.LAUNCHER || r == RobotType.MISSILE;
 }
Example #10
0
 private static boolean commanderLikes(RobotType t) {
   return (t == RobotType.MINER
       || t == RobotType.BEAVER
       || (t.isBuilding && t.canAttack() == false));
 }
Example #11
0
 public RInfoShort(MapLocation l, int e, String t) {
   location = l;
   energon = (double) e;
   type = RobotType.valueOf(t);
 }