Skip to content

Conversation

@wlame
Copy link
Owner

@wlame 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

Copy link
Collaborator

@maxtropets maxtropets Mar 11, 2025

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.

Copy link
Collaborator

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?..

Copy link
Owner Author

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.

Copy link
Owner Author

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.

Copy link
Collaborator

@maxtropets maxtropets Apr 14, 2025

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?

Copy link
Owner Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

- added a_star function with the same signature as dijkstra
- added a 'radius' parameter to BlockageGrid constructor
- some minor improvements
@wlame wlame force-pushed the a_star_path_finding branch from 9e4de3b to 1ce5e82 Compare May 24, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants