コード例 #1
0
  public Direction flee() throws GameActionException {
    cur = rc.getLocation();
    // (r+2)^2 ~= r^2 + 20 if r ~ 4
    if (m.inDangerRadius(cur)) {
      // too close to splash range
      return m.moveInDir(c.enemyhq.directionTo(cur));
    }

    Robot[] en = sensor.getBots(Sensor.ATTACK_RANGE_ENEMIES);
    if (en.length > 0) {
      return fleeWeighted(en);
    }
    //		en= sensor.getBots(Sensor.SENSE_RANGE_ENEMIES);
    //		if (en.length > 0) {
    //			return fleeWeighted(en);
    //		}

    // no enemies
    return Direction.OMNI;
  }
コード例 #2
0
  public Direction fleeWeighted(Robot[] en) throws GameActionException {
    Robot[] allies = sensor.getBots(Sensor.SENSE_RANGE_ALLIES);
    int yDir = 0;
    int xDir = 0;
    int numEnemies = en.length;
    int numAllies = allies.length;

    for (Robot e : en) {
      MapLocation eLoc = rc.senseRobotInfo(e).location;
      xDir -= eLoc.x;
      yDir -= eLoc.y;
    }
    for (Robot a : allies) {
      MapLocation aLoc = rc.senseRobotInfo(a).location;
      xDir += aLoc.x;
      yDir += aLoc.y;
    }
    xDir += numEnemies * cur.x - numAllies * cur.x;
    yDir += numEnemies * cur.y - numAllies * cur.y;

    Direction desired = cur.directionTo(cur.add(xDir, yDir));

    return m.smartMove(desired);
  }