AI: fixed computer's errors if all players quit the game;

This commit is contained in:
Oleg Agafonov 2021-07-24 05:52:02 +04:00
parent d41ccd11bc
commit c1db466d05
4 changed files with 16 additions and 4 deletions

View file

@ -42,7 +42,11 @@ public final class GameStateEvaluator {
public static int evaluate(UUID playerId, Game game, boolean ignoreTapped) {
Player player = game.getPlayer(playerId);
Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next());
Player opponent = game.getPlayer(game.getOpponents(playerId).stream().findFirst().orElse(null));
if (opponent == null) {
return WIN_SCORE;
}
if (game.checkIfGameIsOver()) {
if (player.hasLost() || opponent.hasWon()) {
return LOSE_SCORE;