function move(initGrid, [rowStart, colStart], [rowEnd, colEnd], t) {
const [nRows, nCols] = [initGrid.length, initGrid[0].length];
const visited = blank(initGrid);
visited[rowStart][colStart] = t;
while (visited[rowEnd][colEnd] === ".") {
const grid = gridAt(initGrid, t + 1);
const spaces = [];
for (let row = 0; row < nRows; row++) {
for (let col = 0; col < nCols; col++) {
if (visited[row][col] === t) {
if (col < nCols - 1 && grid[row][col + 1] === ".") {
spaces.push([row, col + 1]);
}
if (row < nRows - 1 && grid[row + 1][col] === ".") {
spaces.push([row + 1, col]);
}
if (grid[row][col] === ".") {
spaces.push([row, col]);
}
if (row > 0 && grid[row - 1][col] === ".") {
spaces.push([row - 1, col]);
}
if (col > 0 && grid[row][col - 1] === ".") {
spaces.push([row, col - 1]);
}
}
}
}
spaces.forEach(([row, col]) => (visited[row][col] = t + 1));
t++;
}
return t;
}