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

Add [find_path] option "nearest_by", and simple_find_path test #4189

Open
wants to merge 1 commit into
base: master
from

Conversation

@stevecotton
Copy link
Contributor

commented Jul 22, 2019

WIP: I'd like suggestions of better names for these, and I'm also wondering
about making the behavior always "movement_cost", and not including the
other options.

Adding this is issue 2 of #4177, changing the behavior when [find_path]
is given a SLF which matches multiple hexes. Issue 1 of #4177 is to convert
the unit test and PR docs to wiki documentation about the current behavior.

The map and tests here should be easy enough for manually editing them. It
duplicates some of the functionality of the existing characterize_pathfinding
tests, however those tests need their expected values to be calculated and
can't be changed by hand.

'''nearest_by''': {DevFeature1.15|0} possible values "movement_cost"
(default), "steps", "hexes". If the [destination] SLF matches multiple hexes,
the one that would need the least movement points to reach may not be the one
that's closest as measured by '''hexes''', or closest as measured by steps,
from the starting point.

In the image, imagine an Elvish Scout standing on the Player 1 start, this unit has
9MP and needs 3MP for each shallow water tile, so it can reach every village without
needing a multi-turn move. Each village might be considered to be the "nearest":

  • "lake" is 3 hexes, 7 MP and 4 steps away
  • "spur" is 5 hexes, 5 MP and 6 steps away
  • "u_turn" is 2 hexes, 8 MP and 9 steps away

Behavior in 1.14 depended on which hex was checked first.

find_path_illustration

@CelticMinstrel

This comment has been minimized.

Copy link
Member

commented Jul 23, 2019

  1. You forgot to initialize current_steps on line 49.
  2. Lines 73 and 74 look mostly redundant? Both lines are testing essentially the same condition, the only difference being which comparison is < and which is <=. Is there a point to doing this? I could be missing something...
Add [find_path] option "nearest_by", and simple_find_path test
Adding this is issue 2 of #4177, changing the behavior when [find_path]
is given a SLF which matches multiple hexes.

The map and tests here should be easy enough for manually editing them. It
duplicates some of the functionality of the existing characterize_pathfinding
tests, however those tests need their expected values to be calculated and
can't be changed by hand.

'''nearest_by''': {DevFeature1.15|0} possible values "movement_cost"
(default), "steps", "hexes". If the [destination] SLF matches multiple hexes,
the one that would need the least movement points to reach may not be the one
that's closest as measured by '''hexes''', or closest as measured by steps,
from the starting point.

Behavior in 1.14 depended on which hex was checked first.
@stevecotton

This comment has been minimized.

Copy link
Contributor Author

commented Jul 23, 2019

Thanks for the review. current_steps seems to be initialized, it's just that the diff is showing that I added the first math.huge instead of the third one.

While cleaning up lines 73 and 74, I found a bug with steps being zero if the destination is inaccessible. Will push an update with that fixed, and more tests.

@stevecotton stevecotton force-pushed the stevecotton:find_path_nearest_by branch from a73e2bd to 3bbd6c3 Jul 23, 2019

@CelticMinstrel

This comment has been minimized.

Copy link
Member

commented Jul 23, 2019

Oh... I see, that was silly of me.

@stevecotton stevecotton changed the title WIP: Add [find_path] option "nearest_by", and simple_find_path test Add [find_path] option "nearest_by", and simple_find_path test Aug 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.