LudoController class
Owns a game of Ludo: holds the current LudoGameState, applies rolls and moves through LudoEngine, animates piece movement step by step, and plays turns automatically for bot seats.
final controller = LudoController(
players: players,
botPlayers: {1, 2, 3}, // seat 0 is human
botDifficulty: LudoBotDifficulty.hard,
);
The controller is a ChangeNotifier; the bundled widgets listen to it automatically. Call dispose when you're done with it.
- Inheritance
-
- Object
- ChangeNotifier
- LudoController
- Implementers
Constructors
-
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)})
Properties
- animatingPiece → LudoPiece?
-
no setter
- autoMoveDelay → Duration
-
Delay before an automatic single-choice move, so the rolled value is
visible first.
final
- autoMoveSingleChoice → bool
-
When a human rolls and every legal move leads to the same result
(a single legal move, or several pieces stacked on the same cell),
play it automatically after autoMoveDelay.
final
- botDifficulty ← LudoBotDifficulty
-
Switches every bot to the built-in strategy for
difficulty.no getter -
botPlayers
→ Set<
int> -
Seats currently played by the bot.
no setter
- botStrategy ↔ LudoBotStrategy
-
The strategy bots use to pick moves. Can be swapped at any time.
getter/setter pair
- botThinkDuration → Duration
-
How long a bot waits before rolling or picking a piece.
final
- canRoll → bool
-
Whether a human may call rollDice right now.
no setter
- canSelectPiece → bool
-
Whether a human may call selectPiece right now.
no setter
- diceRules → LudoDiceRules
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isAnimating → bool
-
no setter
- isCurrentPlayerBot → bool
-
Whether the player to move is a bot.
no setter
- isPaused → bool
-
Whether automatic play (bots and auto-moves) is suspended.
no setter
- isTeamsMode → bool
-
no setter
- onDiceRolled → LudoDiceRolledCallback?
-
final
- onGameFinished → LudoGameFinishedCallback?
-
final
- onPieceCaptured → LudoPieceCapturedCallback?
-
final
- onPieceMoved → LudoPieceMovedCallback?
-
final
- onPlayerWon → LudoPlayerWonCallback?
-
final
- onTeamWon → LudoTeamWonCallback?
-
final
- onTurnChanged → LudoDiceRolledCallback?
-
final
- onTurnForfeited → LudoPlayerWonCallback?
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → LudoGameState
-
no setter
- stepAnimationDuration → Duration
-
Delay between each cell while a piece moves. Duration.zero commits
moves immediately (useful for tests and simulations).
final
-
teams
→ List<
LudoTeam> ? -
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object.
override
-
isBot(
int playerIndex) → bool -
Whether
playerIndexis played by the bot. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
pause(
) → void - Suspends bots and automatic moves, and blocks rollDice and selectPiece until resume is called. A move already animating finishes normally.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
reset(
) → void - Starts a new game with the same players, teams, and bot seats.
-
restore(
LudoGameState state) → void -
Replaces the current game with
state— e.g. one saved earlier with LudoGameState.toJson. Bot seats outside the new player range are dropped. -
resume(
) → void - Resumes play after pause.
-
rollDice(
) → int - Rolls the dice for the current (human) player and returns the value.
-
selectPiece(
int pieceId) → Future< void> -
Moves
pieceIdusing the current roll, animating it one cell at a time. Completes once the move is committed. -
setBot(
int playerIndex, bool isBot) → void -
Hands
playerIndexover to the bot (true) or to a human (false) — e.g. when a player leaves mid-game. -
suggestMove(
) → LudoLegalMove? -
The move the hard bot would play now, for showing a hint to a human.
nullunless a piece selection is pending. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited