MegaMek / megamek

MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight using giant robots, tanks, and/or infantry on a hex-based map.
http://www.megamek.org
GNU General Public License v2.0
295 stars 283 forks source link

[RFE] Make Princess take more notice of PSRs when route-planning #4878

Closed SimonLandmine closed 7 months ago

SimonLandmine commented 10 months ago

With all of the upgrades that have been applied to Princess, the AI is now considerably more effective. However, in a number of cases, it would appear that has resulted in an increased tendency towards self-destruction by PSR. These include, but are not limited to ...

This may be due to the very high weighting of TMM and thus movement speed in Princess' calculations, even when no enemy are in range. Would it be possible to increase the weighting of PSRs in Princess's logic, so that she is more careful about the driving maneuvers, as with the increased Princess training, the 'driving care' slider appears to have limited effect.

(And also ensuring that she is aware of the PSRs required by the TacOps advanced driving options, such as acceleration limits or turn limits, so that these are not risked unless not making these maneuvers would result in ending up in a considerably more risky location.)

(An alternative, more complex, suggestion was for Princess to assess the likely outcome of a loss of control depending on the terrain, but that would require considerably more processing time and additional weighting.)

SimonLandmine commented 10 months ago

One simpler solution proposed would be to add a toggle for Princess that prevents the AI attempting any maneuver that would require a PSR, but that would prevent e.g. attempting to stand and most hovercraft movement.

JonhyBurner commented 10 months ago

A simple toggle would make Princess less effective, I believe. No attempt to stand, no passing through rubble, etc.

Giving more weight to caution would be the way to go, but it would need to be incremental until it starts to reduce the bot's effectiveness. Not knowing when to stop is the reason why so many games have bad AI, so it's a tricky endeavour.

Maybe the alternative would be to code in a couple of conditionals for the most glaring mistakes Princess does, like full movement on abormal gravity. Not to remove the PSRs, but to give extra weight to the decision on when to trigger them.

Sleet01 commented 10 months ago

A simple toggle would make Princess less effective, I believe. No attempt to stand, no passing through rubble, etc.

Giving more weight to caution would be the way to go, but it would need to be incremental until it starts to reduce the bot's effectiveness. Not knowing when to stop is the reason why so many games have bad AI, so it's a tricky endeavour.

Maybe the alternative would be to code in a couple of conditionals for the most glaring mistakes Princess does, like full movement on abormal gravity. Not to remove the PSRs, but to give extra weight to the decision on when to trigger them.

I haven't looked at Princess's movement code yet, but does she do any analysis of PSR chances? If so, we could just tweak the existing weighting so that she only attempts PSRs with a 50%+ chance of success, or so that she is reticent to make more than one PSR per turn, or something.

If not, well... implementing some basic weighting would be a good first step.

gsparks3 commented 10 months ago

AFAIK a bot slider that is supposed to affect the weighting of negative PSR outcomes already exists ("Piloting Caution"), the catch is that from player testing, it does not actually seem to affect the bot's behavior much if at all.

I will also note that a 50% success rate as a threshold is actually quite low; the average bot PSR is something like a hovercraft turning while flanking, which at TN 5 from a 4/5 crew has a 83.3% chance of success. It's still more than enough to drift a lot of them into woods if there's more than one and they keep taking the risk every turn. Really the ideal would be to distinguish between "PSR which will instantly kill or cripple the unit if it fails" vs ones that won't, and weight the former far more negatively.

kuronekochomusuke commented 10 months ago

this slider sets the PSR range, its 50% to 100% in version .15

image

there are fall back paths that kick in if there are not any paths in the range.

Sleet01 commented 10 months ago

@gsparks3 I'd guess that determining which PSRs are "deadly" vs "annoying" might be the hard problem here.

gsparks3 commented 10 months ago

For at least two of the major pain points, it should be calculatable, although I'm less certain if the calculation will be sufficiently fast to keep pathfinding reasonable.

Situation 1: PSR to avoid sideslipping/skidding. After defining the hypothetical movement path, determine which hexes could be unintentionally entered by failing each such PSR; these can be determined based off the skid/sideslip rules. If any of these hexes contain prohibited terrain, failing this PSR is deadly. Unhelpfully, this check would have to be run for every hypothetical movement path containing such a PSR (or even multiple times per path if needed), so it might use a larger amount of computational resources than desired.

Situation 2: PSR to avoid taking damage from excessive MP usage in low gravity. Here the penalty is a fixed amount of damage to the internal structure of a vehicle's front location or a mech's legs that depends on how many MP you spent past the unit's safe limit in standard gravity. Since the damage purely depends on how much MP was expended, this could be shortcut by a quick check at the beginning of pathfinding for a given unit, prohibiting or highly discouraging any paths requiring enough MP to allow instant location destruction from a failure.

Both could have further refinements added, but they seem like a good start.

JonhyBurner commented 10 months ago

To add to @gsparks3 comment, the low gravity logic should be applied to high gravity as well, since the bot's behaviour is similar and PSRs abound in that situation too.

Maybe tornadoes/storms should be added to the possible common PSR cases? I see Princess falling victim there a lot as well, but that might be a result of the weather penalties and less of the bot parameters.

Thom293 commented 10 months ago

I have tested that slider, and I could not tell if it did anything at all. I also changed the number to 999 and something super low and tested it again and still could not notice a difference. I'd guess whatever weight it is is infinitesimal or it's broken. Or I don't understand it (which is possible).

On the toggle, it would be suboptimal. But it would be better than nothing. Given that it would be option there is absolutely zero harm in it, if there are no better solutions. But if someone is going to recode it then the other suggestions here would be better.

Just stopgap suggestion: you could give princess a hidden "SPA" that gives her +2 to piloting skill checks for the first 3 turns, or when unseen, or out of range of enemy weapons, etc, etc. Not perfect but would help some and fall off when engaged. Something like that.

SuperStucco commented 10 months ago

One point to add about the Pilot Caution setting: it appears to modify movement behavior at night. When moved to the right (more caution) Mechs jump less often, and sometimes not at all; units with low MP tend to stay in one hex. When pushed to the left (higher risk) they jump more frequently if possible, and will try to move even with lower MPs, but also do so with a much higher risk of skidding where present.

The jumping is weird. It may be an artefact of the unofficial option to make PSRs when jumping into woods. Otherwise it shouldn't come into play.

Another point for consideration in PSR checking is jumping with prototype jump jets, which require a PSR when landing. This comes up when units like the primitive Wolverine get selected as part of convoy forces in MekHQ.

Thom293 commented 10 months ago

One point to add about the Pilot Caution setting: it appears to modify movement behavior at night. When moved to the right (more caution) Mechs jump less often, and sometimes not at all; units with low MP tend to stay in one hex. When pushed to the left (higher risk) they jump more frequently if possible, and will try to move even with lower MPs, but also do so with a much higher risk of skidding where present.

The jumping is weird. It may be an artefact of the unofficial option to make PSRs when jumping into woods. Otherwise it shouldn't come into play.

Another point for consideration in PSR checking is jumping with prototype jump jets, which require a PSR when landing. This comes up when units like the primitive Wolverine get selected as part of convoy forces in MekHQ.

Well if that is true it would be great if you could tuen the night behavior into the full time. I wonder what is different about night that makes it work? Is it based on distance/mp instead of an actual PSR check?

Thom293 commented 9 months ago

I wanted to Add: Ice. She avoids it not at all. I just fought a full contract on an ice planet with most of the maps having ice. The vast majoritey of the battles princess dunked 1/3-1/2 of her force. You could likterally just stay at extreme range and she would kill most of her force.

I know people dont like the toggle idea. It is a poor solution. But it is a temporary solution. Just a setting to "stay off the ice" and "dont run on high/low G gravity" and "Dont enter water above depth 1" would improve huge sections of gameplay. It might make her "worse" because she has some movement limitations. But a worse princess is better than a dead princess. I would rather fight a mech with worse AI than not fight because she killed all of her mechs. IMHO.

Thom293 commented 8 months ago

Just FYI all: I was looking for something else and started messing with this and got into a fit of testing. ran many tests - approximately 20. 3x1 spaceport map. lots of pavement, but wide streets. I did tests with normal gravity and 0.5. Setting her to "never take a risk" will prevent vehicles and mechs (I did not test VTOL) from making PSR manuvers when approaching combat. Like she wont do them at all. Zero times before she was in shooting range of the enemy. Once combat is engaged - she will do PSR to get TMM just like the other side. When I tested before it was on a condensed map and I didnt notice the difference between combat/non-combat.

So, at least for the time being, I think all Princess vehicles should have that setting all the way to the right, and that will at least prevent her from killing herself before battle.

If there is some other situation where she kills herself, Ill happily test it, if anyone has any ideas.

Thom293 commented 8 months ago

Was half asleep when I typed this and let the conclusion unstated. So I shall state my opinion:

Because it only changed her pre-combat movement, maxxing it to the right did not change her combat performance in any appreciable way that I could see. She still won an equal amount of games. So, in my opinion, ALL vehicle lances should be set to "Never Take a Risk" in every game where it could matter, unless they are set to auto-flee. She will still perform fine once combat is joined.

This does not address all of Simon's issues, and those still need addressing, but this is a partial workaround for some of those situations.

Here is a combat log of Cool (Never take a Risk) vs. Crazy (Highway Menace) on 0.5g for those that care to see. You can see that Cool's first movement PSR is the first turn it joins combat.

gamelog.zip

Thom293 commented 8 months ago

So, looking at it some more - with Ice - any anything that functions similarly to it - the first "trouble" check isnt a PSR, so I dont think her PSR caution setting will trigger it at all. Its just "you break through the Ice on a Roll of X" which isnt a PSR. It then causes some PSRs but they are automatic. I would guess its the same with swamp - if you jump into swamp you are Auto-Stuck. No PSR involved. Here is an ice screenshot, this is on "never takes a risk" setting for the Cool team.
image

So, here is what I found in the BasicPathRanker (I assume this is correct part of code but maybe wrong). Noteably, in the list of hazards, Swamp and Quicksand is not listed. I did try to change the numbers under IceHazard to something arbitrarily large, but that didnt work. I probably just dont know what needs changing though. This is beyond me:

image

SimonLandmine commented 8 months ago

Thanks for all of your research on this! I guess it's possible that the implementation of Swamp and Quicksand post-dates the BasicPathRanker coding. As you say, ice breakthrough and 'stuck' rolls aren't quite the same as PSRs, although they are terrain hazards of a sort, so Swamp and Quicksand should probably have weightings (like Ice) when it comes to path ranking. The discovery that 'maximum driving caution' means Princess will at least not wreck the vees on the approach to battle (but will then manoeuvre to avoid fire) is really useful. Ta!

Thom293 commented 8 months ago

So, Eureka mabye? I think this fixes Ice. https://github.com/MegaMek/megamek/pull/5037

If it does, we can add Swamp, Quicksand, Mud, etc - whatever else and give it a similar treatment and hopefully that will solve most of her hazard pathfinding issues. @SimonLandmine since you are a map expert, what other hexes does she have trouble with? As far as I can tell, the only current terrain hazards shes "sees" are Fire, Magma, Lava, Ice, Water, Building, Bridge. Im sure there are more, but I wouldnt know where to find a comprehensive list.

SimonLandmine commented 8 months ago

I'll have a think as to other terrain types. I guess that it would be any from TacOps that might trigger PSRs (or have negative consequences). Sounds like a good plan adding Swamp, Quicksand, and Mud to the pathfinding lookup.

SuperStucco commented 8 months ago

Don't forget to test with visibility conditions e.g. various grades of darkness, heavy/light fog,. Also weather conditions that similarly cause mud and other additional movement reductions like cold and F4+ tornado winds. When Princess is set to be careful with piloting checks and has reduced MPs it will sit and spin in the same hex rather than try to go anywhere. It won't even use the minimum movement rule.

Thom293 commented 7 months ago

After thinking about this more, given the behavior I noted with the PSR slider, since it doesnt seem to influence her at all during combat, and she will still take whatever PSRs she deems necessary, perhaps it would be worth changing her default behavior to 10, so she doesnt nuke herself before combat? I think its worth testing at least. What say yall?

Also, She seems to jump mechs into water for no reason too. A separate issue, but needs to be addressed also. image

image

SimonLandmine commented 7 months ago

Seems reasonable, and worth testing, especially as Princess still takes PSRs when necessary on a '10'. If I get around to playing a game at any time in the near future, I'll try that. As for the 'jumping into water' issue, I saw that a couple of versions ago, when a Phoenix Hawk disappeared from the battle for no apparent reason (jump, splash, breach, goodbye), but it did seem a bit odd. Maybe it's an attempt to get the cooling bonus? Or just a desire for high cover?