LudoController constructor
LudoController({
- required List<
LudoPlayer> players, - LudoDiceRules diceRules = const LudoDiceRules(),
- int diceRoller()?,
- LudoDiceRolledCallback? onDiceRolled,
- LudoPieceMovedCallback? onPieceMoved,
- LudoPieceCapturedCallback? onPieceCaptured,
- LudoTurnChangedCallback? onTurnChanged,
- LudoPlayerWonCallback? onPlayerWon,
- LudoTeamWonCallback? onTeamWon,
- LudoGameFinishedCallback? onGameFinished,
- LudoTurnForfeitedCallback? onTurnForfeited,
- @Deprecated('Audio was removed in 0.1.0. This flag has no effect.') bool enableAudio = true,
- Duration stepAnimationDuration = const Duration(milliseconds: 180),
- List<
LudoTeam> ? teams, - Set<
int> botPlayers = const {}, - LudoBotDifficulty botDifficulty = LudoBotDifficulty.medium,
- LudoBotStrategy? botStrategy,
- Duration botThinkDuration = const Duration(milliseconds: 500),
- bool autoMoveSingleChoice = true,
- Duration autoMoveDelay = const Duration(milliseconds: 250),
Implementation
LudoController({
required List<LudoPlayer> players,
this.diceRules = const LudoDiceRules(),
int Function()? diceRoller,
this.onDiceRolled,
this.onPieceMoved,
this.onPieceCaptured,
this.onTurnChanged,
this.onPlayerWon,
this.onTeamWon,
this.onGameFinished,
this.onTurnForfeited,
@Deprecated('Audio was removed in 0.1.0. This flag has no effect.')
bool enableAudio = true,
this.stepAnimationDuration = const Duration(milliseconds: 180),
// Teams mode — pass kDefaultTeams or a custom list to enable.
List<LudoTeam>? teams,
Set<int> botPlayers = const {},
LudoBotDifficulty botDifficulty = LudoBotDifficulty.medium,
LudoBotStrategy? botStrategy,
this.botThinkDuration = const Duration(milliseconds: 500),
this.autoMoveSingleChoice = true,
this.autoMoveDelay = const Duration(milliseconds: 250),
}) : assert(
players.length >= 2 && players.length <= 4,
'flutter_ludo supports 2 to 4 players.',
),
assert(
teams == null || players.length == 4,
'Teams mode requires exactly 4 players.',
),
assert(diceRules.startAllowedValues.isNotEmpty),
assert(
botPlayers.every((i) => i >= 0 && i < players.length),
'botPlayers contains an index outside 0..${players.length - 1}.',
),
_diceRoller = diceRoller ?? _defaultDiceRoller,
_engine = LudoEngine(diceRules, teams: teams),
_bots = {...botPlayers},
botStrategy =
botStrategy ?? LudoBotStrategy.forDifficulty(botDifficulty) {
_state = LudoGameState.initial(players, teams: teams);
_scheduleNext();
}