logo
down
shadow

I'm trying to change my Maze traversal recursive coding part into a while loop


I'm trying to change my Maze traversal recursive coding part into a while loop

By : entry_level_programm
Date : October 23 2020, 11:12 PM
This might help you Create a struct to hold X, Y and direction (the three things that change between calls). We'll call that struct State;
Create a std::stack object. Push the current values of X,Y, direction onto the stack before you change them, pop them after you do your work.
code :


Share : facebook icon twitter icon
Recursive backtracker maze generation algorithm stack loop

Recursive backtracker maze generation algorithm stack loop


By : gautam
Date : March 29 2020, 07:55 AM
this will help You swapped x and y in first if in isGood function (grid[x][y] instead of grid[y][x]). This causes the problem at least sometimes.
Right hand maze traversal in C

Right hand maze traversal in C


By : Ali A
Date : March 29 2020, 07:55 AM
it should still fix some issue You are missing the break; statements in the switch(face) after each case: block of code. Without the break; statements, your code will fall through to each of the next case:, which is not what you want.
In order Traversal Breaking Out Of Recursive Loop

In order Traversal Breaking Out Of Recursive Loop


By : user3812086
Date : March 29 2020, 07:55 AM
hope this fix your issue Your problem is that when you return from one level in the recursive stack indicating that you found the target, you forget to use this information at the higher levels to stop the search. Try this (remove the print statements in your final product of course):
code :
private static boolean modifiedInorderTraversal(Node newRoot, Node target){     
    boolean foundIt = false;

    if(newRoot.leftPointer != null){
        foundIt = modifiedInorderTraversal(newRoot.leftPointer, target);
        if(foundIt){
            System.out.println("Target found in left subtree");
            return true;
        }
    }

    System.out.println("searching: "+newRoot.value);
    if(newRoot == target){
        System.out.println("Target found at current node!");
        return true; //the target is this node!
    } 

    if(newRoot.rightPointer != null){
        foundIt = modifiedInorderTraversal(newRoot.rightPointer, target);
        if(foundIt){
            System.out.println("Target found in right subtree!");
            return true;
        }
    }

    System.out.println("Not found below root "+newRoot.value);
    return false; //the target is in neither subtree, and is not the root :-(
}

//My tree:
//      a
//    /   \
//    b    c
//   /\    /\
//  d e   f  g
public static void main(String[] arg){
    Node d = new Node(null,null,"d");
    Node e = new Node(null,null,"e");
    Node f = new Node(null,null,"f");
    Node g = new Node(null,null,"g");

    Node b = new Node(d,e,"b");
    Node c = new Node(f,g,"c");

    Node a = new Node(b,c,"a");

    System.out.println("Searching for f");
    if(modifiedInorderTraversal(a, f)){
        System.out.println("Success!");
    }

    System.out.println("---------------------------------");

    System.out.println("Searching for q");
    Node q = new Node(null,null,"q");
    if(modifiedInorderTraversal(a, q)){
        System.out.println("Shouldn't make it here...");
    } else{
        System.out.println("Didn't find q, as we shouldn't");
    }
}

private static class Node {
    public Node(Node left, Node right, String value){
        leftPointer = left;
        rightPointer = right;
        this.value = value;
    }
    Node leftPointer;
    Node rightPointer;
    String value;
}
Searching for f
searching: d
Not found below root d
searching: b
searching: e
Not found below root e
Not found below root b
searching: a
searching: f
Target found at current node!
Target found in left subtree
Target found in right subtree!
Success!
---------------------------------
Searching for q
searching: d
Not found below root d
searching: b
searching: e
Not found below root e
Not found below root b
searching: a
searching: f
Not found below root f
searching: c
searching: g
Not found below root g
Not found below root c
Not found below root a
Didn't find q, as we shouldn't
How can i change the maze generate part so the maze will be on the terrain X,Z not Y?

How can i change the maze generate part so the maze will be on the terrain X,Z not Y?


By : ConfusedNewb
Date : March 29 2020, 07:55 AM
wish helps you To rotate all the cubes at once, I would rotate the parent object they are all attached to. I would simply change the rotation of the parent object in the Start function of your MazeGenerator script, so your Start would look like this:
code :
void Start ()
{
    mazeRG = new System.Random();

    if (mazeWidth % 2 == 0)
        mazeWidth++;

    if (mazeHeight % 2 == 0)
    {
        mazeHeight++;
    }

    maze = new Maze(mazeWidth, mazeHeight, mazeRG);
    GenerateMaze();
    transform.localRotation = Quaternion.Euler(90, 0, 0);
}
Issue with my recursive maze traversal algorithm

Issue with my recursive maze traversal algorithm


By : ali
Date : March 29 2020, 07:55 AM
This might help you There's a lot of good advice in the comments; I'll just try and summarize them as best I can.
MePePeR's Advice: Use one method call
Related Posts Related Posts :
  • `LoadLibraryExW` triggers exception `0xC0000023` from `NtMapViewOfSection`
  • static_cast to a struct type to access all of its member variable
  • Forward declaration for boost::intrusive_ptr class to reduce compile time
  • How to use priority_queue with a non-static compare method of class instance?
  • Template parameters inside and outside class/struct
  • Determining prime number
  • How to resolve ambiguity between constructors taking std::string and std::vector
  • My program crashes when I try to change private values from an object
  • Unordered_map with custom class as key
  • Strict aliasing rules broken with templates and inheritance
  • C++ Derived Class Override Return Type
  • singly linked list c++ constructor, destructor and printing out
  • How to clone class with vector of unique_ptr to base class
  • error: no match for operator
  • std::vector doesnt accept my struct as template
  • selection of people's contours
  • how to fix the (Error using mexOpenCV) on matlab?
  • Is or was there a proposal for c++ to use the context for short enum values?
  • Fair assumptions about std::hash implementations
  • undefined reference to libusb using cyusb
  • Function returns null pointer instead of address
  • C++17 copy elision and object destruction
  • Input multiple strings via operator>> c++
  • Avoiding overflow boost container
  • How to Write a Lambda Wrapping a Function with Optional Return Value
  • Partial specialization with more template parameters
  • How to convert fixed size array to pointer on pointer array
  • Memory leak in const member constructor with tag dispatching
  • C++ function with a generic and optional class
  • Custom QGraphicsItem That Contains Child QGraphicsItems
  • Are There Restrictions on What can be Passed to auto Template Parameters?
  • Rotating line inside rectangle bounds
  • Why do I need dynamic memory allocation if I can just create an array?
  • How can I convert a text file into a form that MPI_Bcast can send?
  • How to get array of all `this` of an instance
  • Using pointers as parameters
  • Automatic type deduction with const_cast is not working
  • Why does std::is_rvalue_reference not do what it is advertised to do?
  • Function Template Specialization with Forward Declared Type
  • template deduction failed in vector
  • Is there a signed `sizeof` alternative in Qt
  • clarification on overloading the -> operator
  • What is __m128d?
  • QtConcurrent: why releaseThread and reserveThread cause deadlock?
  • Function receiving different value than passed
  • Can C++ close a '''fstream''' variable after '''.close()'''?
  • Is it necessary to overload operator in this specific case
  • Comparing an element of a string array with a string
  • how to dereference a pointer of a map of pointers to objects in c++
  • How recursive function control flow change for static variable?
  • SDL 2 blitting BMP File
  • Why does an extremely large value cause this code to repeat infinitely?
  • Function returning different value than what is in function body before return statement
  • Struggling with including Headers in another header file (C++)
  • WebViewProcessControl initialization crash
  • C++ exception 0xC00000FD: Stack overflow (parameters: 0x00000001, 0x00C02F30)
  • What's difference between forward and move in the constructor of class?
  • C++: Is it possible to condense `bool` objects within the same byte?
  • I cant understand this access modifier
  • Boost Spirit X3: Collapsing one-element lists
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org