function shortestPath(target) {
const queue = [[1, 1, 0]];
const visited = new Set(["1,1"]);
while (queue.length) {
const [x, y, steps] = queue.shift();
if (x === target[0] && y === target[1]) {
return steps;
}
for (const [dx, dy] of dirs) {
const [x2, y2] = [x + dx, y + dy];
if (
x2 >= 0 &&
y2 >= 0 &&
!wallAt(x2, y2) &&
!visited.has(`${x2},${y2}`)
) {
visited.add(`${x2},${y2}`);
queue.push([x2, y2, steps + 1]);
}
}
}
}