2

I am new to Python. I have this Code with me http://code.activestate.com/recipes/577519-a-star-shortest-path-algorithm/history/1/

its the A star algorithm code. I wanted to know how exactly is it generating the obstacles. Basically I have a black and white image. My task is to reach the end point from the start point avoiding the white spaces. Please help me Thank you!

3
  • What's the question? What have you tried yet? Commented Apr 24, 2014 at 7:21
  • I have an image. I have its pixels. All I want to do is find the path avoiding white region. How do you suggest I go about? Commented Apr 24, 2014 at 7:34
  • I'd use simple BFS in this case. Commented Apr 24, 2014 at 7:40

1 Answer 1

2

The path-finding algorithm in function pathFind() is well-commented and decomposed. If there's something specific confusing you, tell us what it is. The important lines are after # generate moves (child nodes) in all possible directions, which admittedly is dense code and not very OO.

I suggest you reduce the parameters (m,n) to a 4x5 or 5x6 then step through its execution, either with pdb debugger (single-step or set breakpoints at key points), or hacking in as many print statements as you need:

# map matrix
n = 30 # horizontal size
m = 30 # vertical size

First try giving it your own custom maps to get a feel for how it works (modify the # fillout the map matrix... lines). Then run it interactively in the debugger.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. I was foing the correct thing, but I was using a different image :P
I don't understand, did you solve your question? or not?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.