-
Notifications
You must be signed in to change notification settings - Fork 0
Add a-star path finding algorythm. #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
wlame
commented
Mar 10, 2025
- added a_star function with the same signature as dijkstra
- added a 'radius' parameter to BlockageGrid constructor
- some minor improvements
| current = previous[current] | ||
| path.reverse() | ||
| return path | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're missing a check for g_score[current] == current_g_score. You shall not continue this iteration if that's not true.
Unlike Dijkstra, A* may give you a worse (by g_score) hex first, unless your heuristic function guarantees the opposite.
Without this check it may actually perform way worse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it also may give you not the shortest path here?..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I got you correct that condition will allways be met.
In current_g_score we have the minimum value of g-scores needed to get to the final end hex. It is guaranteed by the heap, based on the f_score, which will differ from g_score by the constant value of last step (f_score = g_score + heuristic(neighbor)). So minimal f_score means minimal g_score.
⬆️ That was not an AI comment I promise. Despite I also use . at the end of sentenses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be happy to setup test that proves the opposite and dig inside to figure out what am I missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So minimal f_score means minimal g_score.
Why do you need both f and g then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because those mean different things — minimal cost to get to currect cell and estimation cost to get from current cell to target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My claim is - it magically works because of the simplicity of the current heuristics. If you were to add some more penalties (let's say, you want the most straight (fewer turns) path), then you may end up getting wrong results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means that you have to sort by the score which determines what's your best result, and if you're not - than you have to check your current g_score is the best before printing result. So the check I'm talking about should happen earlier.
a0d0155 to
9e4de3b
Compare
- added a_star function with the same signature as dijkstra - added a 'radius' parameter to BlockageGrid constructor - some minor improvements
9e4de3b to
1ce5e82
Compare