1

Do someone want to explain me (in pseudocode too) how the pathfinding/a* algorithm can be implemented in Python? I searched all over the internet but I am not able to understand how to calculate H-cost or G-cost. I found some source code, but it is too difficult for me (I am still a newbie).

Let's think I have a map like this:

'''
S0000000000000000000000000100000000000
00000000000000000000100000001000000000
10000111110101000001100000001000000000
01111100010001000010100000010000000000
00000100001111100100100001110000110000
00001100000001011000000100000001000000
00000100000000101000000000011110000001
00000010000000000111111111100000000011
00000001000000000000000001100000111100
00000000110000000000000000010011000000
00000000010000000001100000001000000000
00000000010000000000110000000111111000
00000000010000000000010000000000000000
00000000011000111111111111111111111111
000000000100000110000010000000000000E0
00000000001100000100001000000000000000
00000000000100000011000000000000000000
00000000000010000000000000000000000000
'''

Where 1s are obstacles, 'S' is the starting point and 'E' is the end. How can I implement that algorithm? It would be great also if you can link an internet page who explain it in a easy way.

martineau
  • 119,623
  • 25
  • 170
  • 301
Luca
  • 51
  • 3
  • 1
    A nice [page](https://www.redblobgames.com/pathfinding/a-star/introduction.html) with animations and stuff. – Gábor Fekete Jan 04 '18 at 16:42
  • Does this help? https://stackoverflow.com/questions/40871864/dijkstra-s-algorithm-in-python Or this https://stackoverflow.com/a/22899400/4014959 ? – PM 2Ring Jan 04 '18 at 16:44
  • Thank you for the two links, now I read those pages and see! – Luca Jan 04 '18 at 16:55
  • The g-cost is the cost of the path already "walked", while the h-cost is the estimation of the remaining cost of the path to reach the goal. They are dependent on the domain you apply the a* algorithm – FrankS101 Jan 05 '18 at 14:51

0 Answers0