roll method

LudoEngineRollResult roll(
  1. LudoGameState state,
  2. int diceValue
)

Implementation

LudoEngineRollResult roll(LudoGameState state, int diceValue) {
  final moves = computeLegalMoves(
    state, diceRules, diceValue,
    teams: teams,
  );

  if (moves.isEmpty) {
    return LudoEngineRollResult(
      state: state.copyWith(
        currentPlayerIndex: _nextPlayer(state, state.currentPlayerIndex),
        phase: LudoTurnPhase.awaitingRoll,
        legalMoves: const [],
        clearDiceValue: true,
      ),
      passed: true,
    );
  }

  return LudoEngineRollResult(
    state: state.copyWith(
      diceValue: diceValue,
      legalMoves: moves,
      phase: LudoTurnPhase.awaitingPieceSelection,
    ),
    passed: false,
  );
}