atum
Version:
A Procedural Graph Based Javascript Library
39 lines (29 loc) • 621 B
JavaScript
/**
* Module containing all the graph search algorithms
*/
// ---- Uninformed Search Algorithms ----
/**
* Search through the successors of a problem to find a goal
*
*
* @private
* @param {any} problem
* @param {Queue} frontier
*
*/
;
import Node from "Node";
function graphSearch(problem, frontier) {
frontier.push(new Node(problem.initial));
let node;
let explored = [];
while (frontier) {
node = frontier.pop();
if (problem.goalTest(node)) {
return node;
}
explored.push(node.state);
// ?
}
return null;
}