flutter_ludo library
flutter_ludo
A complete Ludo game for Flutter: rules engine, animated board, dice, bots with three difficulty levels, 2v2 teams mode, configurable dice rules, and save/restore. See the package README for a full usage guide.
Classes
- LudoBoard
- The Ludo board with all pieces. Rebuilds automatically when controller changes, and lets the human whose turn it is tap a highlighted piece to move it.
- LudoBotStrategy
- Decides which legal move a bot plays.
- LudoController
- 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.
- LudoDice
- Dice face plus a roll button, bound to a LudoController.
- LudoDiceFace
-
A flat die face with pips. Shows a dash when value is
null. - LudoDiceRules
- Configurable dice behaviour and turn rules.
- LudoEasyBot
- Picks uniformly at random among the legal moves.
- LudoEngine
- Pure stateless engine. Pass teams to enable teams mode.
- LudoEngineMoveResult
- LudoEngineRollResult
- LudoGame
- A full game screen: status bar, board, dice, and a game-over dialog. Rebuilds automatically as controller changes.
- LudoGameState
- Immutable snapshot of the entire game.
- LudoHardBot
- The strongest built-in bot.
- LudoLegalMove
- A single legal move available to the current player for the value that was just rolled. See LudoGameState.legalMoves.
- LudoMediumBot
-
Uses
LudoMoveScorer's additive heuristics. - LudoPiece
- A single playing piece.
- LudoPlayer
- Describes a single Ludo player.
- LudoSetup
- A complete, self-contained Ludo app screen: a setup page (player count, human/bot seats, bot difficulty, teams mode, rule set) that launches a LudoGame and returns to setup when the player taps back.
- LudoTeam
- Defines a team in teams mode.
- LudoTheme
- Visual styling for LudoBoard, LudoDice, and LudoGame.
Enums
- LudoBotDifficulty
- Built-in bot skill levels. See LudoBotStrategy.forDifficulty.
- LudoPieceState
- Lifecycle state of a single LudoPiece, per the package specification.
- LudoTurnPhase
Constants
- kBoardGridSize → const int
- Width/height of the board grid, in cells.
-
kCenterCell
→ const List<
int> - The single center cell every piece is ultimately heading toward.
-
kDefaultTeams
→ const List<
LudoTeam> - The two fixed teams used in 2v2 teams mode.
-
kHomeBaseOrigins
→ const List<
List< int> > -
Top-left
[row, col]origin of each player's 6x6 home base quadrant, in the same player-index order as kStartIndices. -
kHomeStretchCells
→ const List<
List< List< >int> > - Each player's 5-cell colored home stretch, ordered from its entrance (reached right after the 51st shared-path cell) to the cell adjacent to the center. Indexed by player (0-3), in the same order as kStartIndices.
-
kHomeYardSlots
→ const List<
List< int> > -
Local
[row, col]offsets (within a 6x6 home base) where a player's 4 waiting pieces sit before entering the board. -
kPathCells
→ const List<
List< int> > -
The 52 cells of the shared outer path, listed in clockwise travel order
as
[row, col]pairs. Index 0 is player 0's start cell; index 13 is player 1's; 26 is player 2's; 39 is player 3's (see kStartIndices). -
kSafeIndices
→ const Set<
int> - Indices into kPathCells that are designated "star"/safe cells. A piece sitting on one of these cells (including any player's start cell) can never be captured.
-
kStartIndices
→ const List<
int> - Index into kPathCells where each of the 4 players enters the board.
Functions
-
areTeammates(
int a, int b, List< LudoTeam> ? teams) → bool -
Returns true if
aandbare teammates. -
captureOpponents(
{required List< LudoPiece> pieces, required LudoPiece mover, List<LudoTeam> ? teams}) → List<LudoPiece> -
Determines which opponent pieces are captured when
moverlands on a cell. -
computeLegalMoves(
LudoGameState state, LudoDiceRules diceRules, int diceValue, {List< LudoTeam> ? teams}) → List<LudoLegalMove> -
Computes all legal moves for the current player given
diceValue. -
globalCellOf(
int playerIndex, int trackPosition) → int -
Resolves a piece's relative track position (must be in
0..50, i.e. on the shared path — seeLudoPiece.isOnSharedPath) forplayerIndexto an absolute index into kPathCells. -
gridCellFor(
int playerIndex, int trackPosition) → List< int> ? -
Resolves any non-home track position to a
[row, col]grid cell, for rendering. -
hasPlayerWon(
List< LudoPiece> pieces, int playerIndex) → bool -
Returns true if
playerIndex's own 4 pieces have all finished. -
hasTeamWon(
List< LudoPiece> pieces, LudoTeam team) → bool -
In teams mode: returns true if both players on
teamhave all 4 pieces finished (8 pieces total). -
isGameFinished(
int winnersCount, int totalPlayers, {List< LudoTeam> ? teams, List<LudoPiece> ? pieces}) → bool - Returns true if the overall game is finished.
-
isSafeCellIndex(
int globalIndex) → bool - Whether the given absolute index into kPathCells is a safe cell.
-
resolvePieceState(
LudoPiece piece) → LudoPieceState -
Derives
piece's current LudoPieceState, using the fixed board geometry to determine whether it currently sits on a safe cell. -
teamOf(
int playerIndex, List< LudoTeam> ? teams) → LudoTeam? -
Returns the LudoTeam that
playerIndexbelongs to, fromteams. Returns null ifteamsis null (i.e. not in teams mode).
Typedefs
- LudoDiceRolledCallback = void Function(int value)
-
LudoGameFinishedCallback
= void Function(List<
int> winnersInOrder) - LudoPieceCapturedCallback = void Function(LudoPiece captured, LudoPiece by)
- LudoPieceMovedCallback = void Function(LudoPiece piece, int from, int to)
- LudoPlayerWonCallback = void Function(int playerIndex, int place)
- LudoTeamWonCallback = void Function(LudoTeam team)
- Fired when a full team wins in teams mode.
- LudoTurnChangedCallback = void Function(int value)
- LudoTurnForfeitedCallback = void Function(int playerIndex, int place)
- Fired when a roll is forfeited by LudoDiceRules.forfeitStreak.