Exemplo n.º 1
0
  // Keep track of deaths
  static void updateRobotDistro(RobotController rc) throws GameActionException {

    // Channel 1: distress: [SS][T][SS][T]...SS=squad, and T = type of distressed robots
    int in = rc.readBroadcast(Util.distress);
    // System.out.println("DISTRESS BROADCASTS: " + in);
    int numRobots =
        ("0" + String.valueOf(in)).length()
            / 3; // Must append a 0 to front of string to process so that numRobots works out
                 // correctly
    // System.out.println(numRobots + "this is the casualty num");
    for (int i = 0; i < numRobots; i++) { // so this never gets iterated through...
      int j = (int) (in / Math.pow(1000, i)) % 1000;
      int type = j % 10;
      int squad = j / 10;
      // System.out.println(type + "and " + squad);

      // subtract from squad count signal and robot type count
      //			System.out.println("ROBOT DIED from SQUAD: " + squad);
      //			System.out.println(Arrays.toString(robotTypeCount));
      robotTypeCount[type]--;
      //			System.out.println(Arrays.toString(robotTypeCount));
      int k = rc.readBroadcast(squad);
      rc.broadcast(squad, (k / 10000 - 1) * 10000 + k % 10000);
    }

    // reset the distress channel
    rc.broadcast(Util.distress, 0);
  }
Exemplo n.º 2
0
  private static void broadcastUpdatedBuildOrder() throws GameActionException {
    boolean scrambledEggs = false;
    // scramble check
    for (int i = 0; i < buildOrder.length; i++) {
      int tmp = rc.readBroadcast(Constants.buildOrderBeginChannel + i);
      if (!(tmp == 0
          || tmp == Constants.buildOrderArt
          || tmp == Constants.buildOrderGen
          || tmp == Constants.buildOrderSup
          || tmp == Constants.buildOrderHeal
          || tmp == Constants.buildOrderShield)) {
        scrambledEggs = true;
        break;
      }
    }

    if (!scrambledEggs) {
      for (int i = 0; i < buildOrder.length; i++) {
        buildOrder[i] = rc.readBroadcast(Constants.buildOrderBeginChannel + i);
      }
    } else {
      for (int i = 0; i < buildOrder.length; i++) {
        rc.broadcast(Constants.buildOrderBeginChannel + i, buildOrder[i]);
      }
    }
  }
Exemplo n.º 3
0
  public static boolean doWeNeedGenerator() throws GameActionException {
    if (rc.readBroadcast(Constants.campChannel) == Constants.campGenInProduction) return false;
    if (Clock.getRoundNum() - allInRound < 80) return false;
    if (rc.readBroadcast(Constants.commandChannel) == Constants.commandRally
        && rc.getTeamPower() > powerThreshold) return false;

    if (rc.getTeamPower() < minPowerThreshold && Clock.getRoundNum() > minRoundThreshold) {
      return true;
    }

    gencount = 0;
    soldiercount = 0;
    othercount = 0;

    Robot[] robos =
        rc.senseNearbyGameObjects(Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam());
    for (Robot r : robos) {
      RobotType rt = rc.senseRobotInfo(r).type;
      if (rt == RobotType.GENERATOR) ++gencount;
      else if (rt == RobotType.SOLDIER) ++soldiercount;
      else ++othercount;
    }

    double decay = .8;
    if (rc.hasUpgrade(Upgrade.FUSION)) {
      decay = .99;
    }

    if ((40 + (10 * gencount) - (1.6 * soldiercount) - (1 * othercount)) * decay < 1) {
      return true;
    }
    return false;
  }
Exemplo n.º 4
0
  // Determines squad of robot to by spawned next
  private static int nextSquadNum(RobotController rc) throws GameActionException {
    // If it reads that defensive robots are dying from channel 10
    int squad = rc.readBroadcast(Util.spawnNext);
    if (squad != 0 && squad < 11 && !rush) {
      rc.broadcast(Util.spawnNext, 0); // reset value
      //			System.out.println("spawning a replacement for defender" + squad);
      return squad;
    }

    // If starting out a rush, spawn enough attacking squads.
    boolean rushFailed = false; // temporary hot fix - later this should be a checkpoint
    int rushRetreat = computeRushRetreat(rc);
    if (rush && Clock.getRoundNum() < rushRetreat && !rushFailed) { // TODO decide when to stop rush
      for (int i = 11; i < 12; i++) {
        if ((rc.readBroadcast(i) / 10000) % 10 < 8) return i;
      }
    }

    // Else if didn't establish pastures yet, need defensive squads
    for (int i = 3; i < 3 + desiredPASTRs.length; i++) {
      if ((rc.readBroadcast(i) / 10000) % 10 < 6) return i;
    }

    // else spawn attackers
    for (int i = 11; i < 21; i++) {
      if ((rc.readBroadcast(i) / 10000) % 10 < 6) return i;
    }

    return 3;
  }
Exemplo n.º 5
0
  public static void runCowboy(RobotController rc, int assignment) throws GameActionException {

    if (assignment == 0) assignment = rc.readBroadcast(rc.getRobot().getID());

    int squad = Channels.assignmentDecoding(assignment)[0];
    int role = Channels.assignmentDecoding(assignment)[1];

    if (rc.readBroadcast(squad) == 0) {
      System.out.println(
          "My time has elapsed. I must die in battle with honor for my squad " + squad + "!");
      kamikaze(rc);
    }

    // checkIfBackupNeeded(rc);

    switch (role) {
      case 0:
        COWBOY.runDefender(rc, squad);
        break;
      case 1:
        COWBOY.runAttacker(rc, squad);
        break;
      case 2:
        COWBOY.runScout(rc, squad);
        break;
    }

    rc.yield();
  }
Exemplo n.º 6
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);
      }
    }
  }
Exemplo n.º 7
0
  static void runAttacker(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();

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

    // First steps away from home HQ
    if (curr.distanceSquaredTo(rc.senseHQLocation()) < 25) Move.tryToMove(rc);

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

    // Go to right place
    if (curr.distanceSquaredTo(target) > 7) {
      // System.out.println(target + " target " + allies.length + "ally length");
      Move.moveTo(rc, target);
    }
  }
Exemplo n.º 8
0
  // Soldiers call this to get pathing directions
  public Direction readResult(MapLocation here, MapLocation dest) {
    for (int page = 0; page < NUM_PAGES; page++) {
      int data;
      try {
        data = rc.readBroadcast(locChannel(page, here));
      } catch (GameActionException e) {
        e.printStackTrace();
        return null;
      }
      if (data != 0) { // all valid published results are != 0
        int y = data & 0xff;
        data >>= 8;
        int x = data & 0xff;
        data >>= 8;
        int actions = data & 0xff;
        data >>= 8;
        int dir = data & 0xf;

        if (cropX(dest.x) == x && cropY(dest.y) == y) {
          return Direction.values()[dir];
        }
      }
    }
    return null;
  }
Exemplo n.º 9
0
  static void spawnRobot(RobotController rc) throws GameActionException {

    if (rc.senseRobotCount() < GameConstants.MAX_ROBOTS && rc.isActive()) {

      int squad = nextSquadNum(rc);
      boolean spawnSuccess = false;
      Robot[] allies =
          rc.senseNearbyGameObjects(
              Robot.class, RobotType.SOLDIER.attackRadiusMaxSquared / 2, team);

      if (squad > 10) {
        spawnSuccess = tryToSpawn(rc, 1);
        if (spawnSuccess) {
          int j = Util.assignmentToInt(squad, 1);
          rc.broadcast(Util.spawnchannel, j);
          //					System.out.println("Spawned an attacker: " + j);
        }

      } else if (squad < 11) {
        spawnSuccess = tryToSpawn(rc, 0);
        if (spawnSuccess) {
          int j = Util.assignmentToInt(squad, 0);
          rc.broadcast(Util.spawnchannel, j);
          //					System.out.println("Spawned a defender: " + j);
        }
      }

      // Increase the squad member count by one
      if (spawnSuccess) {
        rc.broadcast(squad, rc.readBroadcast(squad) + 10000);
      }
    }
  }
Exemplo n.º 10
0
 public static Direction readHerdDir(MapLocation loc, RobotController rc)
     throws GameActionException {
   int channel = baseChannel + GameConstants.MAP_MAX_HEIGHT * loc.x + loc.y;
   int data = rc.readBroadcast(channel);
   if (data == 0) return null;
   Direction dir = Direction.values()[data - 10];
   return dir;
 }
 public QuickSupplierPlayer(RobotController rc) {
   super(rc);
   try {
     rc.broadcast(
         SupplierInProgressCountChannel, rc.readBroadcast(SupplierInProgressCountChannel) - 1);
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 12
0
 public static void expandIndividual() throws GameActionException {
   MapLocation expandLocation =
       new MapLocation(
           rc.readBroadcast(Constants.singleExpandXChannel),
           rc.readBroadcast(Constants.singleExpandYChannel));
   rc.broadcast(Constants.commandChannel, Constants.commandRally);
   while (true) {
     if (rc.getLocation().distanceSquaredTo(expandLocation)
         < 1) // if we are at the location of the rally point
     {
       if (rc.isActive()) // if we are allowed to capture
       {
         if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe()
             < rc.getTeamPower()) // if we have enough power to capture
         {
           int readIn = rc.readBroadcast(Constants.campChannel);
           if (readIn == Constants.campGen) {
             rc.broadcast(Constants.campChannel, Constants.campGenInProduction);
             rc.captureEncampment(RobotType.GENERATOR);
           } else if (readIn == Constants.campGenInProduction) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else if (readIn == Constants.campSupplier) {
             rc.captureEncampment(RobotType.SUPPLIER);
           } else // TODO: transmissions may be being scrambled, for now just make supplier
           {
             rc.captureEncampment(RobotType.SUPPLIER);
           }
           break;
         }
       }
     } else if (rc.senseNearbyGameObjects(Robot.class, expandLocation, 0, rc.getTeam()).length
         > 0) // if there is an allied robot on our rally point
     {
       expandLocation = findClosestEmptyCamp();
       if (expandLocation == null) {
         expandLocation = findRallyPoint();
       }
       goToLocation(expandLocation);
     } else {
       goToLocation(expandLocation);
     }
     rc.yield();
   }
 }
Exemplo n.º 13
0
  public void run() {
    while (true) {
      try {
        Robot[] enemies = rc.senseNearbyGameObjects(Robot.class, 35, rc.getTeam().opponent());

        if (rc.isActive()) {
          Movement.fire(rc, enemies, null);
          HQFunctions.SpawnSoldiers(rc);
        }

        if (Clock.getRoundNum() % 50 == 0) {
          System.out.println();
          System.out.println("Enemy Bots: ");
          int[] AllEnemies = FightMicro.AllEnemyBots(rc);
          for (int i = 0; i < AllEnemies.length; i++) {
            System.out.print(FightMicro.getBotLocation(AllEnemies[i]));
          }
          System.out.println();
        }

        int broadcast = rc.readBroadcast(rallyPoint2);
        if (broadcast != 0) {
          if (broadcast != fightZone) {
            fightZone = broadcast;
            roundSet = Clock.getRoundNum();
          }
          // now it is time for us to move on
          else if (roundSet + 75 < Clock.getRoundNum()) {
            fightZone = 0;
            rc.broadcast(rallyPoint2, 0);
          }
        }

        if (Clock.getRoundNum() % 5 == 0 && Clock.getRoundNum() > 100) {
          // HQFunctions.moveTargetLocationRandomly(rc);
          /*
          if (goneForPastr && (rc.sensePastrLocations(rc.getTeam()).length > 0 || roundNum > (Clock.getRoundNum() - 250)))
          {
              HQFunctions.setTargetLocation(rc, goneForPastr);
          }
          else
          {
              goneForPastr = HQFunctions.setTargetLocation(rc, goneForPastr);
              roundNum = Clock.getRoundNum();
          }*/
          HQFunctions.setTargetLocation(rc, true);
          // HQFunctions.findInitialRally(rc);

        }
      } catch (Exception e) {
      }
      rc.yield();
    }
  }
Exemplo n.º 14
0
  static void checkIfBackupNeeded(RobotController rc) throws GameActionException {

    int soldierSenseRad = (int) RobotType.SOLDIER.sensorRadiusSquared;

    Robot[] allies = rc.senseNearbyGameObjects(Robot.class, soldierSenseRad, rc.getTeam());
    Robot[] enemies =
        rc.senseNearbyGameObjects(Robot.class, soldierSenseRad, rc.getTeam().opponent());

    // System.out.println(allies.length + " " + enemies.length);

    boolean outnumbered = false;
    if (enemies.length == 0) outnumbered = false;
    else if ((double) allies.length / enemies.length <= 1.5) outnumbered = true;

    if (outnumbered && rc.readBroadcast(Channels.backupChannel) == 0) {
      int squad = rc.readBroadcast(rc.getRobot().getID());
      rc.broadcast(
          Channels.backupChannel, Channels.backupEncoding(rc.getLocation(), squad, enemies.length));
      System.out.println("COWBOY sending help call");
    }
  }
Exemplo n.º 15
0
  static void runScout(RobotController rc, int squad) throws GameActionException {
    int squadInfo = rc.readBroadcast(squad);
    MapLocation target = Conversion.intToMapLocation(Channels.scoutDecoding(squadInfo)[1]);
    MapLocation curr = rc.getLocation();

    if (curr.distanceSquaredTo(target) > 50) Move.moveTo(rc, target);
    else {
      int start = Channels.scoutDecoding(squadInfo)[0];
      rc.broadcast(
          Channels.scoutChannel, Channels.scoutEncoding((Clock.getRoundNum() - start), target, 1));
    }
  }
Exemplo n.º 16
0
 // Soldiers call this to get pathing directions
 public static Direction readResult(MapLocation here, MapLocation dest)
     throws GameActionException {
   for (int page = 0; page < NUM_PAGES; page++) {
     int data = rc.readBroadcast(locChannel(page, here));
     if (data != 0) { // all valid published results are != 0
       data -= 10000000;
       if (((dest.x * MAP_HEIGHT) + (dest.y)) == (data % 100000)) {
         return Direction.values()[data / 100000];
       }
     }
   }
   return null;
 }
Exemplo n.º 17
0
  private static void expand() throws GameActionException {
    // rallyPoint = findClosestLocation(rc.senseAllEncampmentSquares());
    if (!localscan) {
      rallyPoint = findClosestEmptyCamp();
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {
      if (!localscan) {
        rallyPoint = findFurthestLocalCamp();
        localscan = true;
      }
    }
    if (rc.getLocation().distanceSquaredTo(rallyPoint)
        < 1) // if we are at the location of the rally point
    {

      if (rc.isActive()) // if we are allowed to capture
      {
        if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe()
            < rc.getTeamPower()) // if we have enough power to capture
        {
          int readIn = rc.readBroadcast(Constants.campChannel);
          if (readIn == Constants.campGen) {
            rc.broadcast(Constants.campChannel, Constants.campGenInProduction);
            rc.captureEncampment(RobotType.GENERATOR);
          } else if (readIn == Constants.campGenInProduction) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else if (readIn == Constants.campSupplier) {
            rc.captureEncampment(RobotType.SUPPLIER);
          } else // TODO: transmissions may be being scrambled, for now just make supplier
          {
            rc.captureEncampment(RobotType.SUPPLIER);
          }
        }
      }
    } else if (rc.senseNearbyGameObjects(Robot.class, rallyPoint, 0, rc.getTeam()).length
        > 0) // if there is an allied robot on our rally point
    {
      rallyPoint = findClosestEmptyCamp();
      if (rallyPoint == null) {
        rallyPoint = findRallyPoint();
      }
      goToLocation(rallyPoint);
    } else {
      goToLocation(rallyPoint);
    }
  }
Exemplo n.º 18
0
  private static boolean reactiveRush(RobotController rc) throws GameActionException {
    // TODO if we are losing in an economy based game
    int ally = rc.sensePastrLocations(rc.getTeam()).length;
    int enemy = rc.sensePastrLocations(rc.getTeam().opponent()).length;

    if (rush) {
      return true;
    } else if (enemy > ally) {
      //			System.out.println("REACTIVE RUSH");
      return true;
    } else if (rc.readBroadcast(Util.failedPastr) > 0) {
      //			System.out.println("REACTIVE RUSH 1");
      return true;
    }

    return false;
  }
Exemplo n.º 19
0
 /**
  * Reads a message on channelType. Checks if signature is correct.
  *
  * @param channelType
  * @return
  */
 public static Message read(ChannelType channelType) {
   try {
     if (rc != null) {
       for (int channelNo : getChannelNos(channelType)) {
         int rawMessage = rc.readBroadcast(channelNo);
         if (rawMessage == 0) {
           return new Message(false, true);
         }
         byte testSignature = (byte) (rawMessage >> 24);
         if (signature == testSignature) { // verified
           int body = rawMessage & signatureMask;
           return new Message(body, true, false); // true means message is valid
         }
       }
     }
     return new Message(false, false);
   } catch (Exception e) {
     return new Message(false, false);
   }
 }
Exemplo n.º 20
0
  // Put team and enemy team pasture, squad, and role info into channels
  static void updateSquadLocs(RobotController rc) throws GameActionException {
    // DEFENDER CHANNELS - 3 to about 8
    // format: [N][XXYY] where N is robot count in the squad and XXYY are coordinates

    // RUSH CHANNEL - 11
    MapLocation[] enemyPASTRs = rc.sensePastrLocations(enemy);
    MapLocation rallyPoint = determineRallyPoint(rc);

    // TODO surround enemy HQ - rush ENDGAME :)
    if (rc.readBroadcast(Util.rushSuccess) > 0) {
      rc.broadcast(11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(HQ.enemyHQ));
    } else if (rush && Clock.getRoundNum() < 1000) {
      // System.out.println("rush and under 1000");
      if (enemyPASTRs.length > 0) {
        rc.broadcast(11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(enemyPASTRs[0]));
        attackedEnemy = true;
      } else if (attackedEnemy && enemyPASTRs.length == 0) { // shut down headquarters and endgame
        rc.broadcast(
            11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(rc.senseEnemyHQLocation()));
      } else rc.broadcast(11, (rc.readBroadcast(11) / 10000) * 10000 + Util.locToInt(rallyPoint));
    }

    for (int i = 0; i < enemyPASTRs.length; i++) {
      if (enemyPASTRs[i].distanceSquaredTo(rc.senseEnemyHQLocation()) < 36) {
        // the pastr is untouchable
        rc.broadcast(
            i + 12, (rc.readBroadcast(i + 12) / 10000) * 10000 + Util.locToInt(rallyPoint));
      } else {
        rc.broadcast(
            i + 12, (rc.readBroadcast(i + 12) / 10000) * 10000 + Util.locToInt(enemyPASTRs[i]));
      }
    }

    for (int i = 0; i < desiredPASTRs.length; i++) {
      rc.broadcast(
          i + 3, (rc.readBroadcast(i + 3) / 10000) * 10000 + Util.locToInt(desiredPASTRs[i]));
      // System.out.println("SQUAD TRACKER " + (i+3));
    }
  }
Exemplo n.º 21
0
  public static void run(RobotController rc) {
    int type = 0;

    while (true) {
      try {
        if (rc.getType() == RobotType.HQ) {
          new SmartHQ(rc).run();
        } else if (rc.getType() == RobotType.NOISETOWER) {
          new GenericTower(rc, false).run();
        } else if (rc.getType() == RobotType.PASTR) {
          rc.yield();
        } else {
          if (type == 0) {
            type = rc.readBroadcast(0);
          } else if (type == SmartHQ.DURAN) {
            // new Duran(rc).run();
          } else if (type == SmartHQ.GHOST) {
            // new Ghost(rc).run();
          } else if (type == SmartHQ.GOLIATH) {
            // new Goliath(rc).run();
          } else if (type == SmartHQ.MARINE) {
            // new Marines(rc).run();
          } else if (type == SmartHQ.MULE) {
            new fastMULE(rc, true).run();
          } else if (type == SmartHQ.TOWER) {
            new SmartTower(rc, true).run();
          } else if (type == SmartHQ.TROLL) {
            // new Scout(rc).run();
          } else if (type == SmartHQ.OPTOWER) {
            new SmartTower(rc, false).run();
          } else if (type == SmartHQ.OPMULE) {
            new fastMULE(rc, false).run();
          }
        }
      } catch (Exception e) {
      }
    }
  }
Exemplo n.º 22
0
 private static void rally() throws GameActionException {
   rallyPoint = findRallyPoint();
   // if we are fairly close to the rally point and we have the necessary soldier counts to make up
   // a wave, gogogogogo
   if (rc.getLocation().distanceSquaredTo(rallyPoint) < rallyRadius) {
     if (rc.readBroadcast(Constants.attackChannel) == Constants.attackAllIn) {
       while (true) {
         Robot[] closeEnemyRobots =
             rc.senseNearbyGameObjects(Robot.class, rc.getLocation(), 14, rc.getTeam().opponent());
         if (closeEnemyRobots.length == 0) {
           goToLocation(rc.senseEnemyHQLocation());
         } else {
           goToLocation(Util.findClosestRobot(rc, closeEnemyRobots));
         }
         rc.yield();
       }
     } else {
       goToLocation(rallyPoint);
     }
   } else {
     goToLocation(rallyPoint);
   }
 }
Exemplo n.º 23
0
  public static void hqCode(RobotController myRC) throws GameActionException {
    rc = myRC;
    Direction defaultSpawnDir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
    evaluateMap();
    while (true) {
      rc.broadcast(Constants.attackChannel, 0);
      enemyRobots =
          rc.senseNearbyGameObjects(
              Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam().opponent());

      if (expandOrRally()) {
        rc.broadcast(Constants.commandChannel, Constants.commandExpand);
        broadcastUpdatedBuildOrder();

        MapLocation rally = findRallyPoint();
        rc.broadcast(Constants.rallyXChannel, rally.x);
        rc.broadcast(Constants.rallyYChannel, rally.y);
      } else {
        MapLocation rally = findRallyPoint();
        rc.broadcast(Constants.rallyXChannel, rally.x);
        rc.broadcast(Constants.rallyYChannel, rally.y);
        rc.broadcast(Constants.commandChannel, Constants.commandRally);
      }

      if (rc.isActive()) {
        int readIn = rc.readBroadcast(Constants.campChannel);

        if (!doWeNeedGenerator()) {
          rc.broadcast(Constants.campChannel, Constants.campSupplier);

          // Spawn a soldier
          Team defaultScan = rc.senseMine(rc.getLocation().add(defaultSpawnDir));
          if (rc.canMove(defaultSpawnDir) && (defaultScan == null || defaultScan == rc.getTeam())) {
            rc.spawn(defaultSpawnDir);
          } else {
            for (Direction d : Direction.values()) // TODO: optimize secondary direction finding
            {
              if (d != Direction.OMNI && d != Direction.NONE) {
                Team scan = rc.senseMine(rc.getLocation().add(d));
                if (rc.canMove(d) && (scan == null || scan == rc.getTeam())) {
                  rc.spawn(d);
                  break;
                }
              }
            }
            if (rc.isActive()) {
              // if there are no valid spawn directions
              rc.researchUpgrade(Upgrade.NUKE);
            }
          }
        } else // we do need a generator
        {
          if (readIn == Constants.campSupplier
              || (readIn != Constants.campGenInProduction && readIn != Constants.campGen)) {
            rc.broadcast(Constants.campChannel, Constants.campGen);
          }
          if (!rc.hasUpgrade(Upgrade.FUSION)) {
            rc.researchUpgrade(Upgrade.FUSION);
          } else if (!rc.hasUpgrade(Upgrade.DEFUSION)) {
            rc.researchUpgrade(Upgrade.DEFUSION);
          } else {
            rc.researchUpgrade(Upgrade.NUKE);
          }
        }
      }

      if (Clock.getRoundNum() > 200) {
        if (rc.senseEnemyNukeHalfDone()) {
          rc.broadcast(Constants.commandChannel, Constants.commandEnemyNukeHalfDone);
          while (!rc.hasUpgrade(Upgrade.DEFUSION)) {
            if (rc.isActive()) {
              rc.researchUpgrade(Upgrade.DEFUSION);
            }
            rc.yield();
          }
          enemyRobots =
              rc.senseNearbyGameObjects(
                  Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam().opponent());
        }
      }
      shallWeAllIn();
      rc.yield();
    }
  }
Exemplo n.º 24
0
 private static int readPageMetadata(int page) throws GameActionException {
   int channel = pageMetadataBaseChannel + page;
   int data = rc.readBroadcast(channel);
   return data;
 }
Exemplo n.º 25
0
 public static int HQCommand() throws GameActionException // true for expand
     {
   return rc.readBroadcast(Constants.commandChannel);
 }
Exemplo n.º 26
0
 private static MapLocation findRallyPoint() throws GameActionException {
   return new MapLocation(
       rc.readBroadcast(Constants.rallyXChannel), rc.readBroadcast(Constants.rallyYChannel));
 }