Ejemplo n.º 1
0
  private static void shallWeAllIn() throws GameActionException {
    if (rc.senseEnemyNukeHalfDone() && Clock.getRoundNum() < 300) {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      return;
    }

    int massedRobos = 0;
    double massedAmountNeeded = .5 * (40 + (10 * gencount) - (1 * othercount));

    if (rc.senseEnemyNukeHalfDone()) massedAmountNeeded -= 10;

    int rallyRadius = 33;
    if (massedAmountNeeded > 50) rallyRadius = 63;

    Robot[] robos =
        rc.senseNearbyGameObjects(Robot.class, findRallyPoint(), rallyRadius, rc.getTeam());

    for (Robot r : robos) {
      if (rc.senseRobotInfo(r).type == RobotType.SOLDIER) {
        ++massedRobos;
      }
    }

    if (massedRobos > massedAmountNeeded) // if we should all in...
    {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      allInRound = Clock.getRoundNum();
    }
  }
Ejemplo n.º 2
0
  // After a little while, if nothing has gone wrong, if we are next to a pastr and no one
  // else is building or has built a noise tower, build one.
  private boolean tryBuildNoiseTower() throws GameActionException {
    if (!rc.isActive()) return false;
    if (Clock.getRoundNum() < 200) return false;
    if (rc.senseRobotCount() < 6) return false;

    // A problem with building a noise tower is that it makes us more vulnerable to
    // a rush. If it's early and the opponent hasn't build a pastr, let's hold off
    // in case it means that they are rushing.
    if (Clock.getRoundNum() < 300 && rc.sensePastrLocations(them).length == 0) return false;

    // Only allowed to build noise tower if adjacent to pastr
    MapLocation[] ourPastrs = rc.sensePastrLocations(us);
    if (ourPastrs.length == 0 || !here.isAdjacentTo(ourPastrs[0])) return false;

    // Check if someone else is already building a noise tower
    MapLocation existingBuilder = MessageBoard.BUILDING_NOISE_TOWER.readMapLocation();
    if (existingBuilder != null) {
      if (rc.senseNearbyGameObjects(Robot.class, existingBuilder, 1, us).length > 0) {
        return false;
      }
    }

    // Construct the noise tower and advertise the fact that we are doing it
    MessageBoard.BUILDING_NOISE_TOWER.writeMapLocation(here);
    constructNoiseTower(ourPastrs[0]);
    return true;
  }
Ejemplo n.º 3
0
  public static boolean doWeNeedGenerator() throws GameActionException {
    if (rc.readBroadcast(Constants.campChannel) == Constants.campGenInProduction) return false;
    if (Clock.getRoundNum() - allInRound < 80) return false;
    if (rc.readBroadcast(Constants.commandChannel) == Constants.commandRally
        && rc.getTeamPower() > powerThreshold) return false;

    if (rc.getTeamPower() < minPowerThreshold && Clock.getRoundNum() > minRoundThreshold) {
      return true;
    }

    gencount = 0;
    soldiercount = 0;
    othercount = 0;

    Robot[] robos =
        rc.senseNearbyGameObjects(Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam());
    for (Robot r : robos) {
      RobotType rt = rc.senseRobotInfo(r).type;
      if (rt == RobotType.GENERATOR) ++gencount;
      else if (rt == RobotType.SOLDIER) ++soldiercount;
      else ++othercount;
    }

    double decay = .8;
    if (rc.hasUpgrade(Upgrade.FUSION)) {
      decay = .99;
    }

    if ((40 + (10 * gencount) - (1.6 * soldiercount) - (1 * othercount)) * decay < 1) {
      return true;
    }
    return false;
  }
Ejemplo n.º 4
0
  // HQ or pastr calls this function to spend spare bytecodes computing paths for soldiers
  public static void work(MapLocation dest, int priority, int bytecodeLimit)
      throws GameActionException {
    int page = findFreePage(dest, priority);
    Debug.indicate("path", 1, "BFS Pathing to " + dest.toString() + "; using page " + page);
    if (page == -1) return; // We can't do any work, or don't have to

    if (!dest.equals(previousDest)) {
      Debug.indicate("path", 0, "BFS initingQueue");
      initQueue(dest);
    } else {
      Debug.indicate("path", 0, "BFS queue already inited");
    }

    previousDest = dest;
    previousRoundWorked = Clock.getRoundNum();
    previousPage = page;

    int mapWidth = rc.getMapWidth();
    int mapHeight = rc.getMapHeight();
    MapLocation enemyHQ = rc.senseEnemyHQLocation();
    boolean destInSpawn = dest.distanceSquaredTo(enemyHQ) <= 25;

    while (locQueueHead != locQueueTail && Clock.getBytecodeNum() < bytecodeLimit) {
      // pop a location from the queue
      MapLocation loc = locQueue[locQueueHead];
      locQueueHead++;

      int locX = loc.x;
      int locY = loc.y;
      for (int i = 8; i-- > 0; ) {
        int x = locX + dirsX[i];
        int y = locY + dirsY[i];
        if (x >= 0 && y >= 0 && x < mapWidth && y < mapHeight && !wasQueued[x][y]) {
          MapLocation newLoc = new MapLocation(x, y);
          if (rc.senseTerrainTile(newLoc) != TerrainTile.VOID
              && (destInSpawn || !Bot.isInTheirHQAttackRange(newLoc))) {
            publishResult(page, newLoc, dest, dirs[i]);

            // push newLoc onto queue
            locQueue[locQueueTail] = newLoc;
            locQueueTail++;
            wasQueued[x][y] = true;
          }
        }
      }
    }

    boolean finished = locQueueHead == locQueueTail;
    Debug.indicate("path", 2, "BFS finished = " + finished + "; locQueueHead = " + locQueueHead);
    writePageMetadata(page, Clock.getRoundNum(), dest, priority, finished);
  }
Ejemplo n.º 5
0
  private static void runMissile() {
    int lastTurn = Clock.getRoundNum() + GameConstants.MISSILE_LIFESPAN;
    int[] damageRange = {0, 8, 15, 24, 35, 48};
    MapLocation target = null;
    boolean targetMoves = true;

    while (true) {
      myLoc = rc.getLocation();
      int turns = lastTurn - Clock.getRoundNum();

      if (targetMoves) { // Re-acquire the target's location
        RobotInfo[] inRange = rc.senseNearbyRobots(damageRange[turns], enemyTeam);
        if (inRange.length > 0) { // No units to target
          target = inRange[0].location;
          targetMoves = inRange[0].type.canMove();
          rc.setIndicatorString(0, "Missile targetting " + inRange[0].type + "@" + target);
        } else {
          targetMoves = false; // Pick a tower or the HQ
          MapLocation[] enemyTowers = rc.senseEnemyTowerLocations();
          for (MapLocation t : enemyTowers) {
            if (myLoc.distanceSquaredTo(t) <= damageRange[turns]) {
              target = t;
              rc.setIndicatorString(0, "Missile targetting Tower @" + target);
              break;
            }
          }
          if (target == null) {
            target = rc.senseEnemyHQLocation();
            rc.setIndicatorString(0, "Missile targetting HQ @" + target);
          }
        }
      }

      try {
        if (target != null) {
          if (myLoc.distanceSquaredTo(target) <= GameConstants.MISSILE_RADIUS_SQUARED) rc.explode();
          else {
            Direction d = myLoc.directionTo(target);
            if (rc.canMove(d)) rc.move(d);
            else if (rc.canMove(d.rotateLeft())) rc.move(d.rotateLeft());
            else if (rc.canMove(d.rotateRight())) rc.move(d.rotateRight());
          }
        }
      } catch (GameActionException e) {
        System.out.println("Missile exception");
        // e.printStackTrace();
      }
      rc.yield();
    }
  }
Ejemplo n.º 6
0
  // Drones
  private static void runDrone() {
    moveDir = Direction.NORTH;
    droneMoveCurrent = 1;
    droneMoveMax = 2;
    patrolClockwise = true;
    droneCentred = false; // We haven't made it to the centre of our spiral yet

    while (true) {
      threats.update();
      myLoc = rc.getLocation();

      // Attack if there is an enemy in sight
      if (rc.isWeaponReady()) attackWeakest();

      // Move if we can and want to
      if (rc.isCoreReady()) {
        if (shouldRetreat()) {
          doRetreatMove(); // Pull back if in range of the enemy guns
        } else if (Clock.getRoundNum() < 600) {
          doPatrol();
        } else {
          doSupply();
        }
      }

      doTransfer();

      rc.yield();
    }
  }
Ejemplo n.º 7
0
  public void turn() throws GameActionException {
    updateStrategicInfo();

    // First turn gets special treatment: spawn then do a bunch of computation
    // (which we devoutly hope will finished before the spawn timer is up
    // and before anyone attacks us).
    if (Clock.getRoundNum() == 0) {
      doFirstTurn();
      return;
    }

    if (rc.isActive()) {
      spawnSoldier();
    }

    attackEnemies();

    directStrategy();

    // Use spare bytecodes to do pathing computations
    MapLocation pathingDest;
    if (attackModeTarget != null) pathingDest = attackModeTarget;
    else if (computedBestPastrLocation != null) pathingDest = computedBestPastrLocation;
    else pathingDest = null;

    if (pathingDest != null) Bfs.work(pathingDest, rc, 9000);
  }
Ejemplo n.º 8
0
  public static void run(RobotController myRC) {
    BaseRobot br = null;
    try {
      switch (myRC.getType()) {
        case HQ:
          br = new HQRobot(myRC);
          break;
        case SOLDIER:
          br = new SoldierRobot(myRC);
          break;
        case ARTILLERY:
          br = new Artillery(myRC);
          break;
        default:
          br = new PassiveEncampment(myRC);
      }

      while (true) {
        br.curRound = Clock.getRoundNum();
        br.run();

        br.rc.yield();
      }

    } catch (Exception e) {
      // DEBUG
      System.out.println("Shit happened!");
      e.printStackTrace();
      br.rc.addMatchObservation(e.toString());
    }
  }
Ejemplo n.º 9
0
  private int findFreePage(MapLocation dest, int priority) throws GameActionException {
    // see if we can reuse a page we used before
    if (dest.equals(previousDest) && previousPage != -1) {
      int previousPageMetadata = readPageMetadata(previousPage);
      if (getMetadataRoundLastUpdated(previousPageMetadata) == previousRoundWorked) {
        MapLocation where = getMetadataDestination(previousPageMetadata);
        if (where.x == cropX(dest.x) && where.y == cropY(dest.y)) {
          if (getMetadataIsFinished(previousPageMetadata)) {
            if (getMetadataIsComplete(previousPageMetadata))
              return -1; // we're done! don't do any work!
            // Restart the search with more up to data map info
            initQueue(dest);
            // System.out.print("Restart BFS to " + dest + ", page " + previousPage+ ", start round
            // " + Clock.getRoundNum() + "\n");
            return previousPage;
          } else {
            return previousPage;
          }
        }
      }
    }

    // Check to see if anyone else is working on this destination. If so, don't bother doing
    // anything.
    // But as we loop over pages, look for the page that hasn't been touched in the longest time
    int lastRound = Clock.getRoundNum() - 1;
    int oldestPage = -1;
    int oldestPageRoundUpdated = 999999;
    for (int page = 0; page < NUM_PAGES; page++) {
      int metadata = readPageMetadata(page);
      if (metadata == 0) { // untouched page
        if (oldestPageRoundUpdated > 0) {
          oldestPage = page;
          oldestPageRoundUpdated = 0;
        }
      } else {
        int roundUpdated = getMetadataRoundLastUpdated(metadata);
        boolean isFinished = getMetadataIsFinished(metadata);
        if (roundUpdated >= lastRound || isFinished) {
          if (cropSame(getMetadataDestination(metadata), dest)) {
            return -1; // someone else is on the case!
          }
        }
        if (roundUpdated < oldestPageRoundUpdated) {
          oldestPageRoundUpdated = roundUpdated;
          oldestPage = page;
        }
      }
    }

    // No one else is working on our dest. If we found an inactive page, use that one.
    if (oldestPage != -1 && oldestPageRoundUpdated < lastRound) return oldestPage;

    // If there aren't any inactive pages, and we have high priority, just trash page 0:
    if (priority == PRIORITY_HIGH) return 0;

    // otherwise, give up:
    return -1;
  }
Ejemplo n.º 10
0
  public static void run(RobotController myRC) {
    rc = myRC;
    barracks = findBarracks();
    while (true) {
      try {
        if (rc.getType() == RobotType.SOLDIER) {
          Robot[] enemyRobots =
              rc.senseNearbyGameObjects(
                  Robot.class, 50000, rc.getTeam().opponent()); // list of enemy robots
          if (enemyRobots.length == 0) {
            Clock.getRoundNum(); // gets the round number
            if (Clock.getRoundNum() < 250) {
              goToLocation(
                  barracks); // if you are before round 250 travel to the "barracks" or meeting
                             // place.
            } else {
              goToLocation(rc.senseEnemyHQLocation());
            }
          } else { // else attack the closest enemy
            int closestDist = 50000;
            MapLocation closestEnemy = null;
            for (int i = 0; i < enemyRobots.length; i++) {
              Robot enemyBot = enemyRobots[i];
              RobotInfo arobotInfo = rc.senseRobotInfo(enemyBot);
              int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation());
              if (dist < closestDist) {
                closestDist = dist;
                closestEnemy = arobotInfo.location;
              }
            }
            goToLocation(closestEnemy);
          }
        } else {
          HqCommand();
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
      rc.yield(); // end turn
    }
  }
Ejemplo n.º 11
0
 public static void timerEnd(String message) {
   int endBytecodeNum = Clock.getBytecodeNum();
   int endRoundNum = Clock.getRoundNum();
   if (endRoundNum == startRoundNum)
     System.out.format(
         "timed %s: took %d bytecodes\n", message, endBytecodeNum - startBytecodeNum);
   else
     System.out.format(
         "timed %s: took %d turns + %d bytecodes\n",
         message, endRoundNum - startRoundNum, endBytecodeNum - startBytecodeNum);
 }
Ejemplo n.º 12
0
 public void enemyInSight(
     MapLocation[] locations,
     int[] ints,
     String[] strings,
     int locationStart,
     int intStart,
     int stringStart,
     int count) {
   closestEnemySeen = Clock.getRoundNum();
   closestEnemy = navigation.findClosest(locations, locationStart);
 }
Ejemplo n.º 13
0
  public void herdInward() throws GameActionException {
    radius = 20 - Math.min(13, (Clock.getRoundNum() % 120) * 16.0 / 120.0);

    MapLocation target =
        new MapLocation(
            (int) (here.x + radius * Math.cos(angle)), (int) (here.y + radius * Math.sin(angle)));
    angle += rate;
    rc.setIndicatorString(0, "angle = " + angle);
    if (rc.canAttackSquare(target)) {
      rc.attackSquare(target);
    }
  }
Ejemplo n.º 14
0
  private static void turn() throws GameActionException {
    if (rc.getHealth() <= 6 * RobotType.SOLDIER.attackPower) {
      MessageBoard.PASTR_DISTRESS_SIGNAL.writeInt(Clock.getRoundNum());
    }

    // do speculative pathing calculations
    int bytecodeLimit = 9000;
    MapLocation[] enemyPastrs = rc.sensePastrLocations(them);
    for (int i = 0; i < enemyPastrs.length; i++) {
      if (Clock.getBytecodeNum() > bytecodeLimit) break;
      Bfs.work(enemyPastrs[i], Bfs.PRIORITY_LOW, bytecodeLimit);
    }
  }
Ejemplo n.º 15
0
  private static int findFreePage(MapLocation dest, int priority) throws GameActionException {
    // see if we can reuse a page we used before
    if (dest.equals(previousDest) && previousPage != -1) {
      int previousPageMetadata = readPageMetadata(previousPage);
      if (getMetadataRoundLastUpdated(previousPageMetadata) == previousRoundWorked
          && getMetadataDestination(previousPageMetadata).equals(dest)) {
        if (getMetadataIsFinished(previousPageMetadata)) {
          return -1; // we're done! don't do any work!
        } else {
          return previousPage;
        }
      }
    }

    // Check to see if anyone else is working on this destination. If so, don't bother doing
    // anything.
    // But as we loop over pages, look for the page that hasn't been touched in the longest time
    int lastRound = Clock.getRoundNum() - 1;
    int oldestPage = -1;
    int oldestPageRoundUpdated = 999999;
    for (int page = 0; page < NUM_PAGES; page++) {
      int metadata = readPageMetadata(page);
      if (metadata == 0) { // untouched page
        if (oldestPageRoundUpdated > 0) {
          oldestPage = page;
          oldestPageRoundUpdated = 0;
        }
      } else {
        int roundUpdated = getMetadataRoundLastUpdated(metadata);
        boolean isFinished = getMetadataIsFinished(metadata);
        if (roundUpdated >= lastRound || isFinished) {
          if (getMetadataDestination(metadata).equals(dest)) {
            return -1; // someone else is on the case!
          }
        }
        if (roundUpdated < oldestPageRoundUpdated) {
          oldestPageRoundUpdated = roundUpdated;
          oldestPage = page;
        }
      }
    }

    // No one else is working on our dest. If we found an inactive page, use that one.
    if (oldestPage != -1 && oldestPageRoundUpdated < lastRound) return oldestPage;

    // If there aren't any inactive pages, and we have high priority, just trash page 0:
    if (priority == PRIORITY_HIGH) return 0;

    // otherwise, give up:
    return -1;
  }
Ejemplo n.º 16
0
  // Launch a missile if there is an enemy in sight.
  // We ignore other missiles
  private static void doLaunch() {
    int count = rc.getMissileCount();
    if (count > 0 && Clock.getRoundNum() % 2 == 0) {
      MapLocation launchFrom; // We can launch 1 tile towards the enemy
      MapLocation explodeAt; // We can explode adjacent to the enemy (1 tile towards us)
      int missileRange = 30;
      RobotInfo[] enemies = rc.senseNearbyRobots(49, enemyTeam);
      MapLocation target = null;
      for (RobotInfo r : enemies) {
        if (r.type != RobotType.MISSILE) { // Ignore missiles
          launchFrom = myLoc.add(myLoc.directionTo(r.location));
          explodeAt = r.location.add(r.location.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) {
            target = r.location;
            break;
          }
        }
      }
      if (target == null) { // Check for towers
        for (MapLocation t : threats.enemyTowers) {
          launchFrom = myLoc.add(myLoc.directionTo(t));
          explodeAt = t.add(t.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) {
            target = t;
            break;
          }
        }

        if (target == null) { // Check for HQ
          MapLocation ehq = threats.enemyHQ;
          launchFrom = myLoc.add(myLoc.directionTo(ehq));
          explodeAt = ehq.add(ehq.directionTo(myLoc));
          if (launchFrom.distanceSquaredTo(explodeAt) <= missileRange) target = ehq;
        }
      }
      if (target != null) {
        try {
          Direction d = myLoc.directionTo(target);

          if (rc.canLaunch(d)) {
            rc.launchMissile(d);
          }
        } catch (GameActionException e) {
          System.out.println("Launch exception");
          e.printStackTrace();
        }
      }
    }
  }
Ejemplo n.º 17
0
  @Override
  public void run() {
    while (true) {
      try {

      } catch (Exception e) {
        System.out.println(
            "Robot "
                + myRC.getRobot().getID()
                + " during round number "
                + Clock.getRoundNum()
                + " caught exception:");
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 18
0
  /*
   * Moves towards the nearest enemy
   * Returns true if we moved or are in the right place
   */
  private static boolean doCloseWithEnemyMove(boolean ignoreThreat) {
    // Move to within attack range of the nearest enemy - ignore towers and HQ until later in the
    // game
    // We can move in closer if we are still out of range of the enemy
    RobotInfo nearest = null;
    RobotInfo preferred = null;
    RobotInfo[] enemies = rc.senseNearbyRobots(senseRange * 16, enemyTeam);
    boolean canFly = (myType == RobotType.DRONE);

    int now = Clock.getRoundNum();
    for (RobotInfo e : enemies) {
      // We want to find and circle units, not towers or HQ (until later in the game)
      if (now < maxRounds / 2 && (e.type == RobotType.HQ || e.type == RobotType.TOWER)) continue;
      // Drones on VOID tiles cannot be reached by ground troops - ignore them
      if (!canFly && rc.senseTerrainTile(e.location) != TerrainTile.NORMAL) continue;
      // Commanders are good at picking off miners, beavers and non combat buildings - have a
      // preference for them
      if (myType == RobotType.COMMANDER
          && commanderLikes(e.type)
          && (preferred == null
              || e.location.distanceSquaredTo(myLoc) < preferred.location.distanceSquaredTo(myLoc)))
        preferred = e;
      if (nearest == null
          || e.location.distanceSquaredTo(myLoc) < nearest.location.distanceSquaredTo(myLoc))
        nearest = e;
    }

    if (preferred != null) nearest = preferred;

    int attackRange = myType.attackRadiusSquared;
    if (myType == RobotType.LAUNCHER)
      attackRange = (1 + GameConstants.MISSILE_LIFESPAN) * (1 + GameConstants.MISSILE_LIFESPAN);

    if (nearest != null) {
      if (ignoreThreat || myLoc.distanceSquaredTo(nearest.location) > attackRange) {
        rc.setIndicatorString(2, "Closing with " + nearest.type + " at " + nearest.location);
        if (rc.isCoreReady()) tryMove(rc.getLocation().directionTo(nearest.location), ignoreThreat);
      } else {
        rc.setIndicatorString(
            2, "Holding at range with " + nearest.type + " at " + nearest.location);
      }
      return true;
    }
    return false;
  }
Ejemplo n.º 19
0
  // 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);
    }
  }
Ejemplo n.º 20
0
 public static void init() {
   m_w = 12987394 + 183639462 * Clock.getRoundNum(); /* must not be zero, nor 0x464fffff */
   m_z = 87692688 + 129348760 * Clock.getRoundNum(); /* must not be zero, nor 0x9068ffff */
 }
Ejemplo n.º 21
0
public class SoldierBehavior extends RobotBehavior {

  enum Role {
    LEFTLEFT,
    LEFTRIGHT,
    RIGHTLEFT,
    RIGHTRIGHT,
    PASTR,
    NONE
  };

  enum Mode {
    GOING_TO_MIDDLE,
    SWEEP_OUT,
    RETURN_HOME,
    STAND_RICH_LOC,
    FIND_PASTR_LOC,
    BUILD_PASTR,
    ACQUIRE_TARGET,
    ENGAGE,
    BIRTH_DECIDE_MODE
  };

  // basic data
  int bornRound = Clock.getRoundNum();
  Mover mover = new Mover();

  // state machine stuff
  Mode mode;
  int roleIndex;
  Role role;

  /** true if this is the first sweep attempt, false afterwards. */
  boolean initialSweep;

  /** true if we're panicking to build pastures at the end */
  boolean panicPastrBuilding;

  /** whether we're done building */
  boolean buildingFinished = false;
  /** whether to sneak to where the building should be built */
  int sneakToBuildingLoc = 0;

  // map locations
  MapLocation dest;

  static final MapLocation middle = new MapLocation(ALLY_HQ.x + HQ_DX / 2, ALLY_HQ.y + HQ_DY / 2);
  static final MapLocation leftleft =
      new MapLocation(ALLY_HQ.x + HQ_DX / 3 - HQ_DY / 3, ALLY_HQ.y + HQ_DY / 3 + HQ_DX / 3);
  static final MapLocation leftright =
      new MapLocation(ALLY_HQ.x + HQ_DX / 3 - HQ_DY / 5, ALLY_HQ.y + HQ_DY / 3 + HQ_DX / 5);
  static final MapLocation rightleft =
      new MapLocation(ALLY_HQ.x + HQ_DX / 3 + HQ_DY / 5, ALLY_HQ.y + HQ_DY / 3 - HQ_DX / 5);
  static final MapLocation rightright =
      new MapLocation(ALLY_HQ.x + HQ_DX / 3 + HQ_DY / 3, ALLY_HQ.y + HQ_DY / 3 - HQ_DX / 3);

  static final Role[] roleList = {Role.LEFTLEFT, Role.LEFTRIGHT, Role.RIGHTLEFT, Role.RIGHTRIGHT};
  static final MapLocation[] roleLocList = {leftleft, leftright, rightleft, rightright};

  public SoldierBehavior() {
    role = Role.NONE;
    changeMode(Mode.BIRTH_DECIDE_MODE);
  }

  @Override
  protected void initMessageHandlers() {
    handlers[MessageType.ATTACK_LOCATION.ordinal()] =
        new MessageHandler() {
          @Override
          public void handleMessage(int[] message) {
            MapLocation loc = new MapLocation(message[0], message[1]);
            // TODO: attack!
          }
        };
  }

  @Override
  public void beginRound() throws GameActionException {
    updateUnitUtils();
    // turn into a pasture or noise tower
    if (buildingFinished) {
      RobotPlayer.run(RC);
    }
    messagingSystem.beginRound(handlers);
  }

  @Override
  public void run() throws GameActionException {
    if (luge()) { // luge = micro
      // set mode to ATTACK or something
      return;
      // send message?
    } else if (mode != Mode.ENGAGE
        && mode != Mode.ACQUIRE_TARGET
        && mode != Mode.BIRTH_DECIDE_MODE
        && mode != Mode.FIND_PASTR_LOC
        && mode != Mode.BUILD_PASTR) {
      if (ENEMY_MILK - ALLY_MILK > 50000 || ENEMY_PASTR_COUNT > ALLY_PASTR_COUNT) {
        changeMode(Mode.ACQUIRE_TARGET);
      } else {
        // try to build pastures if late in game
        // probably deprecated (doesn't happen)
        if (currentRound > 1800 && ENEMY_PASTR_COUNT > ALLY_PASTR_COUNT && !panicPastrBuilding) {
          if (currentCowsHere < 150) {
            panicPastrBuilding = true;
            dest = ALLY_HQ.subtract(ALLY_HQ.directionTo(ENEMY_HQ));
            mover.setTarget(dest);
            sneakToBuildingLoc = 1;
            changeMode(Mode.FIND_PASTR_LOC);
          } else if (currentCowsHere < 400) {
            panicPastrBuilding = true;
            mover.setTarget(ALLY_HQ);
            changeMode(Mode.RETURN_HOME);
          }
        } else if (!initialSweep) {
          // stand on rich squares
          MapLocation loc = findRichSquare();
          if (loc != null) {
            mover.setTarget(loc);
            changeMode(Mode.STAND_RICH_LOC);
          }
        }
      }
    }

    switch (mode) {
      case BIRTH_DECIDE_MODE:
        int robotNum = RC.senseRobotCount();
        if (ENEMY_PASTR_COUNT > ALLY_PASTR_COUNT + 1
            || (robotNum + currentRound / 100 > 22 && ENEMY_PASTR_COUNT > ALLY_PASTR_COUNT)) {
          roleIndex = ALLY_PASTR_COUNT % 4;
          role = Role.PASTR;
          changeMode(Mode.FIND_PASTR_LOC);
          dest =
              new MapLocation(
                  (ALLY_HQ.x + roleLocList[roleIndex].x) / 2,
                  (ALLY_HQ.y + roleLocList[roleIndex].y) / 2);
        } else {
          roleIndex = robotNum % 4;
          role = roleList[roleIndex];

          changeMode(Mode.SWEEP_OUT);
          dest = roleLocList[roleIndex];

          initialSweep = true;
        }
        mover.setTarget(dest);
        mover.move();
        break;
      case GOING_TO_MIDDLE:
        if (mover.arrived()) {
          decideNextMode();
        } else {
          mover.movePushHome();
        }
        break;
      case SWEEP_OUT:
        if (mover.arrived()) {
          dest =
              new MapLocation(
                  (2 * ALLY_HQ.x + roleLocList[roleIndex].x) / 3,
                  (2 * ALLY_HQ.y + roleLocList[roleIndex].y) / 3);
          mover.setTarget(dest);
          changeMode(Mode.RETURN_HOME);
        } else {
          mover.movePushHome();
        }
        break;
      case RETURN_HOME:
        if (mover.arrived()) {
          dest = roleLocList[roleIndex];
          mover.setTarget(dest);
          changeMode(Mode.SWEEP_OUT);

          initialSweep = false;
        } else {
          mover.movePushHome();
        }
        break;
      case STAND_RICH_LOC:
        if (!mover.arrived()) {
          mover.sneak();
        } else {
          RC.setIndicatorString(1, "cows here: " + currentCowsHere);
          if (currentCowsHere < 500) {
            mover.setTarget(roleLocList[roleIndex]);
            changeMode(Mode.SWEEP_OUT);
          }
        }
        break;
      case FIND_PASTR_LOC:
        if (mover.arrived()) {
          changeMode(Mode.BUILD_PASTR);
        } else {
          mover.execute(sneakToBuildingLoc);
        }
        break;
      case BUILD_PASTR:
        if (!RC.isConstructing() && RC.isActive()) {
          RC.construct(RobotType.PASTR);
        }

        if (RC.getConstructingRounds() == 0) {
          buildingFinished = true;
        }
        break;
      case ACQUIRE_TARGET:
        int mindistance = 10000000;
        MapLocation pastrTarget = null;
        for (MapLocation pastrLoc : ENEMY_PASTR_LOCS) {
          int d = currentLocation.distanceSquaredTo(pastrLoc);
          if (d < mindistance) {
            mindistance = d;
            pastrTarget = pastrLoc;
          }
        }

        if (pastrTarget == null) {
          mover.setTarget(ALLY_HQ);
          changeMode(Mode.RETURN_HOME);
        } else {
          mover.setTarget(pastrTarget);
          changeMode(Mode.ENGAGE);
          mover.move();
        }
        break;
      case ENGAGE:
        if (mover.arrived()) {
          changeMode(Mode.RETURN_HOME);
        } else {
          mover.move();
        }
        break;
      default:
        break;
    }
  }

  private void changeMode(Mode m) {
    RC.setIndicatorString(0, currentRound + ": " + m.toString() + " " + role.toString());
    mode = m;
  }

  private MapLocation findRichSquare() {
    double maxCows = currentCowsHere + 50 * COW_GROWTH[curX][curY] + 300; // favor staying here
    double curCows;

    MapLocation best = currentLocation;
    for (MapLocation current :
        MapLocation.getAllMapLocationsWithinRadiusSq(
            currentLocation, RobotType.SOLDIER.sensorRadiusSquared)) {
      try {
        if (RC.senseTerrainTile(current) == TerrainTile.OFF_MAP) continue;

        curCows = RC.senseCowsAtLocation(current) + 50 * COW_GROWTH[current.x][current.y];
        if (curCows > maxCows && RC.senseObjectAtLocation(current) == null) {
          best = current;
          maxCows = curCows;
        }
      } catch (GameActionException e) {
        e.printStackTrace();
      }
    }

    RC.setIndicatorString(1, "max nearby cows: " + maxCows + " at " + best);
    if (maxCows > 1000) {
      return best;
    }

    return null;
  }

  private void decideNextMode() {}

  @Override
  public void endRound() throws GameActionException {
    messagingSystem.endRound();
  }
}
Ejemplo n.º 22
0
 public static void timerStart() {
   startRoundNum = Clock.getRoundNum();
   startBytecodeNum = Clock.getBytecodeNum();
 }
 NavigationController(RobotController rc) {
   this.rc = rc;
   this.myTeam = rc.getTeam();
   this.mapIntDistribution = new int[rc.getMapWidth()][rc.getMapHeight()];
   this.dice = new Random(Clock.getRoundNum());
 }
Ejemplo n.º 24
0
 public static void debugBytecodes(String message) {
   System.out.format(
       "turn: %d, bytecodes: %d: %s\n", Clock.getRoundNum(), Clock.getBytecodeNum(), message);
 }
  public Boolean areDronesRestrictedToMiners() throws GameActionException {

    int clockNumber = Clock.getRoundNum();
    if (clockNumber > 800) return true;
    return false;
  }
Ejemplo n.º 26
0
  public Boolean shouldBlitzkrieg(int roundLimit) throws GameActionException {

    int clockNumber = Clock.getRoundNum();
    return clockNumber > roundLimit - 300;
  }
Ejemplo n.º 27
0
  // @param turns    the amount of turns that the budget was saved up for
  // @param progress the progress that we are in the build order
  public void updateBudgetingForBuildOrderProgress(int turns, int oreMined, int progress)
      throws GameActionException {

    int remainingOre = oreMined;

    // check if we need to take some for the supply depots
    if (progress >= this.civicRatios.length - 1) {

      if (this.broadcaster.budgetForType(RobotType.SUPPLYDEPOT) < 250) {

        this.broadcaster.incrementBudget(RobotType.SUPPLYDEPOT, (int) (remainingOre * 0.1));
        remainingOre *= 0.9;
      }
    }

    // firstly check the beavers
    final int beavers = this.broadcaster.robotCountFor(Beaver.type());
    int beaverOreAllocation = 0;
    if (beavers == 0) {

      beaverOreAllocation = 100;
    }

    // miners
    final int minerFactories = this.broadcaster.robotCountFor(MinerFactory.type());
    int minerOreAllocation = 0;
    if (minerFactories > 0 && this.broadcaster.robotCountFor(Miner.type()) < 30) {

      minerOreAllocation = (60 / (20 / turns));
      if (this.broadcaster.budgetForType(Miner.type()) >= minerFactories * 60)
        minerOreAllocation = 0;
    }

    // launchers
    final int aerospaceLabs = this.broadcaster.robotCountFor(AerospaceLab.type());
    int launcherOreAllocation = aerospaceLabs * (400 / (100 / turns));
    if (this.broadcaster.budgetForType(Launcher.type()) >= aerospaceLabs * 400)
      launcherOreAllocation = 0;

    // drones
    int droneOreAllocation = 0;
    if (Clock.getRoundNum() > 600 && this.broadcaster.robotCountFor(Drone.type()) == 0) {

      droneOreAllocation = 8;
    }

    int total =
        beaverOreAllocation + minerOreAllocation + launcherOreAllocation + droneOreAllocation;
    double multiplier = (total > remainingOre) ? remainingOre / (float) total : 1.0;

    this.broadcaster.incrementBudget(Beaver.type(), (int) (beaverOreAllocation * multiplier));
    this.broadcaster.incrementBudget(Miner.type(), (int) (minerOreAllocation * multiplier));
    this.broadcaster.incrementBudget(Launcher.type(), (int) (launcherOreAllocation * multiplier));
    this.broadcaster.incrementBudget(Drone.type(), (int) (droneOreAllocation * multiplier));

    remainingOre -= total * multiplier;
    if (remainingOre > 40 && oreMined < 500 /* first turn */) {

      beaverOreAllocation = 10;
      this.broadcaster.incrementBudget(Beaver.type(), beaverOreAllocation);
      remainingOre -= beaverOreAllocation;
    }
    this.broadcaster.incrementCivicBudget(remainingOre);
  }
Ejemplo n.º 28
0
  public Boolean shouldGoAllOut(int roundLimit) {

    int clockNumber = Clock.getRoundNum();
    return clockNumber > roundLimit - 150;
  }
Ejemplo n.º 29
0
  public void run() {

    super.run();

    try {

      // run some checks against harassment

      if (this.broadcaster.isEnemyTeamRushing()) this.isHarassing = false;

      int roundNumber = Clock.getRoundNum();
      if (roundNumber > 800) this.isHarassing = false;

      // harassment is A-ok

      if (this.robotController.isWeaponReady()) {

        this.attack();
      }

      if (this.robotController.isCoreReady()) {

        Boolean canMove = true;
        if (canMove) {

          RobotInfo[] enemiesInRange = this.unitController.nearbyEnemiesWithinTheirAttackRange();
          if (enemiesInRange.length > 0) {

            canMove = (this.movementController.moveAway(enemiesInRange) != null);
          }
        }

        if (this.isHarassing) {

          if (canMove) {

            canMove =
                (this.movementController.moveToward(this.locationController.enemyHQLocation())
                    != null);
          }

        } else {

          if (!this.shouldMobilize()) {

            if (canMove) {

              RobotInfo[] enemiesInTerritory = this.enemiesInTerritory();
              if (enemiesInTerritory.length > 0) {

                RobotInfo enemy = this.desiredEnemy(enemiesInTerritory);
                MapLocation bestLocation = enemy.location;
                canMove = this.movementController.moveToward(bestLocation) == null;
              }
            }

            // if we haven't moved toward an enemy location then we can go and stick to the plan
            if (canMove) {

              MapLocation rallyLocation = this.locationController.militaryRallyLocation();
              if (this.locationController.distanceTo(rallyLocation) > 18) {

                this.movementController.moveToward(rallyLocation);

              } else {

                this.movementController.moveTo(this.movementController.randomDirection());
              }
            }

          } else {

            this.mobilize();
          }
        }

        this.supplyController.transferSupplyIfPossible();
      }

    } catch (GameActionException exception) {
    }

    this.robotController.yield();
  }
  public Boolean shouldBlitzkrieg(int roundLimit) throws GameActionException {

    int clockNumber = Clock.getRoundNum();
    return clockNumber > 1700 || this.broadcaster.hasSeenLaunchers();
  }