Skip to content

Conversation

@domob1812
Copy link
Member

This updates the logic in the path finder for stepping the path once the distance map has been computed. Instead of always choosing the next direction based on a fixed order of all six principal directions, we try to stick to the previous direction as long as possible. This is a greedy approach to minimise the number of turns taken, and thus the number of waypoints and sizes of moves. The resulting paths are still of optimal length.

This does not affect consensus (nor would future tuning of the algorithm), since path finding is no longer part of consensus since #145).

This introduces a new type HexCoord::Difference, which represents not
absolute coordinates but differences between them (i.e. directions or
steps).

While both of them are quite similar, they are used differently in e.g.
the arithmetic operations.  Previously both were using the same type, but
this change enforces using the right type in each place now.
When stepping paths, try to continue the last direction as long
as possible while still retaining the optimal distance.  This helps
to avoid unnecessary turns (which then lead to unnecessary many waypoints
in moves).

Note that the implementation is very simple and just a greedy approach, so
it is not (?) guaranteed to really minimise the number of turns.  It does so
quite well in practice, though.

Since the path finder is not part of consensus, this change is not forking
the game state (nor would further tweaks to the algorithm cause forks).
@domob1812 domob1812 added the performance Something related to improving performance label Apr 30, 2021
@domob1812 domob1812 added this to the 0.4 milestone Apr 30, 2021
@domob1812 domob1812 force-pushed the master branch 4 times, most recently from 0852243 to 45886a9 Compare September 20, 2025 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Something related to improving performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants