* Fixed a bug that the win method for a player did not handle the range correctly and did erroneously end the game while still multiple players alive (related to #6553).

This commit is contained in:
LevelX2 2020-05-25 18:09:28 +02:00
parent 365754b6f7
commit d2b8928e60
3 changed files with 76 additions and 8 deletions

View file

@ -2526,12 +2526,14 @@ public abstract class PlayerImpl implements Player, Serializable {
opponent.lostForced(game);
}
}
// if no more opponents alive, you win and the game ends
// if no more opponents alive (independant from range), you win and the game ends
int opponentsAlive = 0;
for (UUID opponentId : game.getOpponents(playerId)) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null && !opponent.hasLost()) {
opponentsAlive++;
for (UUID playerIdToCheck : game.getPlayerList()) {
if (game.isOpponent(this, playerIdToCheck)) { // Check without range
Player opponent = game.getPlayer(playerIdToCheck);
if (opponent != null && !opponent.hasLost()) {
opponentsAlive++;
}
}
}
if (opponentsAlive == 0 && !hasWon()) {
@ -2541,7 +2543,7 @@ public abstract class PlayerImpl implements Player, Serializable {
game.end();
}
} else {
logger.debug("player won -> but already lost before: " + this.getName());
logger.debug("player won -> but already lost before or other players still alive: " + this.getName());
}
}
}