Example #1
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);
  }
Example #2
0
  private void harrassToward(MapLocation enemySoldier) throws GameActionException {
    Direction toEnemy = here.directionTo(enemySoldier);

    if (FastRandom.randInt(4) == 0 && numOtherAlliedSoldiersInRange(here.add(toEnemy, 2), 1) == 0) {
      rc.attackSquare(here.add(toEnemy, 2));
      return;
    }

    int[] numEnemiesAttackingDirs = countNumEnemiesAttackingMoveDirs();

    Direction[] tryDirs;
    Robot[] alliedRobots =
        rc.senseNearbyGameObjects(Robot.class, here, RobotType.SOLDIER.sensorRadiusSquared, us);
    RobotInfo[] allies = Util.senseAllInfos(alliedRobots, rc);
    MapLocation closestAlly = Util.closest(allies, here);
    if (closestAlly == null) {
      tryDirs =
          new Direction[] {
            toEnemy,
            toEnemy.rotateLeft(),
            toEnemy.rotateRight(),
            toEnemy.rotateLeft().rotateLeft(),
            toEnemy.rotateRight().rotateRight(),
            toEnemy.rotateLeft().rotateLeft().rotateLeft(),
            toEnemy.rotateRight().rotateRight().rotateRight()
          };
    } else {
      Direction repel = closestAlly.directionTo(here);
      tryDirs =
          new Direction[] {
            repel,
            repel,
            repel,
            repel,
            toEnemy,
            toEnemy.rotateLeft(),
            toEnemy.rotateRight(),
            toEnemy.rotateLeft().rotateLeft(),
            toEnemy.rotateRight().rotateRight(),
            toEnemy.rotateLeft().rotateLeft().rotateLeft(),
            toEnemy.rotateRight().rotateRight().rotateRight()
          };
    }
    for (int t = 0; t < 3; t++) {
      int i = FastRandom.randInt(tryDirs.length);
      Direction tryDir = tryDirs[i];
      if (!rc.canMove(tryDir)) continue;
      if (numEnemiesAttackingDirs[tryDir.ordinal()] > 0) continue;
      if (Util.inHQAttackRange(here.add(tryDir), theirHQ)) continue;
      Debug.indicate(
          "micro",
          1,
          String.format(
              "harassing enemy soldier; direction %d; attackers = %d %d %d %d %d %d %d %d",
              tryDir.ordinal(),
              numEnemiesAttackingDirs[0],
              numEnemiesAttackingDirs[1],
              numEnemiesAttackingDirs[2],
              numEnemiesAttackingDirs[3],
              numEnemiesAttackingDirs[4],
              numEnemiesAttackingDirs[5],
              numEnemiesAttackingDirs[6],
              numEnemiesAttackingDirs[7]));
      rc.move(tryDir);
      return;
    }
    rc.attackSquare(here.add(toEnemy, 2));
    Debug.indicate("micro", 1, "can't safely approach enemy soldier");
  }