Exemplo n.º 1
0
  public static void HqCommand() throws GameActionException {
    if (rc.getType() == RobotType.HQ) {
      //			if (rc.isActive()) {
      // Spawn a soldier

      int[] directionOffSets = {0, 1, -1, 2, -2};

      //			    Team mineSpawn = rc.senseMine(rc.getLocation().add(spawnDir));
      Direction dir =
          rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // this does not work!
      Direction spawnDir = dir;
      // spawn robots in the direction of the enemy
      if (rc.senseMine(rc.getLocation().add(dir)) != null) {
        lookForDir:
        for (int d : directionOffSets) {
          spawnDir = Direction.values()[(dir.ordinal() + d + 8) % 8];
          if (rc.canMove(spawnDir) && rc.senseMine(rc.getLocation().add(spawnDir)) != null) {
            rc.spawn(Direction.SOUTH);
            rc.spawn(spawnDir);
            break lookForDir;
          }
        }
      }

      if (rc.canMove(dir)) {
        rc.spawn(dir);
      }
      //			}
    }
  }
Exemplo n.º 2
0
  // In this function the HQ spawns a soldier ideally toward the enemy base but in any direction
  // otherwise
  public static void SpawnSoldiers(RobotController rc) {
    try {
      if (rc.isActive() && rc.getType() == RobotType.HQ) {
        Direction toEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
        if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) {
        } else {
          for (int i = 0; i < 7; i++) {
            toEnemy = toEnemy.rotateLeft();

            if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) {
              i = 47;
            } else if (i == 6) {
              toEnemy = Direction.NONE;
            }
          }
        }

        if (toEnemy != Direction.NONE) {
          if (rc.isActive()) {
            if (rc.getType() == RobotType.HQ) {
              rc.spawn(toEnemy);
            }
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Utility Exception");
    }
  }
Exemplo n.º 3
0
 public static void hqCode() throws GameActionException {
   if (rc.isActive()) {
     // Spawn a soldier
     Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation());
     if (rc.canMove(dir)) rc.spawn(dir);
   }
 }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
 public static void tryToSpawn() throws GameActionException {
   if (rc.isActive() && rc.senseRobotCount() < GameConstants.MAX_ROBOTS) {
     for (int i = 0; i < 8; i++) {
       Direction trialDir = allDirections[i];
       if (rc.canMove(trialDir)) {
         rc.spawn(trialDir);
         break;
       }
     }
   }
 }
Exemplo n.º 6
0
  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();
    }
  }