Esempio n. 1
0
  static void runDefender(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();

    int status = rc.readBroadcast(squad + 1);
    int PASTRstatus = Channels.NTPASTRDecoding(status)[1];
    int NTstatus = Channels.NTPASTRDecoding(status)[0];

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

    // Create a PASTR/NT if not already there

    // System.out.println(allies.length + " " + rc.readBroadcast(Channels.numAlliesNeededChannel));
    if (allies.length >= rc.readBroadcast(Channels.numAlliesNeededChannel)
        && curr.distanceSquaredTo(target) < distanceThreshold
        && rc.isActive()) {
      if (PASTRstatus == 0) {
        rc.construct(RobotType.PASTR);
        rc.broadcast(squad + 1, Channels.NTPASTREncoding(NTstatus, 1));
        System.out.println("Constructing a PASTR...");

      } else if (NTstatus == 0) {
        rc.construct(RobotType.NOISETOWER);
        rc.broadcast(squad + 1, Channels.NTPASTREncoding(1, PASTRstatus));
        System.out.println("Constructing a NT...");
      }
    }

    // Then go to right place
    if (curr.distanceSquaredTo(target) > 8) Move.moveTo(rc, target);

    // Then 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);
    }

    // If there is a pastr and noisetower, don't block them!
    if (PASTRstatus == 1 && NTstatus == 1) {
      if (enemyRobots.length == 0 && rc.senseCowsAtLocation(rc.getLocation()) > 30) {
        Move.tryToSneak(rc);
      }
    }
  }