public static void run(RobotController _rc) throws GameActionException {
   Bot.init(_rc);
   init();
   while (true) {
     myLocation = rc.getLocation();
     Radio.process();
     action();
     Radio.clear();
     Clock.yield();
   }
 }
Beispiel #2
0
 public static void loop(RobotController theRC) throws GameActionException {
   Clock.yield();
   Bot.init(theRC);
   init();
   while (true) {
     try {
       turn();
     } catch (Exception e) {
       e.printStackTrace();
     }
     Clock.yield();
   }
 }
Beispiel #3
0
  // HQ or pastr calls this function to spend spare bytecodes computing paths for soldiers
  public static void work(MapLocation dest, int priority, int bytecodeLimit)
      throws GameActionException {
    int page = findFreePage(dest, priority);
    Debug.indicate("path", 1, "BFS Pathing to " + dest.toString() + "; using page " + page);
    if (page == -1) return; // We can't do any work, or don't have to

    if (!dest.equals(previousDest)) {
      Debug.indicate("path", 0, "BFS initingQueue");
      initQueue(dest);
    } else {
      Debug.indicate("path", 0, "BFS queue already inited");
    }

    previousDest = dest;
    previousRoundWorked = Clock.getRoundNum();
    previousPage = page;

    int mapWidth = rc.getMapWidth();
    int mapHeight = rc.getMapHeight();
    MapLocation enemyHQ = rc.senseEnemyHQLocation();
    boolean destInSpawn = dest.distanceSquaredTo(enemyHQ) <= 25;

    while (locQueueHead != locQueueTail && Clock.getBytecodeNum() < bytecodeLimit) {
      // pop a location from the queue
      MapLocation loc = locQueue[locQueueHead];
      locQueueHead++;

      int locX = loc.x;
      int locY = loc.y;
      for (int i = 8; i-- > 0; ) {
        int x = locX + dirsX[i];
        int y = locY + dirsY[i];
        if (x >= 0 && y >= 0 && x < mapWidth && y < mapHeight && !wasQueued[x][y]) {
          MapLocation newLoc = new MapLocation(x, y);
          if (rc.senseTerrainTile(newLoc) != TerrainTile.VOID
              && (destInSpawn || !Bot.isInTheirHQAttackRange(newLoc))) {
            publishResult(page, newLoc, dest, dirs[i]);

            // push newLoc onto queue
            locQueue[locQueueTail] = newLoc;
            locQueueTail++;
            wasQueued[x][y] = true;
          }
        }
      }
    }

    boolean finished = locQueueHead == locQueueTail;
    Debug.indicate("path", 2, "BFS finished = " + finished + "; locQueueHead = " + locQueueHead);
    writePageMetadata(page, Clock.getRoundNum(), dest, priority, finished);
  }
Beispiel #4
0
  protected static void init(RobotController theRC) throws GameActionException {
    Bot.init(theRC);
    //		Debug.init(theRC, "pages");

    // claim the assignment to build this pastr so others know not to build it
    int numPastrLocations = MessageBoard.NUM_PASTR_LOCATIONS.readInt();
    for (int i = 0; i < numPastrLocations; i++) {
      MapLocation pastrLoc = MessageBoard.BEST_PASTR_LOCATIONS.readFromMapLocationList(i);
      if (rc.getLocation().equals(pastrLoc)) {
        MessageBoard.PASTR_BUILDER_ROBOT_IDS.claimAssignment(i);
        break;
      }
    }
  }
  protected static void init(RobotController theRC) throws GameActionException {
    Bot.init(theRC);
    // Debug.init(theRC, "herd");

    here = rc.getLocation();

    // claim the assignment to build this tower so others know not to build it
    int numPastrLocations = MessageBoard.NUM_PASTR_LOCATIONS.readInt();
    amSuppressor = true;
    for (int i = 0; i < numPastrLocations; i++) {
      MapLocation pastrLoc = MessageBoard.BEST_PASTR_LOCATIONS.readFromMapLocationList(i);
      if (rc.getLocation().isAdjacentTo(pastrLoc)) {
        amSuppressor = false;
        MessageBoard.TOWER_BUILDER_ROBOT_IDS.claimAssignment(i);
        break;
      }
    }

    if (amSuppressor) {
      int bestDistSq = 999999;
      int numSuppressors = MessageBoard.NUM_SUPPRESSORS.readInt();
      int suppressorIndex = -1;
      for (int i = 0; i < numSuppressors; i++) {
        MapLocation target = MessageBoard.SUPPRESSOR_TARGET_LOCATIONS.readFromMapLocationList(i);
        int distSq = here.distanceSquaredTo(target);
        if (distSq < bestDistSq) {
          bestDistSq = distSq;
          suppressionTarget = target;
          suppressorIndex = i;
        }
      }
      if (suppressorIndex != -1) {
        MessageBoard.SUPPRESSOR_BUILDER_ROBOT_IDS.claimAssignment(suppressorIndex);
      }
    } else {
      // Figure out the best direction to start herding in
      double[] freeCows = new double[8];
      double[][] cowGrowth = rc.senseCowGrowth();
      Direction[] dirs = Direction.values();
      for (int i = 0; i < 8; i++) {
        Direction dir = dirs[i];
        MapLocation probe = here.add(dir);
        while (Util.passable(rc.senseTerrainTile(probe))
            && here.distanceSquaredTo(probe) <= RobotType.NOISETOWER.attackRadiusMaxSquared) {
          freeCows[i] += cowGrowth[probe.x][probe.y];
          probe = probe.add(dir);
        }
      }

      double bestScore = -1;
      int bestDir = -1;
      for (int i = 0; i < 8; i++) {
        double score = freeCows[i] + freeCows[(i + 1) % 8] + freeCows[(i + 2) % 8];
        if (score > bestScore) {
          bestScore = score;
          bestDir = i;
        }
      }
      attackDir = dirs[bestDir];
    }
  }
 private double evaluate(RobotInfo info) {
   return bot.distanceSquaredTo(info.location);
 }