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

@ -26,7 +26,11 @@ public final class GameStateEvaluator2 {
public static PlayerEvaluateScore evaluate(UUID playerId, Game game) {
Player player = game.getPlayer(playerId);
Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next()); // TODO: add multi opponent support?
Player opponent = game.getPlayer(game.getOpponents(playerId).stream().findFirst().orElse(null)); // TODO: add multi opponent support?
if (opponent == null) {
return new PlayerEvaluateScore(WIN_GAME_SCORE);
}
if (game.checkIfGameIsOver()) {
if (player.hasLost()
|| opponent.hasWon()) {