public ComputedContext(GameState gameState) { this.gameState = gameState; tiles = new BoardParser() .parse( gameState.getGame().getBoard().getTiles(), gameState.getGame().getBoard().getSize()); heroTile = tiles[gameState.getHero().getPos().getX()][gameState.getHero().getPos().getY()]; paths = new PathFinder(tiles); paths.calculate(gameState.getHero().getPos()); }
public Strategy getSuitableStrategy() { Optional<GameState.Hero> killWorthyOpponent = gameState .getGame() .getHeroes() .stream() .filter( x -> x.getMineCount() > gameState.getHero().getMineCount() && x.getLife() + 25 < gameState.getHero().getLife() && paths .getBestPath(heroTile, tiles[x.getPos().getX()][x.getPos().getY()]) .size() < 5 // Target rich/weak players/close ) .findFirst(); if (killWorthyOpponent.isPresent()) { LOGGER.log(Level.INFO, "Using kill strategy"); LAST_STRATEGY = StrategyType.KILL; return new KillStrategy(this, killWorthyOpponent.get()); } if (gameState.getHero().getLife() > getCockinessLevel(gameState) && LAST_STRATEGY != StrategyType.BEER) { LOGGER.log(Level.INFO, "Using mine strategy"); LAST_STRATEGY = StrategyType.MINE; return new MineStrategy(this); } else { LOGGER.log(Level.INFO, "Using beer strategy"); LAST_STRATEGY = LAST_STRATEGY == StrategyType.BEER && gameState.getHero().getLife() > 75 ? StrategyType.NONE : StrategyType.BEER; return new BeerStrategy(this); } }
/** * Magical function that meticulously calculates the required cockiness level. * * @param state * @return cockiness level */ private double getCockinessLevel(GameState state) { // NOTE: Do not try to reproduce. Highly statistical method. return state.getHero().getMineCount() > 4 ? 50 : 30; }