# Algorithm Path Calculation

## Recommended Posts

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)

##### Share on other sites

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?

##### Share on other sites

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.

Hope this helps!

##### Share on other sites
Posted (edited)
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.

Hope this helps!

Thanks, will check it out 😀

Edited by Swiss Cheese

##### Share on other sites

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.

## Create an account

Register a new account

• 18
• 25
• 11
• 21
• 16