I’m trying to automate the maze search I’ve created (I know I keep posting about this one). So weird issue, I need to test if the paths have been explored so I created a variable that can be updated every time there is no unvisited neighbor, however I got stuck for a while here as I simply put the path_evaluated counter in the else statement, which would cause it to run endlessly and therefore “detect” the procedure was finished prematurely, It wasn’t until I specifically created a (!next) statement that it was able to correctly identify the number of paths it had evaluated. Again this is probably a noobish question but I thought that else was only supposed to run if the original statement was false.
function findnode(){
if(nodes_array_Created&&!paths_completed){
var counts = nodesindex.length;
while(ad<counts){
total_paths += nodesindex[ad].neighbours.length;
ad++;
}
for(var i=0;i<nodesindex.length;i++){
var a = key_Node[i].original_id.toString();
var b = key_Node[i].original_id;
nodesindex[i].connectedNodes[b] = true;
var next = nodesindex[i].neighbour_Node(b);
var steps_to_nodes = key_Node[i].steps_to_nodes;
find_node_count ++;
if(key_Node[i].nodes<key_Node[i].neighbours.length){
if(next){
nodesindex[i].highlight();
if(next.node){
next.connectedNodes[b]=true;
var a = nodesindex[i].parent[0]
var b = nodesindex[i].parent[1]
if(a === key_Node[i]){
var node_info = [];
for(var j=0;j<key_Node[i].node_info.length;j++){
if(!key_Node[i].node_info[j][0]&&node_info.length<1){
node_info = key_Node[i].node_info[j];
}}
if(node_info.length>0){
node_info[0] = steps_to_nodes;
node_info[1] = next;
}
}
else if(b === key_Node[i]){
var node_info = [];
for(var j=0;j<key_Node[i].node_info.length;j++){
if(!key_Node[i].node_info[j][0]&&node_info.length<1){
node_info = key_Node[i].node_info[j];
}}
if(node_info.length>0){
node_info[0] = steps_to_nodes;
node_info[1] = next;
}
}
if(nodesindex[i].node){
var node_info= [];
for(var j=0;j<next.node_info.length;j++){
if(!key_Node[i].node_info[j][0]&&node_info.length<1){
node_info = key_Node[i].node_info[j];
}}
if(node_info.length>0){
node_info[0] = steps_to_nodes;
node_info[1] = next;
}
}
key_Node[i].steps_to_nodes = 1;
nodesindex[i] = key_Node[i];
key_Node[i].nodes ++;
//paths_evaluated ++;
}
else{
key_Node[i].steps_to_nodes ++;
if(!next.node_info[0][1] ){
next.node_info[0][0] = steps_to_nodes;
next.node_info[0][1] = key_Node[i];
}
else{
next.node_info[1][0] = steps_to_nodes;
next.node_info[1][1] = key_Node[i];
}
key_Node[i].child.push([steps_to_nodes,next]);
nodesindex[i] = next;
}
}
else {
nodesindex[i] = key_Node[i];
if(count>0){
key_Node[i].steps_to_nodes = 1;
}}
if(!next){
paths_evaluated++;
}
}
else if(!key_Node[i].evaluated){
key_Node[i].evaluated = true;
//paths_evaluated ++;
}
}
console.log(testing)
for(var i=0;i<key_Node.length;i++){
var c = key_Node[i].original_id;
//nodesindex[i].connectedNodes[b] = true;
var nextKey = key_Node[i].neighbour_Node(c);
if(!next){
//paths_evaluated ++;
}
}
}
};