Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 160x 160x 160x 160x 334x 13x 147x 435x 1x 146x | export function findStackableRowIndex(
rowCount: number,
preferredRow: number,
canPlaceAt: (targetRow: number) => boolean,
): number | undefined {
const safeRowCount = Number.isFinite(rowCount) ? Math.max(0, Math.floor(rowCount)) : 0;
const safePreferredRow = Number.isFinite(preferredRow) ? Math.floor(preferredRow) : 0;
Iif (safeRowCount <= 0) {
return undefined;
}
// Keep overlap ordering deterministic for SCROLL=0 stacks: prefer rows farther from the judge line (upper rows)
// first.
for (let targetRow = safePreferredRow - 1; targetRow >= 0; targetRow -= 1) {
if (canPlaceAt(targetRow)) {
return targetRow;
}
}
for (let targetRow = safePreferredRow + 1; targetRow < safeRowCount; targetRow += 1) {
if (canPlaceAt(targetRow)) {
return targetRow;
}
}
return undefined;
}
|