public Direction fleeClosest(Robot[] en) throws GameActionException { MapLocation min = rc.senseLocationOf(en[0]); int minDist = min.distanceSquaredTo(cur); for (int i = 1; i < en.length; i++) { MapLocation next = rc.senseLocationOf(en[i]); int dist = next.distanceSquaredTo(cur); if (minDist < dist) { min = next; minDist = dist; } } Direction desired = cur.directionTo(min); return m.moveInDir(desired); }
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; }