Rfe 6295: teach princess that leaping is dangerous #6311
Merged
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.
Summary
This patch looks to fix a long-standing issue with Princess pathing where she needlessly risks her units while attempting to close with opponents. The title RFE refers to Leaping (from TacOps) but this likely applies to any number of hazards, specifically during the early turns before fire is exchanged.
Problem
Currently Princess generates a large set of prospective paths for every unit she controls:
This produces usually dozens or hundreds of possible paths to choose from, all valid from a movement standpoint.
During most entity behaviour types, such as fighting or retreating, we then rank all these paths to find the best (or least-worst) option among them.
But during the period where Princess's units are closing on but not yet engaging their enemies, we ignore these paths completely and try to create a very few longest-distance-possible paths to guide each unit towards A) a known enemy position, B) a suspected enemy position (esp. for the heat map), C) a strategic target, or D) the opposite map edge.
The problem is that we currently replace all pre-generated paths with these longest-distance paths, which may mean that a myriad of movement options are replaced by a few, or even just one, prospective high-speed movement path meant to close on the destination as soon as possible. And the way we generate these long-distance paths is ignorant of hazards and PSRs.
Given single, or a small selection of, very bad paths, Princess unfortunately just takes the least-bad option. In testing this bug I found that if one long-distance path contained a leap step, it was highly likely that all did, because they were selected to maximize movement towards a specific hex in a nearly-straight line; no paths that avoid the leap (or other hazards) completely could be generated. I warrant that this is true of other hazard types as well based on code inspection.
Solution
I chose to attack this issue in two ways:
I additionally tweaked the way that the bravery mod and expected success values apply to the expected outgoing and incoming damage values, to prevent the Bravery/Aggression setting from completely overwhelming the damage avoidance setting in the Bot configuration.
So far I have not seen any noticeable difference in path calculation times between the new and old code, likely because:
A) the unit paths I'm selecting from were already pre-calculated and validated by the time they are added back to the prospective paths list, and
B) the new PSR checks only trigger when leaps are included in paths to be ranked, which should happen less often now.
Testing
4.a. Large and small armies
4.b. Large and small maps
4.c. New and old code
Leap instances were definitely reduced, although not completely removed from every simulation run. They should still be available, after all, just not used inadvertently.
N.B.
*There is almost certainly an opportunity to speed up the initial unit path generation process by restricting its radius to the current unit's maximum MP in hexes, although comments in that code state that this process should be relatively fast even when scanning the entire map.