Skip to content
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

Avoid unnecessary turns in path finder #196

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

domob1812
Copy link
Collaborator

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

1 participant