예제 #1
0
  /**
   * Returns a list of the enemies with radius squares of your hero
   *
   * @param gameState
   * @param searchResults
   * @param radius
   * @return
   */
  public static List<GameState.Hero> getHeroesAround(
      AdvancedGameState gameState,
      Map<GameState.Position, AdvancedMurderBot.DijkstraResult> searchResults,
      int radius) {
    List<GameState.Hero> heroes = new LinkedList<>();

    for (GameState.Hero currentHero : gameState.getHeroesByPosition().values()) {
      GameState.Position currentHeroPosition = currentHero.getPos();
      if (searchResults.get(currentHeroPosition).getDistance() <= radius
          && currentHero.getId() != gameState.getMe().getId()) heroes.add(currentHero);
    }

    return heroes;
  }
예제 #2
0
  /**
   * Creates a new AdvancedGameState by taking he previous AdvancedGameState and updating is using a
   * new GameState
   *
   * @param oldGameState
   * @param updatedState
   */
  public AdvancedGameState(AdvancedGameState oldGameState, GameState updatedState) {

    // Copy the stuff we can just re-use
    this.boardGraph = oldGameState.getBoardGraph();
    this.pubs = oldGameState.getPubs();
    this.viewUrl = oldGameState.getViewUrl();
    // Re-build the hero maps
    this.heroesByPosition = new HashMap<>();
    this.heroesById = new HashMap<>();
    for (GameState.Hero currentHero : updatedState.getGame().getHeroes()) {
      this.heroesByPosition.put(currentHero.getPos(), currentHero);
      this.heroesById.put(currentHero.getId(), currentHero);
    }
    this.me = updatedState.getHero();

    // Update the mines
    this.mines = oldGameState.getMines();
    for (Mine currentMine : this.mines.values()) {
      // Vindinium does the x and y coordinates backwards
      int tileStart =
          currentMine.getPosition().getX() * updatedState.getGame().getBoard().getSize() * 2
              + (currentMine.getPosition().getY() * 2);
      // We don't want the whole tile; we want the second char
      String owner =
          updatedState.getGame().getBoard().getTiles().substring(tileStart + 1, tileStart + 1 + 1);
      Mine mine;
      if (owner.equals("-")) {
        mine = new Mine(currentMine.getPosition(), null);
      } else {
        int ownerId = Integer.parseInt(owner);
        mine = new Mine(currentMine.getPosition(), this.heroesById.get(ownerId));
      }

      this.mines.put(mine.getPosition(), mine);
    }
  }