コード例 #1
0
ファイル: HQ.java プロジェクト: TeamYOLO/BC2013
  public static boolean expandOrRally() throws GameActionException // true for expand
      {
    // rush distance
    // double rushDistance = rc.senseHQLocation().distanceSquaredTo(rc.senseEnemyHQLocation());
    // number of encampments

    if (!expandPhase) {
      singleExpand();
      return false;
    }

    int numAlliedCamps = rc.senseAlliedEncampmentSquares().length;
    if (numAlliedCamps > 13) {
      rc.broadcast(Constants.commandChannel, Constants.commandRally);
      expandPhase = false;
      return false;
    }

    if (numAlliedCamps >= optimalBuildings) {
      rc.broadcast(Constants.commandChannel, Constants.commandRally);
      expandPhase = false;
      return false;
    }

    rc.broadcast(Constants.commandChannel, Constants.commandExpand);
    return true;
  }
コード例 #2
0
ファイル: HQ.java プロジェクト: TeamYOLO/BC2013
  private static void shallWeAllIn() throws GameActionException {
    if (rc.senseEnemyNukeHalfDone() && Clock.getRoundNum() < 300) {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      return;
    }

    int massedRobos = 0;
    double massedAmountNeeded = .5 * (40 + (10 * gencount) - (1 * othercount));

    if (rc.senseEnemyNukeHalfDone()) massedAmountNeeded -= 10;

    int rallyRadius = 33;
    if (massedAmountNeeded > 50) rallyRadius = 63;

    Robot[] robos =
        rc.senseNearbyGameObjects(Robot.class, findRallyPoint(), rallyRadius, rc.getTeam());

    for (Robot r : robos) {
      if (rc.senseRobotInfo(r).type == RobotType.SOLDIER) {
        ++massedRobos;
      }
    }

    if (massedRobos > massedAmountNeeded) // if we should all in...
    {
      rc.broadcast(Constants.attackChannel, Constants.attackAllIn);
      allInRound = Clock.getRoundNum();
    }
  }
コード例 #3
0
ファイル: HQ.java プロジェクト: TeamYOLO/BC2013
  public static void singleExpand() throws GameActionException {
    int numCamps = rc.senseAlliedEncampmentSquares().length;
    if (numCamps >= optimalBuildings + farAwayButSafeBuildings) return;

    if (numCamps < optimalBuildings) {}

    if (false) { // figure out condition
      MapLocation expansion = null;
      expansion = findClosestEmptyCamp();
      rc.broadcast(Constants.commandChannel, Constants.commandBuildIndividual);
      rc.broadcast(Constants.singleExpandXChannel, expansion.x);
      rc.broadcast(Constants.singleExpandYChannel, expansion.y);
    }
  }
コード例 #4
0
ファイル: HQ.java プロジェクト: TeamYOLO/BC2013
  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]);
      }
    }
  }
コード例 #5
0
ファイル: AbstractRobot.java プロジェクト: braszek/battlecode
 protected void sendSpam() throws GameActionException {
   Message m = new Message();
   m.ints = new int[1];
   m.locations = new MapLocation[1];
   m.locations[0] = new MapLocation(0, 0);
   m.strings = new String[1];
   m.strings[0] = "MQ_ATTACK";
   myRC.broadcast(m);
 }
コード例 #6
0
 public QuickSupplierPlayer(RobotController rc) {
   super(rc);
   try {
     rc.broadcast(
         SupplierInProgressCountChannel, rc.readBroadcast(SupplierInProgressCountChannel) - 1);
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
コード例 #7
0
ファイル: Soldier.java プロジェクト: TeamYOLO/BC2013
 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();
   }
 }
コード例 #8
0
ファイル: Bfs.java プロジェクト: gabi-a/battlecode2014
 // metadata format:
 // fprrrrxxyy
 // f = finished or not
 // p = priority
 // rrrr = round last updated
 // xx = dest x coordinate
 // yy = dest y coordinate
 private static void writePageMetadata(
     int page, int roundLastUpdated, MapLocation dest, int priority, boolean finished)
     throws GameActionException {
   int channel = pageMetadataBaseChannel + page;
   int data =
       (finished ? 1000000000 : 0)
           + 100000000 * priority
           + 10000 * roundLastUpdated
           + MAP_HEIGHT * dest.x
           + dest.y;
   rc.broadcast(channel, data);
 }
コード例 #9
0
ファイル: Bfs.java プロジェクト: Blackmoor/Battlecode2015
 // metadata format: stored in binary
 // ufpprrrrxxyy
 // u = contains unknowns or not (1 bit)
 // f = finished or not (1 bit)
 // pp = priority (2 bits)
 // rrrr = round last updated (12bits)
 // xx = dest x coordinate (8 bits)
 // yy = dest y coordinate (8 bits)
 private void writePageMetadata(
     int page, int roundLastUpdated, MapLocation dest, int priority, boolean finished)
     throws GameActionException {
   int channel = pageMetadataBaseChannel + page;
   int data =
       (containsUnknowns ? 1 << 31 : 0)
           | (finished ? 1 << 30 : 0)
           | ((priority & 0x3) << 28)
           | (roundLastUpdated << 16)
           | (cropX(dest.x) << 8)
           | cropY(dest.y);
   rc.broadcast(channel, data);
 }
コード例 #10
0
  public HQPlayer(RobotController rc) {
    super(rc);
    this.currentLocation = rc.getLocation();
    this.directionToEnemyHQ = this.currentLocation.directionTo(enemyHQLocation);
    this.initialMineCount = rc.senseMineLocations(currentLocation, 10000, Team.NEUTRAL).length;

    try {
      if (this.canBeTrapped()) {
        rc.setIndicatorString(2, "Can be trapped");
        this.markSpawnSquare();
      } else {
        rc.setIndicatorString(2, "No trap sensed");
      }

      // pick encampments on our side of the map

      rc.broadcast(TargetEncampmentsStartChannel, targetEncampmentsStart);
      this.targetEncampments =
          rc.senseEncampmentSquares(
              currentLocation,
              this.currentLocation.distanceSquaredTo(enemyHQLocation) / 4,
              Team.NEUTRAL);
      // int a = Clock.getBytecodeNum();
      QuicksortLocations(this.targetEncampments, this.currentLocation);
      // int b = Clock.getBytecodeNum();
      // rc.setIndicatorString(1, "Bytecodes: "+(b-a));

      this.broadcastTargetEncampments();

      int rendezvousX = (3 * this.currentLocation.x + this.enemyHQLocation.x) / 4;
      int rendezvousY = (3 * this.currentLocation.y + this.enemyHQLocation.y) / 4;
      MapLocation rendezvous = new MapLocation(rendezvousX, rendezvousY);
      rc.broadcast(RendezVousChannel, intFromMapLocation(rendezvous));
    } catch (GameActionException e) {
      e.printStackTrace();
    }
  }
コード例 #11
0
ファイル: Soldier.java プロジェクト: TeamYOLO/BC2013
  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);
    }
  }
コード例 #12
0
ファイル: Bfs.java プロジェクト: Blackmoor/Battlecode2015
 // We store the data in this format:
 // 1000ddddaaaaaaaaxxxxxxxxyyyyyyyy
 // 1 = validation to prevent mistaking the initial 0 value for a valid pathing instruction
 // d = direction to move (enum ordinal)
 // a = actions (turns) to move here
 // x = x coordinate of destination
 // y = y coordinate of destination
 private void publishResult(
     int page, MapLocation here, MapLocation dest, Direction dir, int actions) {
   int data = 0x80;
   data |= dir.ordinal();
   data <<= 8;
   data |= actions;
   data <<= 8;
   data |= cropX(dest.x);
   data <<= 8;
   data |= cropY(dest.y);
   int channel = locChannel(page, here);
   try {
     rc.broadcast(channel, data);
   } catch (GameActionException e) {
     e.printStackTrace();
   }
 }
コード例 #13
0
ファイル: HQ.java プロジェクト: TeamYOLO/BC2013
  public static void evaluateMap() throws GameActionException {
    MapLocation neutralCamps[] = rc.senseEncampmentSquares(rc.getLocation(), 1000000, Team.NEUTRAL);
    MapLocation me = rc.getLocation();
    MapLocation them = rc.senseEnemyHQLocation();
    rushDistance = them.distanceSquaredTo(me);

    for (MapLocation loc : neutralCamps) {
      double toUs = loc.distanceSquaredTo(me);
      double toThem = loc.distanceSquaredTo(them);
      if (toUs / toThem < .81) {
        if (rushDistance > toUs) optimalBuildings++;
        else farAwayButSafeBuildings++;
      }
    }

    buildOrder = new int[optimalBuildings];

    for (int i = 0; i < optimalBuildings; i++) {
      buildOrder[i] = (i + 1) % 3 == 0 ? Constants.buildOrderGen : Constants.buildOrderSup;
      rc.broadcast(Constants.buildOrderBeginChannel + i, buildOrder[i]);
    }
  }
コード例 #14
0
ファイル: Bfs.java プロジェクト: gabi-a/battlecode2014
 // We store the data in this format:
 // 10d0xxyy
 // 1 = validation to prevent mistaking the initial 0 value for a valid pathing instruction
 // d = direction to move
 // xx = x coordinate of destination
 // yy = y coordinate of destination
 private static void publishResult(int page, MapLocation here, MapLocation dest, Direction dir)
     throws GameActionException {
   int data = 10000000 + (dir.ordinal() * 100000) + (dest.x * MAP_HEIGHT) + (dest.y);
   int channel = locChannel(page, here);
   rc.broadcast(channel, data);
 }
コード例 #15
0
 private static void writeHerdDir(MapLocation loc, Direction dir, RobotController rc)
     throws GameActionException {
   int channel = baseChannel + GameConstants.MAP_MAX_HEIGHT * loc.x + loc.y;
   int data = 10 + dir.ordinal();
   rc.broadcast(channel, data);
 }
コード例 #16
0
ファイル: HQ.java プロジェクト: TeamYOLO/BC2013
  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();
    }
  }
コード例 #17
0
ファイル: AbstractRobot.java プロジェクト: braszek/battlecode
 protected void sendMessage(Message m) throws GameActionException {
   m.strings = new String[2];
   m.strings[0] = "MQ_ATTACK";
   m.strings[1] = myRC.getTeam().toString();
   myRC.broadcast(m);
 }