I have an input file which is a 4X4 matrix, and each item of the matrix is represented by 4 digits 0's and 1's. 1 is closed and 0 means open, the direction is NSEW ( first digit represents North and so on..). I'm trying to recursively find my way from 1 point to another in the maze. Please help :)

Also I am using a stack to store my data, i have coded that up in a .h file along with an overloaded extraction operator so I can do stuff like fout<< Path.Push(data);

Recommended Answers

All 2 Replies

Just turn right.

Below is the general outline of how you would use backtracking / branch and bound to solve it.

bool promising( node n); // returns true if n is solution or could lead to solution
void checknode( node n)
{
  if( promising(n))
  {
    if(node is target point)
    {
      writeSolution();
    }

    else
    {
      for each node m that is adjacent to n
      {
         checknode(m)
      }
    }

  }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.