Ejemplo n.º 1
0
  // This method will attempt to spawn in the given direction (or as close to it as possible)
  static boolean trySpawn(Direction d, RobotType type) {
    if (!rc.hasSpawnRequirements(type)) return false;

    int offsetIndex = 0;
    int[] offsets = {0, 1, -1, 2, -2, 3, -3, 4};
    int dirint = directionToInt(d);
    while (offsetIndex < 8) {
      int i = (dirint + offsets[offsetIndex] + 8) % 8;
      Direction spawn = directions[i];

      if (rc.canSpawn(spawn, type) && rc.hasSpawnRequirements(type)) {
        try {
          rc.spawn(spawn, type);
          strategy.addUnit(type);
        } catch (GameActionException e) {
          System.out.println("Spawn exception");
          // e.printStackTrace();
        }
        return true;
      }
      offsetIndex++;
    }

    return false;
  }
Ejemplo n.º 2
0
  // This method will attempt to build in the given direction (or as close to it as possible)
  static boolean tryBuild(Direction d, RobotType type) {
    int offsetIndex = 0;
    int[] offsets = {0, 1, -1, 2, -2, 3, -3, 4};
    int dirint = directionToInt(d);
    while (offsetIndex < 8) {
      int i = (dirint + offsets[offsetIndex] + 8) % 8;
      Direction build = directions[i];
      MapLocation m = myLoc.add(build);

      if (rc.canBuild(build, type) && !wouldBlock(build) && !threats.isThreatened(m)) {
        try {
          rc.build(directions[i], type);
          strategy.addUnit(type);
        } catch (GameActionException e) {
          System.out.println("Build exception");
          // e.printStackTrace();
        }
        return true;
      }
      offsetIndex++;
    }

    return false;
  }