I’m using DFS algorithm with a stack data structure where the logic so far
while (stack is not empty){
pop last added cell
mark as visited
explore all available children(yet to be visited) in the following order left,right,top, down
push to stack
}
while this does traverse the whole maze it does so in a very organized fashion which is
down
up
right
left
my question is how can I make it random?
code:
while ( nodeList.Count > 0) {
Node temp = nodeList.Pop();
temp.visited = true;
if (temp.left!=null && temp.left.visited == false) {
nodeList.Push(temp.left);
}
if (temp.right != null && temp.right.visited == false)
{
nodeList.Push(temp.right);
}
if (temp.up != null && temp.up.visited == false)
{
nodeList.Push(temp.up);
}
if (temp.down != null && temp.down.visited == false)
{
nodeList.Push(temp.down);
}
yield return new WaitForSeconds(1f);
}