Exemple #1
0
  static void runAttacker(RobotController rc, int squad) throws GameActionException {

    Team team = rc.getTeam();
    Team enemy = team.opponent();

    int squadInfo = rc.readBroadcast(squad);
    MapLocation target = Conversion.intToMapLocation(squadInfo);
    MapLocation curr = rc.getLocation();

    Robot[] allies =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().attackRadiusMaxSquared * 2, team);

    // First steps away from home HQ
    if (curr.distanceSquaredTo(rc.senseHQLocation()) < 25) Move.tryToMove(rc);

    // attack!
    Robot[] enemyRobots =
        rc.senseNearbyGameObjects(Robot.class, rc.getType().sensorRadiusSquared * 2, enemy);
    MapLocation eloc = Attack.nearestEnemyLoc(rc, enemyRobots, rc.getLocation());

    if (eloc != null) {
      if (rc.isActive()) Move.moveToward(rc, eloc);
      if (rc.isActive() && rc.canAttackSquare(eloc)) rc.attackSquare(eloc);
    }

    // Go to right place
    if (curr.distanceSquaredTo(target) > 7) {
      // System.out.println(target + " target " + allies.length + "ally length");
      Move.moveTo(rc, target);
    }
  }
  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();
  }
Exemple #3
0
  private static MapLocation findHQpstr(MapLocation origPstr) throws GameActionException {
    // returns the first pstr location, close to the HQ so it can be defended well
    MapLocation HQ = hq.senseHQLocation();
    MapLocation enemyHQ = hq.senseEnemyHQLocation();
    Direction toward_enemy = HQ.directionTo(enemyHQ);
    MapLocation HQpstr = origPstr;

    int r = hq.getType().sensorRadiusSquared;
    // System.out.println(r);

    for (Direction i : Util.allDirections) {
      MapLocation p = HQ.add(i, 10); // perimeter location
      //			System.out.println("map" + p.x + "" + p.y);
      if (p.x < 0 || p.x > mapX || p.y < 0 || p.y > mapY || i == toward_enemy) continue;
      else {
        int a = terrainMap[p.x][p.y];
        System.out.println(a);
        if (a == NORMAL || a == ROAD) {
          return p;
        }
      }
    }

    //		if (cowDensMap[test.x, test.y] > 1) { //check to see if that spot exists
    //			HQpstr = HQ.add(away_from_enemy);
    //		} else { //that spot is probably in a wall, which would be weird, but possible
    //
    //		}
    return HQpstr;
  }
 public SpawnStrategy(RobotController rc) throws GameActionException {
   this.rc = rc;
   this.info = rc.senseRobotInfo(rc.getRobot());
   this.hqLocation = rc.senseHQLocation();
   this.directionToEnemy = this.hqLocation.directionTo(rc.senseEnemyHQLocation());
   // this.primarySpawnLocation = hqLocation.add(directionToEnemy);
   this.enemyTeam = this.info.team.opponent();
 }
 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;
 }
Exemple #7
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;
  }
Exemple #8
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);
  }
Exemple #9
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);
  }
Exemple #10
0
  public static void initializeGameVars(RobotController rc) throws GameActionException {
    hq = rc;

    team = hq.getTeam();
    enemy = team.opponent();
    cowDensMap = hq.senseCowGrowth();
    mapY = cowDensMap.length;
    mapX = cowDensMap[0].length;
    idealNumPastures = computeNumPastures();
    enemyHQ = rc.senseEnemyHQLocation();
    teamHQ = rc.senseHQLocation();
    createTerrainMap();
    desiredPASTRs = findPastureLocs();
    //    	System.out.println("Desired pastures : " + Arrays.deepToString(desiredPASTRs));

    initializerRun = true;

    rush = startRush(rc);

    rand = new Random(17);
  }
Exemple #11
0
  public static void run(RobotController rc) {

    enemyHQ = rc.senseEnemyHQLocation();
    myHQ = rc.senseHQLocation();
    mapHeight = rc.getMapHeight();
    mapWidth = rc.getMapWidth();

    while (true) {
      try {
        if (rc.getType() == RobotType.SOLDIER) {
          if (rc.isActive()) soldierRun(rc);
        } else if (rc.getType() == RobotType.HQ) {
          hqCode.hqRun(rc, enemyHQ);
        } else if (rc.getType() == RobotType.ARTILLERY) {
          encampCode.artilleryRun(rc);
        }
        rc.yield();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Exemple #12
0
  public static void initUtils(RobotController rc) {
    RC = rc;
    ID = RC.getRobot().getID();

    MAP_WIDTH = rc.getMapWidth();
    MAP_HEIGHT = rc.getMapHeight();

    ALLY_TEAM = rc.getTeam();
    ENEMY_TEAM = (ALLY_TEAM == Team.A) ? Team.B : Team.A;
    ALLY_HQ = rc.senseHQLocation();
    ENEMY_HQ = rc.senseEnemyHQLocation();

    birthRound = Clock.getRoundNum();

    random = new Random(((long) ID << 32) ^ Clock.getRoundNum());

    //		messagingSystem = new MessagingSystem();

    for (Upgrade upgrade : Upgrade.values()) {
      UPGRADES_RESEARCHED[upgrade.ordinal()] = RC.hasUpgrade(upgrade);
    }
    updateUtils();
  }
Exemple #13
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;
  }