Putting Leader self-preservation into the AI

General feedback and discussion of the game.

Moderators: Forum Moderators, Developers

F50
Posts: 48
Joined: April 22nd, 2008, 9:59 pm

Re: Putting Leader self-preservation into the AI

Post by F50 » May 12th, 2008, 9:28 pm

the idea may be fuzzy for you and me, but it need not be. I have lost more than a few games from failing to protect my units correctly. Brute force shouldn't be an issue since the AI usually doesn't control more than 1 such unit (per AI team).

the safety % should be decided by the WML, as you want to be able to change this depending on whether you want your leader to be more brave/cowardly, so agreeing on a % is hardly important.

Qes
Posts: 357
Joined: August 9th, 2007, 10:28 pm
Location: Minnesota

Re:

Post by Qes » May 15th, 2008, 12:28 pm

Dave wrote:
DDR wrote:if HP < 30% then
run away
end if
This wouldn't do very well at all. There are many situations where the leader is in grave danger and has much higher than 30%.

Also by the time it's down to 30% it's likely the player has already trapped it between ZoCs.

Finally where does it run to? If it just goes to some nearby village then it'll likely still get hunted down there and killed....if it runs as far as possible, then it'll be difficult for it to heal and get into a situation where it can recruit again...

David

These are excellent salient points. And I dont think a large complex system of "if-then" statements would solve the issue, so much as bog down the AI.

I think the AI is good - not great. It IS much better than most other games, but I do think it can always be improved.
I think it's a true statement, that trying to ascertain our thought-processes involving risk management could make for a superior AI, but we want to keep away from strict if-thens.

Somewhere on the forums it was discussed about the change in statistics given for EV's for games. Specifically the useful notation of gold gained and lost, as well as xp gained and lossed.

I'm wondering if it wouldn't be possible to introduce gold and xp into the equations for statistics as desired in those other threads AND make use of them in the AI.

If the AI could be taught that Gold and XP were the penultimate resources to value and protect, then units could each be assigned various values based on gold and experience.

If hp/max hp becomes a fraction of the total cost of a specific unit, then every unit has it's value exacted at any given moment. An injured unit will have "less gold value" than a healthy one, however, a lost unit has 0 gold, which could be turned into an absolute of sorts that the AI could be told to avoid. Add in XP (total, not merely currant) and you might see the AI starting to value higher level creatures more than lower levels.

In this, through XP the AI could be taught to use low levels as expendible means to protect higher levels, and through the calculation of current vs max gold value for each creature - whether or not to 'withdraw' them from danger.

"Withdrawl" and danger could be also manifest in gold and Xp values. The AI could calculate the enemies value, in gold and xp, and in what "Range" of its own units. In this, it could identify that a more expensive unit is in close proximity (i.e. striking distance) to one of his own less expensive units. And, unless there is a MORE expensive unit the AI needs to protect for even more weighted reasons, it would move it out of the range of the attacking units. Unless within a certain range, it's own total gold value in all it's units was superior to that of the enemy - it might go on the attack to remove the threat instead of retreating. Gold-values could be used, referred to, and manipulated to fit a wide variety of circumstances that the AI could quickly assess and execute actions at a higher level of difficulty against the player.

Those other threads were talking of using gold value in combat statistics - combat statistics that could be used to assess threat, the combat calculator itself could be used by the AI (invisibly of course) to identify near threats and opportunities, and if instructed, to attack or retreat accordingly.

If healing and poison were given their appropriate values in gold-influence over the course of a game, then the AI might start to use healing units more effectively - keeping them away from enemies (as their value's could be multiplicative), and retreating wounded units to the healing units. Healing units would then also become more "valuable" targets to the AI.

This was a long way in saying that - if the AI were to understand gold-value and xp-value, which came to some total value of each and every individual unit, I wonder if it wouldnt be possible to minimize "if-thens" but still give a procedural impetus to AI actions that would make it a lot more lethal and a lot less suicidal.

-Qes

EDIT: This could also mean that the AI would be correctly taught that the loss of a village might be more economically viable than the loss of a unit protecting that village, since village gold per turn could be translated into an 'unit-gold value' for any given turn.

EDIT2: Also, if a given unit has it's probability of survival (via combat statistics) generally reduced to (or close to) 0 regardless of what actions it might, or other units might take in a given turn, the AI could be taught how to maximise it's value for as long as possible. For example, if it can kill something, it might try that, if the odds are against that - it might put it somewhere where it would require the most amount of units to attack it to kill it. And if nothing else, to simply sit and force units to attack it (rather than freeing up an action on the enemies turn).
Yes I use windows.
Yes I'm aware of what that means.
Yes I'm still gonna use windows.

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Putting Leader self-preservation into the AI

Post by zookeeper » May 15th, 2008, 1:44 pm

Perhaps a pretty good solution, provided that it's not terribly difficult to do, would be to make the AI leader by default always choose a move resulting in the least immediate danger to itself (immediate meaning the time until its next turn). So, the AI leader could attack enemy units if it'd be statistically impossible for it to subsequently get killed on the enemies' turn (assuming that none of its other units which might be screening the leader would die?). Of course it'd still be possible for the AI leader to then charge the enemies in a situation where it could not die in one turn, but would likely be dropped to low HP and trapped. The aggression and caution settings for the AI are all fine and good in campaign play, but IMO it'd be good if leaders still had a bit of "extra caution" like that.

Maybe the same idea could simply be refined a bit: never move to a location or attack if you'd risk losing >50% of current HP on the following turn? Never move to a location where you can be pinned down from two sides unless you can't move to a location where you couldn't be pinned down? And always choose the action which results in the lowest immediate CTBK if it's impossible to avoid a CTBK?

F50
Posts: 48
Joined: April 22nd, 2008, 9:59 pm

Re: Putting Leader self-preservation into the AI

Post by F50 » May 16th, 2008, 1:36 am

zookeeper wrote:And always choose the action which results in the lowest immediate CTBK if it's impossible to avoid a CTBK?
bad. bad idea. you often have 4.5% CTBK, and its still a good move.

Sangel
Moderator Emeritus
Posts: 2232
Joined: March 26th, 2004, 10:58 pm
Location: New York, New York

Re: Putting Leader self-preservation into the AI

Post by Sangel » May 16th, 2008, 9:29 pm

How about dividing expected damage by CTBK, or somesuch? If the result isn't suitably enticing, no attack is made. But this still doesn't teach our AI leader how to judge when the odds are hopeless, and where to run to if they are.

Damn. AI is hard.
"Pure logic is the ruin of the spirit." - Antoine de Saint-Exupéry

CarpeGuitarrem
Posts: 250
Joined: November 19th, 2007, 7:46 pm
Location: One among the Fence

Re: Putting Leader self-preservation into the AI

Post by CarpeGuitarrem » May 18th, 2008, 4:17 am

Sangel wrote: Damn. AI is hard.
That's because machines evaluate. They don't conceptualize.
Glory in Blood...Needs Programming Help!

If you have time, check out my ongoing serial story...
The Hidden: Secrets of the Future's Past

Jozrael
Posts: 1034
Joined: June 2nd, 2006, 1:39 pm
Location: NJ, USA.

Re: Putting Leader self-preservation into the AI

Post by Jozrael » May 20th, 2008, 2:39 pm

Yet

atly
Posts: 3
Joined: May 1st, 2008, 7:27 pm
Location: France
Contact:

Re: Putting Leader self-preservation into the AI

Post by atly » May 21st, 2008, 10:24 am

What does this have to do with conceptualizing?

Anyway, there should be ways to make the AI better, all of them requiring the AI to be able to understand the battle from a more general view, which AI lacks currently.

We could artificially create a line of defense defined by map terrain or units (which involves generally positive terrains like trees or mounts, regardless of the specific units, which wouldn't have enough relevance, excepted maybe dwarves) ; regarding general faction alignment you can then make AI be able to move back or forth from that line, and push further away if the added strength of his units is superior to that of enemy units in sight. That'd allow leader self-preservation (eg. behind the line and where ctbk is weak) and a more precise setting of AI agressiveness (along with general more efficiency).
Also, not taking in account more specific details at first allows general improvement, especially against another AI. Approximations have minor relevance regarding that fact.

Of course, I do not mean to modelize it on the fly: bruteforced analyzes of every hex in reach would be too much of a work for not enough interesting uses, on top of being extremely slow. A more doable option would be to set up, for a given map, some informations such as general battle orientation and strategic lines (as for example, on most 2p maps the middle consists of plain, which players have to cross to attack the opponent, or stall on adjacent good terrain hexes).
Battle orientation would allow the AI to spread units on a line orthogonal to that direction (and additionally to retreat or advance in a circular shape, the radius of curvature being the initial keep on classically disposed maps) and the strategic lines not to put oneself in too much danger.

Howewer, this has its limitations and more refined analysis would be too complex. But it is clear that you cannot implement strategy in AI behavior as long as you only focus on units separately, and any more general modelization would be more relevant (it would also be possible to refine it over time, once the basis is there).

In short, what I suggest, not only for leader preservation but for the AI in general, would be a simple geometric-based battle placement - that's just the general idea. The current implementation, as far as I can see by reading the AIwml page, could be pretty well adapted to follow those kinds of guidelines.

Post Reply