1 1 1 1 1 1 1 1 1 1
1 1 0 0 0 1 0 T 0 1
S 0 0 1 1 1 0 1 1 1
1 1 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1 1

Could you please help me solve this exercise ?
Need some help how to implement "Wall follower" Algorithm in order to find a path to the treasure.
I have to build a programme in C that reads a matrix with 0 and 1, asks the user to give START and TREASURE coordinates and finds a path to the treasure.
"1" means you cannot pass through that value, "0" means you can pass through that value.

Looking forward to get an answer from you. Thanx in advance.

I have to build a programme

Yes, you have to build it. What have you tried so far? What has your research into solving the problem shown you so far? Have you done anything?

This is programming. Thinking about a problem in such a way that the solution lends itself to a programmatic implementation. All the rest is syntax and learning your tools.

How would you do this on paper? Don't think about how to code it - think about how to solve it.

I imagine you might start by doing something like this:

  1. Starting position; move in any random direction I can.
  2. Try to turn (and go) left. If I can't turn left, go forwards. If I can't go forwards, turn (and go) right. If I can't turn right, go back (and note that now "my left" is changed around as well).

Now you do the next step.

It's really that simple. Programming is thinking.

This article has been dead for over six months. Start a new discussion instead.