예제 #1
0
파일: Rook.java 프로젝트: NicoAdams/JChess
  public ArrayList<Position> getMoveListIgnoreCheck(Position current, Board b) {
    int[] rowDeltas = new int[] {1, 0, -1, 0};
    int[] colDeltas = new int[] {0, 1, 0, -1};

    return Mover.getMoves(
        current, b, rowDeltas, colDeltas, color, Mover.Type.STRAIGHT, Mover.Capture.ALLOWED);
  }
  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;
  }
 @Override
 protected Contact getContactForEnterRangeEvent(Sensor sensor, Mover target) {
   Contact contact = contacts.get(target);
   if (contact == null) {
     contact = new SensorContact((Mover) target);
     contacts.put(target, contact);
   }
   System.out.println(
       "TestMediator providing contact "
           + contact.toString()
           + " for target "
           + target.toString());
   return contact;
 }
 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 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);
  }
 @Override
 protected void targetIsEnteringSensorRange(Sensor sensor, Mover target) {
   System.out.println(target.toString() + " is entering range of " + sensor.toString());
   System.out.println("TestMediator does no special processing before scheduling detections");
 }