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

@ -34,7 +34,11 @@ public class ActionSimulator {
}
public int evaluateState() {
Player opponent = game.getPlayer(game.getOpponents(player.getId()).iterator().next());
Player opponent = game.getPlayer(game.getOpponents(player.getId()).stream().findFirst().orElse(null));
if (opponent == null) {
return Integer.MAX_VALUE;
}
if (game.checkIfGameIsOver()) {
if (player.hasLost() || opponent.hasWon()) {
return Integer.MIN_VALUE;