Esempio n. 1
0
  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();
  }
 private static MapLocation findRallyPoint() {
   MapLocation enemyLoc = rc.senseEnemyHQLocation();
   MapLocation ourLoc = rc.senseHQLocation();
   int x = (enemyLoc.x + 3 * ourLoc.x) / 4;
   int y = (enemyLoc.y + 3 * ourLoc.y) / 4;
   MapLocation rallyPoint = new MapLocation(x, y);
   return rallyPoint;
 }
 private static MapLocation findBarracks() {
   MapLocation ourLoc = rc.senseHQLocation();
   MapLocation enemyLoc = rc.senseEnemyHQLocation();
   int x = (enemyLoc.x + 3 * ourLoc.x) / 4; // makes the meeting place 1/4 of the way to the enemy.
   int y = (enemyLoc.y + 3 * ourLoc.y) / 4;
   MapLocation barracks = new MapLocation(x, y);
   return barracks;
 }
Esempio n. 4
0
  public static boolean turnNuke(RobotController rc) {
    boolean nuke = false;

    GameObject[] nearByEnemies =
        rc.senseNearbyGameObjects(Robot.class, 35, rc.getTeam().opponent());
    GameObject[] nearByFriends;

    if (nearByEnemies.length == 0) {

    } else {
      MapLocation[] nearBySpots = new MapLocation[8];

      Direction dir = rc.getLocation().directionTo(rc.senseHQLocation());

      for (int i = 0; i < nearBySpots.length; i++) {
        nearBySpots[i] = rc.getLocation().add(dir);
        dir.rotateLeft();
      }

      int[] damage = new int[8];

      for (int i = 0; i < damage.length; i++) {
        nearByEnemies =
            rc.senseNearbyGameObjects(Robot.class, nearBySpots[i], 2, rc.getTeam().opponent());
        nearByFriends = rc.senseNearbyGameObjects(Robot.class, nearBySpots[i], 2, rc.getTeam());

        int total = nearByEnemies.length - nearByFriends.length;
        damage[i] = total;
      }

      int largest = damage[0];
      int index = 0;

      for (int k = 1; k < damage.length; k++) {
        if (largest < damage[k]) {
          largest = damage[k];
          index = k;
        }
      }

      if (largest > 1) {
        // Nuke nuker = new Nuke(rc, nearBySpots[index]);
        // nuker.run();
        return true;
      } else {
        return false;
      }
    }
    return nuke;
  }
Esempio n. 5
0
  protected static void init(RobotController theRC) throws GameActionException {
    rc = theRC;
    us = rc.getTeam();
    them = us.opponent();

    ourHQ = rc.senseHQLocation();
    theirHQ = rc.senseEnemyHQLocation();

    mapWidth = rc.getMapWidth();
    mapHeight = rc.getMapHeight();

    FastRandom.init();
    MessageBoard.init(theRC);
    Bfs.init(theRC);
  }
Esempio n. 6
0
  private static MapLocation findRallyPoint() throws GameActionException {

    MapLocation closestEnemy = null;
    closestEnemy = Util.findClosestRobot(rc, enemyRobots);

    if (closestEnemy != null
        && closestEnemy.distanceSquaredTo(rc.getLocation()) < rushDistance * .2) {
      return closestEnemy;
    }

    MapLocation enemyLoc = rc.senseEnemyHQLocation();
    MapLocation ourLoc = rc.senseHQLocation();
    int x = (enemyLoc.x + 2 * ourLoc.x) / 3;
    int y = (enemyLoc.y + 2 * ourLoc.y) / 3;
    return new MapLocation(x, y);
  }
Esempio n. 7
0
  // finds best corner to collect milk where the return is an int as follows:
  // 1  2
  // 3  4
  public static int findBestCorner(RobotController rc) {
    double[][] pasture = rc.senseCowGrowth();

    double[] voids = new double[4];
    double[] cows = new double[4];
    double[] distances = new double[4];

    double max = 0;
    int corner = 0;
    double total = 0;
    MapLocation target = null;
    MapLocation current = rc.senseHQLocation();

    for (int k = 1; k <= 4; k++) {
      switch (k) {
        case 1:
          target = new MapLocation(5, 5);
          break;
        case 2:
          target = new MapLocation(rc.getMapWidth() - 6, 5);
          break;
        case 3:
          target = new MapLocation(5, rc.getMapHeight() - 6);
          break;
        default:
          target = new MapLocation(rc.getMapWidth() - 6, rc.getMapHeight() - 6);
          break;
      }

      while (target.x != current.x || target.y != current.y) {
        if (rc.senseTerrainTile(current) == TerrainTile.VOID) {
          total++;
        }
        current = current.add(current.directionTo(target));
      }

      voids[k - 1] = total;
      distances[k - 1] = rc.senseHQLocation().distanceSquaredTo(target);

      total = 0;
      current = rc.senseHQLocation();
    }

    // top left corner
    for (int k = 0; k < 10; k++) {
      for (int a = 0; a < 10; a++) {
        total += pasture[k][a];
      }
    }
    cows[0] = total;

    total = 0;

    // top right corner
    for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) {
      for (int a = 0; a < 10; a++) {
        total += pasture[k][a];
      }
    }
    cows[1] = total;

    total = 0;

    // bottom left corner
    for (int k = 0; k < 10; k++) {
      for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) {
        total += pasture[k][a];
      }
    }
    cows[2] = total;

    total = 0;

    // bottom right corner
    for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) {
      for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) {
        total += pasture[k][a];
      }
    }
    cows[3] = total;

    for (int k = 0; k < 4; k++) {
      total = cows[k] * 1 - voids[k] * 50 - distances[k] * .001;

      if (total > max) {
        max = total;
        corner = k + 1;
      }
    }

    return corner;
  }