public boolean isWinner(UUID playerId) { if (game != null) { Player player = game.getPlayer(playerId); if (player != null && player.hasWon()) return true; } return false; }
public int simulate(UUID playerId) { // long startTime = System.nanoTime(); Game sim = createSimulation(game, playerId); sim.resume(); // long duration = System.nanoTime() - startTime; int retVal = -1; //anything other than a win is a loss for (Player simPlayer: sim.getPlayers().values()) { // logger.info(simPlayer.getName() + " calculated " + ((SimulatedPlayerMCTS)simPlayer).getActionCount() + " actions in " + duration/1000000000.0 + "s"); if (simPlayer.getId().equals(playerId) && simPlayer.hasWon()) { // logger.info("AI won the simulation"); retVal = 1; } } return retVal; }
sb.append(player.hasWon() ? "W" : ""); sb.append(player.hasLost() ? "L" : ""); sb.append(player.hasQuit() ? "Q" : "");
protected UUID findWinnersAndLosers() { UUID winnerIdFound = null; for (Player player : state.getPlayers().values()) { if (player.hasWon()) { logger.debug(player.getName() + " has won gameId: " + getId()); winnerIdFound = player.getId(); break; } if (!player.hasLost() && !player.hasLeft()) { logger.debug(player.getName() + " has not lost so he won gameId: " + this.getId()); player.won(this); winnerIdFound = player.getId(); break; } } for (Player player : state.getPlayers().values()) { if (winnerIdFound != null && !player.getId().equals(winnerIdFound) && !player.hasLost()) { player.lost(this); } } return winnerIdFound; }
public static int evaluate(UUID playerId, Game game, boolean ignoreTapped) { Player player = game.getPlayer(playerId); Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next()); if (game.checkIfGameIsOver()) { if (player.hasLost() || opponent.hasWon()) { return LOSE_SCORE; } if (opponent.hasLost() || player.hasWon()) { return WIN_SCORE; } } int lifeScore = (player.getLife() - opponent.getLife()) * LIFE_FACTOR; int poisonScore = (opponent.getCounters().getCount(CounterType.POISON) - player.getCounters().getCount(CounterType.POISON)) * LIFE_FACTOR * 2; int permanentScore = 0; for (Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) { permanentScore += evaluatePermanent(permanent, game, ignoreTapped); } for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponent.getId())) { permanentScore -= evaluatePermanent(permanent, game, ignoreTapped); } permanentScore *= PERMANENT_FACTOR; int handScore = 0; handScore = player.getHand().size() - opponent.getHand().size(); handScore *= HAND_FACTOR; int score = lifeScore + poisonScore + permanentScore + handScore; if (logger.isDebugEnabled()) { logger.debug("game state for player " + player.getName() + " evaluated to- lifeScore:" + lifeScore + " permanentScore:" + permanentScore + " handScore:" + handScore + " total:" + score); } return score; }
@Override public void endGame() { Game game = getGame(); for (MatchPlayer matchPlayer : this.players) { Player player = game.getPlayer(matchPlayer.getPlayer().getId()); if (player != null) { // get the left time from player priority timer if (game.getPriorityTime() > 0) { matchPlayer.setPriorityTimeLeft(player.getPriorityTimeLeft()); } if (player.hasQuit()) { matchPlayer.setQuit(true); } if (player.hasWon()) { matchPlayer.addWin(); } } } if (game.isADraw()) { addDraw(); } checkIfMatchEnds(); game.fireGameEndInfo(); gamesInfo.add(createGameInfo(game)); }
public int evaluateState() { Player opponent = game.getPlayer(game.getOpponents(player.getId()).iterator().next()); if (game.checkIfGameIsOver()) { if (player.hasLost() || opponent.hasWon()) { return Integer.MIN_VALUE; } if (opponent.hasLost() || player.hasWon()) { return Integer.MAX_VALUE; } } int value = player.getLife(); value -= opponent.getLife(); PermanentEvaluator evaluator = new PermanentEvaluator(); for (Permanent permanent: game.getBattlefield().getAllActivePermanents(player.getId())) { value += evaluator.evaluate(permanent, game); } for (Permanent permanent: game.getBattlefield().getAllActivePermanents(player.getId())) { value -= evaluator.evaluate(permanent, game); } value += player.getHand().size(); value -= opponent.getHand().size(); return value; }