Beispiel #1
0
 private double estimateNearbyCowGrowth(MapLocation loc) {
   double ret = 0;
   int minX = Math.max(0, loc.x - 10);
   int minY = Math.max(0, loc.y - 10);
   int maxX = Math.min(rc.getMapWidth() - 1, loc.x + 10);
   int maxY = Math.min(rc.getMapHeight() - 1, loc.y + 10);
   for (int x = minX; x <= maxX; x++) {
     for (int y = minY; y <= maxY; y++) {
       if (rc.senseTerrainTile(new MapLocation(x, y)) != TerrainTile.VOID) ret += cowGrowth[x][y];
     }
   }
   return ret;
 }
Beispiel #2
0
  private void computeOutPath() throws GameActionException {
    Pair<Direction, Integer> pathingInfo = messagingSystem.readPathingInfo(dest);
    if (pathingInfo.first == null) {
      outPath = null;
      return;
    }
    RC.setIndicatorString(1, "Computing outPath");

    outPath = new LocSet();
    distances = new int[MAP_SIZE];
    MapLocation loc = dest;
    int d = pathingInfo.second;
    while (!loc.equals(DIJKSTRA_CENTER)) {
      pathingInfo = messagingSystem.readPathingInfo(loc);
      distances[outPath.size] = d - pathingInfo.second;
      outPath.insert(loc);
      loc = loc.subtract(pathingInfo.first);
    }

    int[] diffs = new int[outPath.size - 1];
    for (int i = diffs.length; --i > 0; ) {
      diffs[i] = distances[i + 1] - distances[i];
    }

    // heuristic to prefer further away points on the path (which may be closer to us)
    for (int i = 1; i < outPath.size; i++) {
      distances[i] = distances[i - 1] + Math.max(1, diffs[i - 1] * 100 / (100 + 10 * i));
    }
  }
Beispiel #3
0
 static boolean attack(RobotController rc, RobotInfo[] infos) throws GameActionException {
   RobotInfo best = null;
   double points = -Common.MAX_ID;
   for (RobotInfo info : infos) {
     double newPoints = 300 - info.health;
     newPoints /= Math.max(3, Math.max(info.viperInfectedTurns, info.zombieInfectedTurns));
     if (newPoints > points) {
       best = info;
       points = newPoints;
     }
   }
   if (best != null) {
     if (rc.canAttackLocation(best.location)) {
       rc.attackLocation(best.location);
       return true;
     }
   }
   return false;
 }
 private void updateDrawLoc() {
   if (RenderConfiguration.showDiscrete() || !isDoing(ActionType.MOVING)) {
     drawX = drawY = 0;
   } else {
     // still waiting perfection of delay system
     // float dist = .5f;
     float dist =
         (float) Math.max(Math.min(moving * (movementDelay / info.type.movementDelay), 1), 0);
     // System.out.println("moving: " + moving + "actionDelay: " + actionDelay + "total " +
     // totalActionRounds);
     drawX = -dist * dir.dx;
     drawY = -dist * dir.dy;
   }
 }
Beispiel #5
0
  // Decide whether to behave aggressively or defensively. Only be aggressive if we are in attack
  // mode
  // and there is a decent number of allies around, or if we are in any mode and we have a big
  // numbers advantage
  private MicroStance chooseMicroStance(MapLocation attackTarget) throws GameActionException {
    if (Strategy.active == Strategy.HQ_PASTR) return MicroStance.HARRASS;

    if (visibleEnemies.length == 0) {
      return MicroStance.AGGRESSIVE; // stance doesn't matter if there are no enemies
    } else {
      int numAllies = 1; // us
      numAllies +=
          Math.max(
              numOtherAlliedSoldiersInRange(here, RobotType.SOLDIER.sensorRadiusSquared),
              numOtherAlliedSoldiersInRange(Util.closest(visibleEnemies, here), 16));

      if (attackTarget == null) {
        if (numAllies >= visibleEnemies.length * 2 || numAllies > visibleEnemies.length + 3)
          return MicroStance.AGGRESSIVE;
        else return MicroStance.DEFENSIVE;
      } else {
        if (numAllies >= 2 && numAllies >= visibleEnemies.length - 1) return MicroStance.AGGRESSIVE;
        else return MicroStance.DEFENSIVE;
      }
    }
  }
Beispiel #6
0
  protected void transferEnergon() throws GameActionException {
    for (Robot robot : myRC.senseNearbyGroundRobots()) {
      try {
        RobotInfo robotInfo = myRC.senseRobotInfo(robot);

        if (robotInfo.team == myRC.getTeam()) {
          MapLocation robotLocation = robotInfo.location;

          if (myRC.getLocation().isAdjacentTo(robotLocation))
            myRC.transferEnergon(
                Math.max(
                    0,
                    Math.min(
                        robotInfo.maxEnergon - robotInfo.eventualEnergon,
                        myRC.getEnergonLevel() / 2)),
                robotLocation,
                RobotLevel.ON_GROUND);
        }
      } catch (GameActionException e) {

      }
    }
  }
Beispiel #7
0
  private Strategy pickStrategyByAnalyzingMap() throws GameActionException {
    // Guess how long it would take the enemy to rush a well-placed pastr
    MapLocation mapCenter = new MapLocation(rc.getMapWidth() / 2, rc.getMapHeight() / 2);
    int openPastrRushRounds =
        guessTravelRounds(theirHQ, mapCenter)
            + guessTravelRounds(mapCenter, computedBestPastrLocation);

    // my pathfinding rocks:
    int pastrTravelDelay =
        (int)
            (GameConstants.SOLDIER_MOVE_ACTION_DELAY
                * Math.sqrt(ourHQ.distanceSquaredTo(computedBestPastrLocation)));
    int pastrBuildDelay =
        (int)
            (GameConstants.HQ_SPAWN_DELAY_CONSTANT_1
                + RobotType.PASTR.captureTurns); // how long it will take for our pastr to go up
    openPastrRushRounds += pastrBuildDelay; // they can't rush until they know where to rush to

    // Guess how many rounds it would take us to win with a noise tower in the open
    double openPastrCowGrowth = estimateNearbyCowGrowth(computedBestPastrLocation);
    int openPastrRoundsNeeded = estimateTimeToWin(openPastrCowGrowth);
    int towerInefficiency = 150; // we don't start milking immediately, unfortunately
    openPastrRoundsNeeded += towerInefficiency;
    int fastTowerBuildDelay =
        RobotType.NOISETOWER.captureTurns
            + pastrTravelDelay; // account for the time needed to go there and set up a tower
    int safeTowerBuildDelay =
        RobotType.NOISETOWER.captureTurns
            + Math.max(
                81, pastrTravelDelay); // account for the time needed to go there and set up a
    // tower and wait for them to make a pastr
    int fastOpenPastrRoundsToWin = openPastrRoundsNeeded + fastTowerBuildDelay;
    int safeOpenPastrRoundsToWin = openPastrRoundsNeeded + safeTowerBuildDelay;

    // Guess how many rounds it would take us to win with a noise tower in the HQ
    double hqPastrCowGrowth = estimateNearbyCowGrowth(ourHQ);
    int hqPastrRoundsToWin = estimateTimeToWin(hqPastrCowGrowth);
    double hqSlowdown = estimateHQHerdObstacleSlowdownFactor();
    hqPastrRoundsToWin *= hqSlowdown;
    hqPastrRoundsToWin += RobotType.NOISETOWER.captureTurns;
    hqPastrRoundsToWin += towerInefficiency;

    //		Debug.indicate("map", 0, String.format("fastOpenPastrRoundsToWin = %d,
    // safeOpenPastrRoundsToWin = %d (cows = %f)", fastOpenPastrRoundsToWin,
    //				safeOpenPastrRoundsToWin, openPastrCowGrowth));
    //		Debug.indicate("map", 1, String.format("hqPastrRoundsToWin = %d (cows = %f, slowdown = %f),
    // rushRounds = %d", hqPastrRoundsToWin, hqPastrCowGrowth,
    //				hqSlowdown, openPastrRushRounds));

    Strategy strat;

    if (fastOpenPastrRoundsToWin < openPastrRushRounds) {
      // I can't imagine this actually happening, but if we can win before the rush even gets to us
      // then go for it!
      strat = Strategy.NOISE_THEN_ONE_PASTR;
    } else if (safeOpenPastrRoundsToWin < hqPastrRoundsToWin) {
      // otherwise we probably have to decide between a safe open pastr and an HQ pastr.
      // Go open pastr only if is significantly faster
      strat = Strategy.ONE_PASTR_THEN_NOISE;
    } else {
      strat = Strategy.HQ_PASTR;
    }

    return strat;
  }
Beispiel #8
0
 /**
  * Number of turns it will take to clear
  *
  * @param rubble
  * @return
  */
 public static double turnsToClearRubble(double rubble) {
   //        Amount left after clearing = max(95%*(original amount)-20,0)
   double turns = rubble / GameConstants.RUBBLE_CLEAR_FLAT_AMOUNT;
   return Math.max(0, turns);
 }
 public int movesAway(MapLocation start, MapLocation target) {
   return Math.max(Math.abs(target.x - start.x), Math.abs(target.y - start.y));
 }