🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Path Calculation

Started by
5 comments, last by Nypyren 4 years, 11 months ago

Hi Volks

I'm stuck since weeks with my Gameproject because the Path Calculation. (programming in C)

The Game is 4096x4096 divided by tiles of 64x64. How can I find the shortest Path from green point to red point (attachment Image)

 

matrix64x64_path_calculation.png

Life is short, break the rules

Advertisement

what exactly is the problem?

I mean, the trivial thing would be to just create a recursive function, that would mark the current position and call itself for the 4 neighbours. when you reach the goal, you'd check if the current step count is lower than the currently shortest path and then store the way you've walked.

I assume, you have problems with some implementation detail? or are you trying to get some particular algorithm to work? in that case, where exactly are you stuck? Or is the 64x64 grid of 64x64 grids the problem?

You could look into a proven pathfinding algorithm such as A*. Make sure to cache the resulting path information though as A* can be rather expensive.

See: https://dev.to/jansonsa/a-star-a-path-finding-c-4a4h

Hope this helps!

7 hours ago, ProfL said:

what exactly is the problem?

I mean, the trivial thing would be to just create a recursive function, that would mark the current position and call itself for the 4 neighbours. when you reach the goal, you'd check if the current step count is lower than the currently shortest path and then store the way you've walked.

I assume, you have problems with some implementation detail? or are you trying to get some particular algorithm to work? in that case, where exactly are you stuck? Or is the 64x64 grid of 64x64 grids the problem?

I did something like this. but I need to find out the shortest path without walking into all the dead ends or walking back. but sometimes I have to walk back if I get the wrong way. I need something like a algorythm scheme.

 

6 hours ago, Brain said:

You could look into a proven pathfinding algorithm such as A*. Make sure to cache the resulting path information though as A* can be rather expensive.

See: https://dev.to/jansonsa/a-star-a-path-finding-c-4a4h

Hope this helps!

Thanks, will check it out ?

Life is short, break the rules

Thank you Guys, I've found a solution here https://www.youtube.com/watch?v=KiCBXu4P-2Y

 

Life is short, break the rules

BFS is the easiest algorithm to implement which finds an optimal path.  Even though A* is typically recommended for pathfinding, BFS is much easier to implement correctly and works great for mazes in particular.

This topic is closed to new replies.

Advertisement