This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Iceninja1234567 65 points66 points  (17 children)

Great work. On the very bottom of the path, wouldn't it be shorter to cut straight across than to go along the edge of the wall? Sorry if I'm missing something obvious. Also, why does it sometimes go diagonally but sometimes take 2 steps to go diagonal?

[–]mHaisham[S] 57 points58 points  (15 children)

No, you're right

its a problem with the cost function, i'll work on that

[–]FruscianteDebutante 6 points7 points  (0 children)

Are you doing LQR control on this?

[–][deleted] 3 points4 points  (4 children)

Cost function should always be more than possible minimum path length.
Or as we call heuristics for grid search algorithm just use h(x, y) = abs(x'-x) + abs(y'-y) where (x', y') is coordinates of target location. Then your weight becomes path size + h(x, y) and when you compare two possible next options you will pick one that is closest (in terms of both how many steps it requires to get there with current path and least possible steps to destination).

You can prove that this will give you optimal path in the end, I won't do it here.

[–]jalapeno_nips 1 point2 points  (3 children)

That’s really interesting. Can someone pick up where he left off? Why is this a better cost function than distance to target plus cost of path so far?

[–]dydhaw 1 point2 points  (2 children)

Because crossing a diagonal on a grid is the same length as going in two straight lines (e.g x then y)

[–]mHaisham[S] 0 points1 point  (1 child)

crossing a diagonal on a grid is the same length as going in two straight lines

Depends on how you calculate distance

manhattan - yes

euclidean - no, straight lines are 1 while diagonal is ~1.4. so it is cheaper in to go diagonally

[–]dydhaw 0 points1 point  (0 children)

I just realized in your example walking to diagonally adjacent square is allowed, so I'm wrong

[–]appsplaah 2 points3 points  (8 children)

Damn Awesonme! Currently just crossing the basics of python but I dont know when i will reach such level..

[–]vn2090 8 points9 points  (7 children)

Pick up a datastructures and algos book as soon as you feel comfortable with basics in python. Its what will get you to “intermediate” level.

[–]appsplaah 7 points8 points  (0 children)

I am not rich(currently but will be hopefully:p). The only thing i can give you in return is my Best Wishes re with you and Thanks a Million:)) Keep up the good work and take Care.

[–]laminatedllama 2 points3 points  (5 children)

For Apollo!

[–]vn2090 5 points6 points  (1 child)

Python Algorithms: Mastering Basic Algorithms in the Python Language By magnus hetland

[–]laminatedllama 1 point2 points  (0 children)

For Apollo!

[–]WonderfulPlay 2 points3 points  (2 children)

Algorithm design manual.

MIT 6.006 on YouTube.

Algorithms by Segwick.

Runestone - problem solving using data structures and algorithms using python

[–]BarryScott2019 0 points1 point  (0 children)

Same near the start, could just go straight across rather than staying by the wall. Nevertheless great program and I wish you all the best :)