How does the AI know when to retreat?

Discussion of all aspects of the game engine, including development of new and existing features.

Moderators: Forum Moderators, Developers

Post Reply
User avatar
Bob_The_Mighty
Posts: 782
Joined: July 13th, 2006, 1:15 pm

How does the AI know when to retreat?

Post by Bob_The_Mighty » November 29th, 2014, 1:18 pm

I'm interested to know how the AI handles units that are either severely wounded or poisoned. I'm sometimes surprised to see them go and heal, maybe because they didn't use to do it so much. What's the weighting for this behaviour? And am I right in thinking that poison doesn't factor in the ai's choice of which attack to use or which target to go for?

I'd like suggestions on how to handle a custom status that works a bit like poison. I've been toying with a status that makes units set on fire, which deals damage every turn, but currently they fight on regardless of the flames engulfing them.

It might be possible to force an ignited/poisoned unit back to a village, but sometimes this might not always be wise (especially if the nearest village is miles away, or there is an important kill they could make).

Perhaps an endangered unit could be set to a micro ai like coward, but again the benefits of fighting or fleeing are situational.

Any ideas?
My current projects:
2p Campaign: The Altaz Mariners
3p Survival: Save The Village

User avatar
Wintermute
Inactive Developer
Posts: 840
Joined: March 23rd, 2006, 10:28 pm
Location: On IRC as "happygrue" at: #wesnoth-mp

Re: How does the AI know when to retreat?

Post by Wintermute » November 30th, 2014, 2:08 am

I haven't used them yet but have you experimented with mattsc's work on Micro AI? He would be a good person to ask in any case, and is often on IRC in #wesnoth-dev.
"I just started playing this game a few days ago, and I already see some balance issues."

mattsc
Posts: 1103
Joined: October 13th, 2010, 6:14 pm
Location: Wandering, mostly aimlessly

Re: How does the AI know when to retreat?

Post by mattsc » November 30th, 2014, 4:04 pm

Hi Bob. The decision for a unit to retreat to a village is made in the healing candidate action. If you're interested in the exact details, the code is here. Roughly speaking: if a non-regenerating unit is poisoned or has lost 4 or more HP, it looks for the least exposed village to retreat to and goes there if that location is not too exposed.

This is a very simple algorithm, but as you write yourself, it is very difficult to come up with something more complex that makes sense under all circumstances. I have been struggling with that for a long time and have not found a good solution yet (not in the Micro AIs, but in the MP AI I am working on). Thus, there really isn't a good option currently available that would take those exceptions you mention into account (and certainly none of the MAIs do it). Having said that, if you can come up with a specific rule-set that is simple enough that it can be put into code, I'd be happy to try writing a custom AI that uses that for you test out. I'd be interested in having something like that too. Be aware though that the emphasis is on it having to be simple, it quickly gets almost unmanageable otherwise.

If you have not tried it out yet, you might also want to have a look at the Freelands MP AI in the AI-demos add-on (the AI we call 'Fred') which attempts to make some of the sorts of decisions you mention. It's still very much unfinished and makes all kinds of bad mistakes (so I am not endorsing it as a complete AI), but you might see some things you like or don't like in there. Any feedback would be much appreciated (although I currently don't have time to work on it) and if you see bits that you think would be useful for handling your custom status, we can try to pull them out of that code.

As for poison not being taken into account in choosing which unit to attack, I believe that is true.

Post Reply