SebLague / Pathfinding

MIT License
668 stars 251 forks source link

Bug in Ep3 code to find node with lowest F cost #10

Open stefanct opened 4 years ago

stefanct commented 4 years ago

https://github.com/SebLague/Pathfinding/blob/b938872d12bbf9a78cda1e88cbb6a5acff25ccbf/Episode%2003%20-%20astar/Assets/Scripts/Pathfinding.cs#L29-L32

This does only set another node as current if the h-cost is also lower not just the f-cost - also the first if does not make much sens since it can be rewritten as a single <=. In the respective video you use another version (https://youtu.be/mZfyt03LDH4?t=331) that might actually work because of associativity rules of || and && essentially leading to something like "lower f OR (equal f AND lower h)".

I was implementing a-star in plain C for fun after watching your videos and that bit confused me because I of course though I made an error somewhere else. Thanks for the inspiration - your videos are great.