isGameFinished function

bool isGameFinished(
  1. int winnersCount,
  2. int totalPlayers, {
  3. List<LudoTeam>? teams,
  4. List<LudoPiece>? pieces,
})

Returns true if the overall game is finished.

  • Standard mode: winnersCount >= totalPlayers - 1
  • Teams mode: at least one full team has all 8 pieces home

Implementation

bool isGameFinished(
  int winnersCount,
  int totalPlayers, {
  List<LudoTeam>? teams,
  List<LudoPiece>? pieces,
}) {
  if (teams != null && pieces != null) {
    // Teams mode: game ends the moment one full team finishes.
    return teams.any((t) => hasTeamWon(pieces, t));
  }
  // Standard mode: all but one player have finished.
  return winnersCount >= totalPlayers - 1;
}