예제 #1
0
  public static MapLocation spotOfTrollTower(RobotController rc, MapLocation pastr) {
    MapLocation target = pastr;
    int width = rc.getMapWidth();
    int height = rc.getMapHeight();
    int dist = 350;

    if (pastr.x < width / 2) {
      while (target.distanceSquaredTo(pastr) < dist && target.x > 0) {
        target = target.add(Direction.WEST);
      }
    } else {
      while (target.distanceSquaredTo(pastr) < dist && target.x < rc.getMapWidth() - 1) {
        target = target.add(Direction.EAST);
      }
    }
    if (pastr.y < height / 2) {
      while (target.distanceSquaredTo(pastr) < dist && target.y < height - 1) {
        target = target.add(Direction.SOUTH);
      }
    } else {
      while (target.distanceSquaredTo(pastr) < dist && target.y > 0) {
        target = target.add(Direction.NORTH);
      }
    }

    while (rc.senseTerrainTile(target) == TerrainTile.VOID && target.x < width / 2) {
      target = target.add(Direction.EAST);
    }
    while (rc.senseTerrainTile(target) == TerrainTile.VOID && target.x > width / 2) {
      target = target.add(Direction.WEST);
    }

    return target;
  }
예제 #2
0
  public static MapLocation spotOfSensorTower(RobotController rc) {
    rand = new Random();
    MapLocation target = null;

    int corner = Utilities.findBestCorner(rc);

    switch (corner) {
      case 1:
        target = new MapLocation(5, 5);
        break;
      case 2:
        target = new MapLocation(rc.getMapWidth() - 6, 5);
        break;
      case 3:
        target = new MapLocation(5, rc.getMapHeight() - 6);
        break;
      default:
        target = new MapLocation(rc.getMapWidth() - 6, rc.getMapHeight() - 6);
        break;
    }

    Direction dir = directions[rand.nextInt(8)];
    // make sure we don't try to build on a void space
    while (rc.senseTerrainTile(target).equals(TerrainTile.VOID)) {
      target = target.add(dir);
      dir = directions[rand.nextInt(8)];
    }

    return target;
  }
예제 #3
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) {
          }
        }
      }
    }
  }
예제 #4
0
 public static void fireCircle(RobotController rc, int radius, MapLocation center) {
   for (int k = 0; k < directions.length; k++) {
     while (!rc.isActive()) {}
     MapLocation toFire = center.add(directions[k], radius);
     try {
       if (toFire.x >= 0
           && toFire.x < rc.getMapWidth()
           && toFire.y >= 0
           && toFire.y < rc.getMapHeight()) {
         rc.attackSquare(toFire);
         rc.yield();
       }
     } catch (Exception e) {
     }
     while (!rc.isActive()) {}
     toFire = center;
     for (int a = 0; a < radius / 2; a++) {
       toFire = toFire.add(directions[k]);
       toFire = toFire.add(directions[(k + 1) % directions.length]);
     }
     try {
       if (toFire.x >= 0
           && toFire.x < rc.getMapWidth()
           && toFire.y >= 0
           && toFire.y < rc.getMapHeight()) {
         rc.attackSquare(toFire);
         rc.yield();
       }
     } catch (Exception e) {
     }
   }
 }
예제 #5
0
  public static MapLocation spotOfPastr(RobotController rc) {
    MapLocation target;
    int[] lookPlaces = {1, 1, 0, 3, 6, 7, 4, 5, 2, 3, 0, 2, 2, 3, 1, 4, 5, 3, 2, 5, 6};
    int counter = 0;
    Direction dir;
    int corner = findBestCorner(rc);
    rand = new Random();
    switch (corner) {
      case 1:
        target = new MapLocation(2, 2);
        break;
      case 2:
        target = new MapLocation(rc.getMapWidth() - 3, 2);
        break;
      case 3:
        target = new MapLocation(2, rc.getMapHeight() - 3);
        break;
      default:
        target = new MapLocation(rc.getMapWidth() - 3, rc.getMapHeight() - 3);
        break;
    }

    while (rc.senseTerrainTile(target).equals(TerrainTile.VOID)) {

      dir = directions[rand.nextInt(8)];
      target = target.add(dir);
      counter++;
    }
    return target;
  }
예제 #6
0
  private int findBestCorner() {
    double[][] pasture = rc.senseCowGrowth();

    double max = 0;
    int corner = 0;
    double total = 0;

    // top left corner
    for (int k = 0; k < 10; k++) {
      for (int a = 0; a < 10; a++) {
        total += pasture[k][a];
      }
    }
    if (total > max) {
      max = total;
      corner = 1;
    }
    total = 0;

    // top right corner
    for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) {
      for (int a = 0; a < 10; a++) {
        total += pasture[k][a];
      }
    }
    if (total > max) {
      max = total;
      corner = 2;
    }
    total = 0;

    // bottom left corner
    for (int k = 0; k < 10; k++) {
      for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) {
        total += pasture[k][a];
      }
    }
    if (total > max) {
      max = total;
      corner = 3;
    }
    total = 0;

    // bottom right corner
    for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) {
      for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) {
        total += pasture[k][a];
      }
    }
    if (total > max) {
      max = total;
      corner = 4;
    }

    return corner;
  }
예제 #7
0
  public static MapLocation[] BestPastureSpots(RobotController rc) {
    MapLocation[] empty = new MapLocation[1];
    try {
      // Check if a robot is spawnable and spawn one if it is
      double growthRates[][] = rc.senseCowGrowth();
      int countofBestSpots = 0;
      double best = 0.0001;
      for (int i = 0; i < rc.getMapWidth(); i++) {
        for (int k = 0; k < rc.getMapHeight(); k++) {
          if (growthRates[i][k] > best) {
            best = growthRates[i][k];
            countofBestSpots = 1;
          } else if (growthRates[i][k] == best) {
            countofBestSpots++;
          }

          SpawnSoldiers(rc);
        }
      }

      MapLocation[] bestSpots = new MapLocation[countofBestSpots];
      int index = 0;
      for (int i = 0; i < rc.getMapWidth(); i++) {
        for (int k = 0; k < rc.getMapHeight(); k++) {
          if (growthRates[i][k] == best) {
            bestSpots[index] = new MapLocation(i, k);
            index++;
          }

          SpawnSoldiers(rc);
        }
      }

      for (int i = 1; i < countofBestSpots; i++) {
        for (int j = i; j < countofBestSpots; j++) {
          int dist1 = rc.getLocation().distanceSquaredTo(bestSpots[j]);
          int dist2 = rc.getLocation().distanceSquaredTo(bestSpots[j]);

          if (dist1 < dist2) {
            MapLocation temp = bestSpots[j];
            bestSpots[j] = bestSpots[j - 1];
            bestSpots[j - 1] = temp;
          }

          SpawnSoldiers(rc);
        }
      }
      return bestSpots;
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Utility Exception");
    }
    return empty;
  }
예제 #8
0
  public static void workOnCache(RobotController rc, int bytecodeLimit) {
    if (cacheFinished) return;

    int mapWidth = rc.getMapWidth();
    int mapHeight = rc.getMapHeight();

    int x, y;
    if (workStarted) {
      x = workLocX;
      y = workLocY;
    } else {
      x = mapWidth - 1;
      y = mapHeight - 1;
      workStarted = true;
    }

    outerloop:
    while (x >= 0) {
      while (y >= 0) {
        terrain[x][y] = rc.senseTerrainTile(new MapLocation(x, y));
        y--;
        // TODO: this is in a tight loop so it would be nice to do this check less often
        if (Clock.getBytecodeNum() > bytecodeLimit) break outerloop;
      }
      y = mapHeight - 1;
      x--;
    }

    workLocX = x;
    workLocY = y;

    if (x < 0) cacheFinished = true;
  }
예제 #9
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);
  }
예제 #10
0
 public static void assessMap(int bigBoxSizeIn, RobotController rc) {
   bigBoxSize = bigBoxSizeIn;
   int coarseWidth = rc.getMapWidth() / bigBoxSize;
   int coarseHeight = rc.getMapHeight() / bigBoxSize;
   coarseMap = new int[coarseWidth][coarseHeight];
   for (int x = 0; x < coarseWidth * bigBoxSize; x++) {
     for (int y = 0; y < coarseHeight * bigBoxSize; y++) {
       coarseMap[x / bigBoxSize][y / bigBoxSize] += countObstacles(x, y, rc);
     }
   }
   // printCoarseMap();
   // printBigCoarseMap(rc);
   // System.out.println("Big Box Size: " + bigBoxSizeIn);
 }
예제 #11
0
  protected static void init(RobotController theRC) throws GameActionException {
    rc = theRC;
    us = rc.getTeam();
    them = us.opponent();

    ourHQ = rc.senseHQLocation();
    theirHQ = rc.senseEnemyHQLocation();

    mapWidth = rc.getMapWidth();
    mapHeight = rc.getMapHeight();

    FastRandom.init();
    MessageBoard.init(theRC);
    Bfs.init(theRC);
  }
예제 #12
0
 public static void pullInto(RobotController rc, int radius, MapLocation center) {
   for (int k = 0; k < directions.length; k++) {
     while (!rc.isActive()) {}
     MapLocation toFire = center.add(directions[k], radius);
     try {
       while (toFire.distanceSquaredTo(center) > 3) {
         if (toFire.x >= 0
             && toFire.x < rc.getMapWidth()
             && toFire.y >= 0
             && toFire.y < rc.getMapHeight()) {
           try {
             rc.attackSquare(toFire);
             rc.yield();
           } catch (Exception e) {
           }
         }
         toFire = toFire.add(directions[k].opposite());
       }
     } catch (Exception e) {
     }
   }
 }
예제 #13
0
 private static MapLocation getRandomLocation() {
   return new MapLocation(randall.nextInt(rc.getMapWidth()), randall.nextInt(rc.getMapHeight()));
 }
예제 #14
0
  public static void computeAndPublish(MapLocation here, MapLocation pastr, RobotController rc)
      throws GameActionException {
    // Useful data
    int attackRange =
        (int)
            (Math.sqrt(RobotType.NOISETOWER.attackRadiusMaxSquared)
                - 3); // -3 becauase we actually have to shoot past the square
    int attackRangeSq = attackRange * attackRange;
    int mapWidth = rc.getMapWidth();
    int mapHeight = rc.getMapHeight();
    Direction[] dirs =
        new Direction[] {
          Direction.NORTH_WEST,
          Direction.SOUTH_WEST,
          Direction.SOUTH_EAST,
          Direction.NORTH_EAST,
          Direction.NORTH,
          Direction.WEST,
          Direction.SOUTH,
          Direction.EAST
        };
    int[] dirsX = new int[] {1, 1, -1, -1, 0, 1, 0, -1};
    int[] dirsY = new int[] {1, -1, -1, 1, 1, 0, -1, 0};

    // Set up the queue
    MapLocation[] locQueue =
        new MapLocation
            [(2 * RobotType.NOISETOWER.attackRadiusMaxSquared + 1)
                * (2 * RobotType.NOISETOWER.attackRadiusMaxSquared + 1)];
    int locQueueHead = 0;
    int locQueueTail = 0;
    boolean[][] wasQueued = new boolean[GameConstants.MAP_MAX_WIDTH][GameConstants.MAP_MAX_HEIGHT];

    // Push pastr onto queue
    locQueue[locQueueTail] = pastr;
    locQueueTail++;
    wasQueued[pastr.x][pastr.y] = true;

    while (locQueueHead != locQueueTail) {
      // 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 (here.distanceSquaredTo(newLoc) <= attackRangeSq) {
            if (rc.senseTerrainTile(newLoc) != TerrainTile.VOID) {
              writeHerdDir(newLoc, dirs[i], rc);

              // push newLoc onto queue
              locQueue[locQueueTail] = newLoc;
              locQueueTail++;
              wasQueued[x][y] = true;
            }
          }
        }
      }
    }
  }
예제 #15
0
  // finds best corner to collect milk where the return is an int as follows:
  // 1  2
  // 3  4
  public static int findBestCorner(RobotController rc) {
    double[][] pasture = rc.senseCowGrowth();

    double[] voids = new double[4];
    double[] cows = new double[4];
    double[] distances = new double[4];

    double max = 0;
    int corner = 0;
    double total = 0;
    MapLocation target = null;
    MapLocation current = rc.senseHQLocation();

    for (int k = 1; k <= 4; k++) {
      switch (k) {
        case 1:
          target = new MapLocation(5, 5);
          break;
        case 2:
          target = new MapLocation(rc.getMapWidth() - 6, 5);
          break;
        case 3:
          target = new MapLocation(5, rc.getMapHeight() - 6);
          break;
        default:
          target = new MapLocation(rc.getMapWidth() - 6, rc.getMapHeight() - 6);
          break;
      }

      while (target.x != current.x || target.y != current.y) {
        if (rc.senseTerrainTile(current) == TerrainTile.VOID) {
          total++;
        }
        current = current.add(current.directionTo(target));
      }

      voids[k - 1] = total;
      distances[k - 1] = rc.senseHQLocation().distanceSquaredTo(target);

      total = 0;
      current = rc.senseHQLocation();
    }

    // top left corner
    for (int k = 0; k < 10; k++) {
      for (int a = 0; a < 10; a++) {
        total += pasture[k][a];
      }
    }
    cows[0] = total;

    total = 0;

    // top right corner
    for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) {
      for (int a = 0; a < 10; a++) {
        total += pasture[k][a];
      }
    }
    cows[1] = total;

    total = 0;

    // bottom left corner
    for (int k = 0; k < 10; k++) {
      for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) {
        total += pasture[k][a];
      }
    }
    cows[2] = total;

    total = 0;

    // bottom right corner
    for (int k = rc.getMapWidth() - 11; k < rc.getMapWidth(); k++) {
      for (int a = rc.getMapHeight() - 11; a < rc.getMapHeight(); a++) {
        total += pasture[k][a];
      }
    }
    cows[3] = total;

    for (int k = 0; k < 4; k++) {
      total = cows[k] * 1 - voids[k] * 50 - distances[k] * .001;

      if (total > max) {
        max = total;
        corner = k + 1;
      }
    }

    return corner;
  }
 NavigationController(RobotController rc) {
   this.rc = rc;
   this.myTeam = rc.getTeam();
   this.mapIntDistribution = new int[rc.getMapWidth()][rc.getMapHeight()];
   this.dice = new Random(Clock.getRoundNum());
 }
예제 #17
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);
 }