ghostPiece method

Tetromino ghostPiece(
  1. Tetromino piece,
  2. BoardState board
)

Returns the lowest valid Y the piece can drop to (for ghost piece).

Implementation

Tetromino ghostPiece(Tetromino piece, BoardState board) {
  var ghost = piece;
  while (true) {
    final dropped = ghost.copyWith(
      position: Position(ghost.position.row + 1, ghost.position.col),
    );
    if (hasCollision(dropped, board)) return ghost;
    ghost = dropped;
  }
}