Combat Odds

xienwolf

Deity
Joined
Oct 4, 2007
Messages
10,589
Location
Location! Location!
Well, I've got a bit of a "Secret Project" which I am working on for a mod-mod which I am certain quite a few of the other Mods will decide to use, and I am hoping that the main mod will incorporate. For now, I'll only say 2 things about it: 1) It's fun, 2) The AI doesn't understand it so well.


In light of #2, I am pausing the project and working on the AI for a bit of it. Unfortunately before I touch too much of the AI directly dealing with what I am creating, I need to polish up the current. First step is Combat Odds, and I am seeking input.

The following is the list of what I am thinking for the initial setup. Let me know if anything else affects how you think about Combat (makes you more/less willing to take risks).



Any time that the AI is facing potential Combat, I want to have it call a function to get the unit in the Stack which it is most willing to lose, according to the following formula (The AI will at the end attack using the lowest Acceptable Risk Rate):

AIgetMinCombatOdds said:
  • -Combat Odds
    • If the unit is pretty likely to die, I don't want to attack with it
  • -300 + (50 * Duration)
    • If Duration > 0 (Summoned Unit -->Probably Always first choice, at any odds)[*]If possible, will also have a hook to catch Permanent Summons (maybe also Planar Gate Summons) and assign them a -100 (more likely than "real" units, but still expendable)
  • +100
    • If Duration From Combat > 0
  • -75
    • If Immortal
  • + iTier * 5
    • The Tier of a unit is how early it comes in the Tech Tree. Thus if you have a Warrior (Tier 1) and an Axeman (Tier 2), you'd be a bit more willing to risk the Warrior
  • +20
    • If any of the Potential Upgrades for the Unit has a Minimum Level Requirement (primarily Adepts & Priests)
  • +20
    • If the Unit is a World Limited Unit (Hero)
  • +10
    • If the Unit is Carrying Equipment
  • -Withdrawal Chance / 2
    • If the Unit might survive even through Defeat
  • -Net Number of First Strikes * 2
    • Might already be a part of calculating the Combat Odds, if so, won't use it
  • -10
    • If the Unit will Abandon me on Change of Civic/Religion (since the AI is pretty likely going to do one or the other eventually)
  • -1 per Unit owned
    • If the AI has a stack of 20 Scouts, then each one is pretty much not that important
  • -2 * Number of Targets allowed with Collateral Damage, + Collateral Damage Limit / 5, + Collateral Strength / 10
    • This makes the Computer more willing to attack early with a Unit that can do lots of Collateral Damage to weaken the stack

I haven't figured out precisely how yet, but I also intend to have this effect what level of risk the AI is willing to take with the Combat Odds, in addition to the order in which the units will attack. The ideal will be to cap it so that the AI is willing ot risk almost any unit at 95% win chance, standard units around 75% chance, and summons at absolutely any chances. So most likely I will just run the numbers for a variety of units and come up with a normalizing function which will balance out to around that point. Anytime that a Unit has a 98% Chance to win, it will be checked against other units with the same odds and the one with the highest XP will make the attack, regardless of the list for Minimum Risk
 
You should probably make it take the actual duration into account, not just whether duration is limited or not. A unit with duration of 3 is slightly more valueble than one with a duration of 1.

Units that gain duration from combat should also be more aggressive.

Immortal units should be extremely aggressive.
 
But wont it disrupt the AIs current attack algorithm?

Currently the AI can suicide a stack on a city to get it if it is sure to win and still have few defenders. Happened to me few times. If you call this function then the AI can start suiciding and then in the middle your algorithm can 'throw it off balance' and change its mind. You would have to do much tweaking and adjusting.

Next issue is that Kael is working on the AI now so your project may very soon be obsolete.
 
-Net Number of First Strikes * 2

* Might already be a part of calculating the Combat Odds, if so, won't use it
Pretty sure it already is.

Being a World Unit could be better as an adjustment to this (or even simply bypassing it and treating it like Kael has in the main mod I guess) - not sure how you were planning on coding it up.
Regarding summons, ones which gain benefit from surviving should probably go after suicidal collateral units and other summons - either ones with a unitcombat and duration > 1 or ones whose duration is extended by victory. So a Host of the Einherjar should often wait for the enemy to be a bit weakened on both those counts. That said, if the odds are already good, I'd RATHER attack with that sort of unit than a throwaway one, since I'd be throwing away experience otherwise.
 
Added some more fields to account for Duration from Combat and Durations over 1.

[NWO]_Valis;6881272 said:
But wont it disrupt the AIs current attack algorithm?

No, this will initially be designed to leave the AI doing as it normally does with deciding to attack, but change the order in which it decides to do so. Once the order is refined, then work will be done with shifting how/when it is willing to take larger risks. But the ideal is that it still makes the same decisions on the macro- scale, but not on the micro.

[NWO]_Valis;6881272 said:
Currently the AI can suicide a stack on a city to get it if it is sure to win and still have few defenders. Happened to me few times. If you call this function then the AI can start suiciding and then in the middle your algorithm can 'throw it off balance' and change its mind. You would have to do much tweaking and adjusting.

It would still be capable of that this way. The adjustment for how many units it has is a pretty small one, so won't cause it to break off an attack midway through a stack. Especially since it will be facing weaker defenders by that point and thus have better odds.

[NWO]_Valis;6881272 said:
Next issue is that Kael is working on the AI now so your project may very soon be obsolete.

Yes, Kael is working on the AI, but that doesn't mean we cannot assist in the matter. AI is a huge and complex beast. I have no doubt that his work will alter some aspects of mine eventually, but right now he is looking at the over-arching strategy, and I am fiddling with the individual tactics.
 
Hmmm. A few suggestions.

Make it NEVER attack when it has less than a .8% chance of winning. Doing significant damage is very unlikely in situations below that.

Heroes should probably never attack less than 80-90%... Just weighing them will get them killed rather fast.

Ive noticed units with more first strikes tend to do quite a bit more damage in suicide attacks, even if they have no real chance of winning... Prehaps give this some consideration.

Otherwise... Very good concept. Hope you find a good way to impliment it for the AI. I would love to see orthus with a stack, weaken a city first, and THEN attack it himself. And I don't even know how many times Ive had an adpet attack me and then its skeleton just sit there staring blankly...
 
And I don't even know how many times Ive had an adpet attack me and then its skeleton just sit there staring blankly...

careful with this one: summons like skeletons, tigers and (from Yvian) treeants are permanent, but should still be considered expendable. May be tough to implement as a function though, so rather make seperate ratings for these few units?

If possible, make the AI check the higher exp units in a stack first, and check their combat odds. If above X% (say, 80+), attack, otherwise let other units in the stack attack first, then check their odds again.
 
Hadn't been thinking in terms of feeding your likely victories for XP. I'll try to write a "Attack of Opportunity" hook in there so that if any unit has 98% or better it jumps to the front of the line for attacking.

Non-Temporary Summons I might be able to code in. The game is tracking the number that you own and the number of units who are allowed to summon them, so I should be able to utilize the same mechanism to flag them as temporary units. At present I am not sure if I can do so in an elegant manner though, and this whole thing needs to be very elegant since it will be called a LOT (especially if the Attacks of Opportunity itteration is added).

EDIT: I suppose one way I can assist in making this a bit more elegant is to make the "Risk" of a unit be an attribute stored on the unit itself. Then the act of summoning something will place a large "Risk Pool" on the unit to reflect the expendable nature. This would keep me from having to loop over the units to discover if they are summoned or not, and I could have the Risk Pool already contain the modifiers for a few other looping functions, like having Min Level Requirements on your Upgrades.
 
I hope you can consider choosing defenders too. I would like it if there were a point at which the computer won't choose to defend with my best unit, even if it has the highest chance of winning. You'd probably know better than I, but I'm thinking if a unit is above a certain level, then it won't defend if its chance is below a certain point, as long as there are more defenders than attackers. That's not counter-intuitive is it?
 
I hadn't given thought to changing how defenders are selected, but I do agree that it is an area in which some serious work is needed as well. I'd love for my units that are going to disappear at the start of the next turn anyway to be the primary defenders. Or ones who will prevent Collateral if I am at risk of taking some (not sure how that works as yet though)
 
Back
Top Bottom