Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix pathfinding bug, where the algo would incorrectly choose the path if the two tiles were on the same axis.
The previous check
not new_tile[0] == prev_best[0](and it's equivalent for vertical movement) would always be true even when moving on the same axis (e.g. ifprev_tileis [10, 10],prev_bestis [9, 10], andnew_tileis [11, 10]).We now check if the difference is 1, which only happens if it moves on a different axis.
In the example above, if the direction was [1, 1] (top-right) the function would still return
Falseas bothif previous_move_direction == self.HORIZONTAL and abs(new_tile[0] - prev_best[0]) == 1:andif prev_tile[1] == new_tile[1]:would be true. Now the first if is correct;y evaluated to false, and the code uses the section that starts atdirection = self._get_direction_from_endpoints(end_points)which would previously never be hit.Also, updates the comments in this function to make it clear what this function does and how it does it.