Ejemplo n.º 1
0
 private double estimateNearbyCowGrowth(MapLocation loc) {
   double ret = 0;
   int minX = Math.max(0, loc.x - 10);
   int minY = Math.max(0, loc.y - 10);
   int maxX = Math.min(rc.getMapWidth() - 1, loc.x + 10);
   int maxY = Math.min(rc.getMapHeight() - 1, loc.y + 10);
   for (int x = minX; x <= maxX; x++) {
     for (int y = minY; y <= maxY; y++) {
       if (rc.senseTerrainTile(new MapLocation(x, y)) != TerrainTile.VOID) ret += cowGrowth[x][y];
     }
   }
   return ret;
 }
Ejemplo n.º 2
0
 public Bfs(RobotController theRC) {
   rc = theRC;
   map = null;
   MAP_HEIGHT = GameConstants.MAP_MAX_HEIGHT;
   MAP_WIDTH = GameConstants.MAP_MAX_WIDTH;
   PAGE_SIZE = MAP_WIDTH * MAP_HEIGHT;
   NUM_PAGES = Math.min(45000 / PAGE_SIZE, MAX_PAGES);
 }
Ejemplo n.º 3
0
 public static void printCoarseMap() {
   System.out.println("Coarse map:");
   for (int x = 0; x < coarseMap[0].length; x++) {
     for (int y = 0; y < coarseMap.length; y++) {
       int numberOfObstacles = coarseMap[x][y];
       System.out.print(Math.min(numberOfObstacles, 999) + " ");
     }
     System.out.println();
   }
 }
Ejemplo n.º 4
0
  public void herdInward() throws GameActionException {
    radius = 20 - Math.min(13, (Clock.getRoundNum() % 120) * 16.0 / 120.0);

    MapLocation target =
        new MapLocation(
            (int) (here.x + radius * Math.cos(angle)), (int) (here.y + radius * Math.sin(angle)));
    angle += rate;
    rc.setIndicatorString(0, "angle = " + angle);
    if (rc.canAttackSquare(target)) {
      rc.attackSquare(target);
    }
  }
 private void updateDrawLoc() {
   if (RenderConfiguration.showDiscrete() || !isDoing(ActionType.MOVING)) {
     drawX = drawY = 0;
   } else {
     // still waiting perfection of delay system
     // float dist = .5f;
     float dist =
         (float) Math.max(Math.min(moving * (movementDelay / info.type.movementDelay), 1), 0);
     // System.out.println("moving: " + moving + "actionDelay: " + actionDelay + "total " +
     // totalActionRounds);
     drawX = -dist * dir.dx;
     drawY = -dist * dir.dy;
   }
 }
Ejemplo n.º 6
0
 public static void printBigCoarseMap(RobotController rc) {
   System.out.println("Fine map:");
   for (int x = 0; x < coarseMap[0].length * bigBoxSize; x++) {
     for (int y = 0; y < coarseMap.length * bigBoxSize; y++) {
       if (countObstacles(x, y, rc) == NORMAL_COST
           || countObstacles(x, y, rc)
               == ROAD_COST) { // there's no obstacle, so print the box's obstacle count
         int numberOfObstacles = coarseMap[x / bigBoxSize][y / bigBoxSize];
         System.out.print(Math.min(numberOfObstacles, 999));
       } else { // there's an obstacle, so print an X
         System.out.print("X");
       }
       System.out.print(" ");
     }
     System.out.println();
   }
 }
Ejemplo n.º 7
0
  protected void transferEnergon() throws GameActionException {
    for (Robot robot : myRC.senseNearbyGroundRobots()) {
      try {
        RobotInfo robotInfo = myRC.senseRobotInfo(robot);

        if (robotInfo.team == myRC.getTeam()) {
          MapLocation robotLocation = robotInfo.location;

          if (myRC.getLocation().isAdjacentTo(robotLocation))
            myRC.transferEnergon(
                Math.max(
                    0,
                    Math.min(
                        robotInfo.maxEnergon - robotInfo.eventualEnergon,
                        myRC.getEnergonLevel() / 2)),
                robotLocation,
                RobotLevel.ON_GROUND);
        }
      } catch (GameActionException e) {

      }
    }
  }
Ejemplo n.º 8
0
  public static void forwardishIfProtection(Direction movingDirection2) throws GameActionException {

    boolean stationArchon = RobotPlayer.stationArchon;
    // boolean tempRoamingArchon = RobotPlayer.tempRoamingArchon;
    if (stationArchon) return; // or do other stuff
    int id = RobotPlayer.id;
    // System.out.println(Integer.toString(id));

    // int waitTurns = 1;

    RobotController rc = RobotPlayer.rc;

    int waitTurns = rc.getType() == RobotType.ARCHON ? 1 : 1;
    // if(rc.getRoundNum()%waitTurns ==0){// leader let the soldiers catch up
    if (true) {
      for (int i : possibleDirections) {
        Direction candidateDirection = Direction.values()[(movingDirection2.ordinal() + i + 8) % 8];
        MapLocation candidateLocation =
            rc.getLocation().add(candidateDirection.dx, candidateDirection.dy);
        if (patient > 0) {
          //					if (rc.getType() == RobotType.ARCHON)
          //						System.out.println("should be  an archon moving now");

          MapLocation oldLoc = rc.getLocation();
          if (rc.canMove(candidateDirection)
              && !pastLocations.contains(candidateLocation)
              && enoughProtectionAhead(candidateLocation)) {

            if (!pastLocations.contains(oldLoc)) {

              pastLocations.add(rc.getLocation());
            }
            if (pastLocations.size() > 5) pastLocations.remove(0);

            rc.move(candidateDirection);
            if (rc.getType() == RobotType.ARCHON && !RobotPlayer.stationArchon) {
              // System.out.println("Im getting this far");
              // System.out.println("I should have moved in direction: "+
              // candidateDirection.toString());
            }

            // if (rc.getType() == RobotTypse.ARCHON)
            //	System.out.println("should have moved an archon new location " +
            // rc.getLocation().toString()+ "old : " + oldLoc) ;

            patient = Math.min(patient + 1, 30);
            return;
          }
        } else {

          if (rc.canMove(candidateDirection) && enoughProtectionAhead(candidateLocation)) {
            rc.move(candidateDirection);
            patient = Math.min(patient + 1, 30);
            return;
          } else { // dig !
            if (rc.senseRubble(candidateLocation) > GameConstants.RUBBLE_OBSTRUCTION_THRESH) {
              rc.clearRubble(candidateDirection);
              return;
            }
          }
        }
      }
      patient = patient - 5;
    }
  }
Ejemplo n.º 9
0
 public static void init(RobotController theRC) {
   rc = theRC;
   MAP_HEIGHT = rc.getMapHeight();
   PAGE_SIZE = rc.getMapWidth() * MAP_HEIGHT;
   NUM_PAGES = Math.min(40000 / PAGE_SIZE, MAX_PAGES);
 }