Reputation:
(source: blogcu.com)
Assume there is a rabbit and at position (1,1). Moreover, its home is at position (7,7). How can it reach that position ?
Home positon is not fix place.
Real question, I am trying to solve a problem on a book for exersizing c.What algorithm should I apply to find solution? Should I use linked list to store data?
Data is (1,1), (1,2),..., (3,3) ..., (7,7) Place marked with black shows wall.
Upvotes: 2
Views: 307
Reputation:
Breadth-first search is always a good one.
http://www.codeproject.com/KB/recipes/mazesolver.aspx
Upvotes: 0
Reputation: 54286
There are a bunch of search algorithms you can use. The easiest to implement will be either breadth-first search or depth-first search.
Algorithms like A* are likely to be more efficient but are a little harder to code.
Check out the Wikipedia "Search algorithms" page. It has links to a number of well-known algorithms.
Upvotes: 0
Reputation: 75625
Use A*. It is the classic go-to algorithm for path-finding (that article lists many other algorithms you can consider too).
By using A* you learn an algorithm that you might actually need in your normal programming career later ;)
An example evaluation of a maze similar to that in the question using A*:
Upvotes: 2