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);
      }
    }
  }
Esempio n. 2
0
  public void run() {
    while (true) {
      if (rc.getType() == RobotType.SOLDIER) {
        switch (corner) {
          case 1:
            Utilities.MoveMapLocation(rc, new MapLocation(2, 2), true);
            break;
          case 2:
            Utilities.MoveMapLocation(rc, new MapLocation(rc.getMapWidth() - 3, 2), true);
            break;
          case 3:
            Utilities.MoveMapLocation(rc, new MapLocation(2, rc.getMapHeight() - 3), true);
            break;
          default:
            Utilities.MoveMapLocation(
                rc, new MapLocation(rc.getMapWidth() - 3, rc.getMapHeight() - 3), true);
            break;
        }

        if (rc.isActive()) {
          try {
            rc.construct(RobotType.PASTR);
          } catch (Exception e) {
          }
        }
      }
    }
  }
Esempio n. 3
0
 public void run() {
   while (true) {
     try {
       if (rc.isActive()) {
         if (rc.getLocation().equals(towerSpot)
             || (rc.getLocation().isAdjacentTo(towerSpot)
                 && !rc.canMove(rc.getLocation().directionTo(towerSpot)))) {
           rc.construct(RobotType.NOISETOWER);
         } else {
           Movement.MoveMapLocation(rc, towerSpot, false);
         }
       }
     } catch (Exception e) {
     }
   }
 }