* Server: fixed that multiplayer game can be closed on "1x human + 1x AI" remain (see #6178);

This commit is contained in:
Oleg Agafonov 2021-08-19 01:42:35 +04:00
parent 3da525520c
commit e488997124
2 changed files with 21 additions and 12 deletions

View file

@ -48,7 +48,7 @@ public class TableController {
private final UUID chatId;
private final String controllerName;
private final Table table;
private final ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<>(); // human players only, use table.seats for AI
private Match match;
private MatchOptions options;
@ -985,10 +985,14 @@ public class TableController {
// return false;
}
}
// check for active players
int validHumanPlayers = 0;
int validAIPlayers = 0;
int aiPlayers = 0;
int humanPlayers = 0;
// check humans
for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
if (matchPlayer == null) {
@ -1016,12 +1020,21 @@ public class TableController {
// user exits on the server and match player has not quit -> player is valid
validHumanPlayers++;
}
} else {
aiPlayers++;
}
}
// if at least 2 human players are valid (multiplayer) or all human players are valid the table is valid or it's an AI match
return validHumanPlayers >= 2 || validHumanPlayers == humanPlayers || aiPlayers > 1;
// check AI
for (MatchPlayer matchPlayer : match.getPlayers()) {
if (!matchPlayer.getPlayer().isHuman()) {
aiPlayers++;
if (matchPlayer.getPlayer().isInGame()) {
validAIPlayers++;
}
}
}
// table must contain minimum two active players
return (validAIPlayers + validHumanPlayers) >= 2;
}
return true;
}