gridCellFor function

List<int>? gridCellFor(
  1. int playerIndex,
  2. int trackPosition
)

Resolves any non-home track position to a [row, col] grid cell, for rendering.

  • trackPosition in 0..50 -> a cell on the shared path.
  • trackPosition in 51..55 -> a cell in the player's home stretch.
  • trackPosition of 56 (finished) -> kCenterCell.

Returns null for a piece still at home (trackPosition < 0) — callers should use kHomeBaseOrigins / kHomeYardSlots for those instead.

Implementation

List<int>? gridCellFor(int playerIndex, int trackPosition) {
  if (trackPosition < 0) return null;
  if (trackPosition >= 56) return kCenterCell;
  if (trackPosition < 51) {
    return kPathCells[globalCellOf(playerIndex, trackPosition)];
  }
  return kHomeStretchCells[playerIndex][trackPosition - 51];
}