function dfsPathfind(grid, start, end, allowDiag) {
const visited = new Set([key(start[0], start[1])]);
const prev = new Map();
const stack = [[start[0], start[1]]];
while (stack.length) {
const __pattern1 = stack.pop();
const cr = __pattern1[0];
const cc = __pattern1[1];
visitNode(cr, cc);
if (cr === end[0] && cc === end[1]) {
reconstructPath(prev, start, end);
return;
}
const neighbors = getNeighbors(grid, cr, cc, allowDiag).reverse();
for (const [nr, nc] of neighbors) {
const neighborKey = key(nr, nc);
if (visited.has(neighborKey)) continue;
visited.add(neighborKey);
prev.set(neighborKey, [cr, cc]);
stack.push([nr, nc]);
pushFrontier(nr, nc);
}
}
reportNoPath();
} def dfsPathfind(grid, start, end, allowDiag):
visited = Set([key(start[0], start[1])])
prev = Map()
stack = [[start[0], start[1]]]
while stack.length:
__pattern1 = stack.pop()
cr = __pattern1[0]
cc = __pattern1[1]
visitNode(cr, cc)
if ((cr == end[0]) and (cc == end[1])):
reconstructPath(prev, start, end)
return
neighbors = getNeighbors(grid, cr, cc, allowDiag).reverse()
for nr, nc in neighbors:
neighborKey = key(nr, nc)
if visited.has(neighborKey):
continue
visited.add(neighborKey)
prev.set(neighborKey, [cr, cc])
stack.push([nr, nc])
pushFrontier(nr, nc)
reportNoPath() #include <vector>
#include <algorithm>
void dfsPathfind(int grid, int start, int end, int allowDiag) {
auto visited = Set([key(start[0], start[1])]);
auto prev = Map();
auto stack = [[start[0], start[1]]];
while(stack.length) {
auto __pattern1 = stack.pop();
auto cr = __pattern1[0];
auto cc = __pattern1[1];
visitNode(cr, cc);
if(((cr == end[0]) && (cc == end[1]))) {
reconstructPath(prev, start, end);
return;
}
auto neighbors = getNeighbors(grid, cr, cc, allowDiag).reverse();
for(auto& [nr, nc] : neighbors) {
auto neighborKey = key(nr, nc);
if(visited.has(neighborKey)) {
continue;
}
visited.add(neighborKey);
prev.set(neighborKey, [cr, cc]);
stack.push([nr, nc]);
pushFrontier(nr, nc);
}
}
reportNoPath();
} public void dfsPathfind(int grid, int start, int end, int allowDiag) {
var visited = Set([key(start[0], start[1])]);
var prev = Map();
var stack = [[start[0], start[1]]];
while(stack.length) {
var __pattern1 = stack.pop();
var cr = __pattern1[0];
var cc = __pattern1[1];
visitNode(cr, cc);
if(((cr == end[0]) && (cc == end[1]))) {
reconstructPath(prev, start, end);
return;
}
var neighbors = getNeighbors(grid, cr, cc, allowDiag).reverse();
foreach(var (nr, nc) in neighbors) {
var neighborKey = key(nr, nc);
if(visited.has(neighborKey)) {
continue;
}
visited.add(neighborKey);
prev.set(neighborKey, [cr, cc]);
stack.push([nr, nc]);
pushFrontier(nr, nc);
}
}
reportNoPath();
} #include <stdio.h>
void dfsPathfind(int grid, int start, int end, int allowDiag) {
var visited = Set([key(start[0], start[1])]);
var prev = Map();
var stack = [[start[0], start[1]]];
while(stack.length) {
var __pattern1 = stack.pop();
var cr = __pattern1[0];
var cc = __pattern1[1];
visitNode(cr, cc);
if(((cr == end[0]) && (cc == end[1]))) {
reconstructPath(prev, start, end);
return;
}
var neighbors = getNeighbors(grid, cr, cc, allowDiag).reverse();
for(int _fod_i = 0; _fod_i < neighbors_len; _fod_i++) {
int nr = neighbors[_fod_i][0];
int nc = neighbors[_fod_i][1];
var neighborKey = key(nr, nc);
if(visited.has(neighborKey)) {
continue;
}
visited.add(neighborKey);
prev.set(neighborKey, [cr, cc]);
stack.push([nr, nc]);
pushFrontier(nr, nc);
}
}
reportNoPath();
}