resolvePieceState function

LudoPieceState resolvePieceState(
  1. LudoPiece piece
)

Derives piece's current LudoPieceState, using the fixed board geometry to determine whether it currently sits on a safe cell.

Implementation

LudoPieceState resolvePieceState(LudoPiece piece) {
  if (piece.isHome) return LudoPieceState.home;
  if (piece.isFinished) return LudoPieceState.finished;
  if (piece.isOnHomeStretch) return LudoPieceState.safe;

  final cell = globalCellOf(piece.playerIndex, piece.trackPosition);
  return isSafeCellIndex(cell) ? LudoPieceState.safe : LudoPieceState.active;
}