Improving the defensive capabilities of the AI

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderators: Forum Moderators, Developers

Forum rules
Before posting a new idea, you must read the following:
Post Reply
gooby
Posts: 154
Joined: August 8th, 2012, 6:47 am

Improving the defensive capabilities of the AI

Post by gooby » November 10th, 2013, 12:04 am

Forgive me if this has been suggested already; I haven't found anything to this effect. Forgive me also if this idea is intractable in the existing framework.

I've noticed that the AI excels at (often brazen) offenses. In particular, it appears skilled at picking off units that have been weakened to the breaking point, as well as the subgoal of bringing them to that breaking point. I am sometimes surprised by the weaknesses the AI finds on my part in this way. What seems absent is the ability to mount a coherent defense. Defense requires recognizing focal points like a fortress wall, the edge of a mountain range, the banks of a river, what have you. It also requires recognizing how far you have to spread to prevent being flanked. I imagine that's something that's not easy to formalize. However, I have a cheap solution to this problem: identifying sets of tiles in the scenario map that constitute "defense zones". A very simple example would be the set of all the castle tiles that make the boundaries of a fortress. The desired behavior would then be some combination of inhabiting those tiles, retiring for healing and/or curing if the situation becomes too dangerous—then returning—and attacking opponents adjacent to the tiles in question if suitably weak, or simply holding one's ground in the event of a relatively strong opponent or opponents in the vicinity.

It is entirely conceivable that a map could have more than one defense zone. The behavior will then have to be elaborated in some way, for instance, one side could be designated for each defense zone, or a unit could simply be attracted to the nearest defense zone available. A further elaboration I can imagine is time: if turns are in short supply, it would make sense to adopt a relatively aggressive defensive stance. In addition to that, if a distant leader needs to be defeated, a suitable heuristic recognizing that the enemy's offense on the defense has broken could be applied, perhaps based on the ratio of one's units, weighted by their strength, to the enemy's, similarly weighted. As soon as the back of the offense were broken, maintenance of the protection of the defense zone would then be abandoned and behavior reverted to the default offensive stance.

User avatar
Crow_T
Posts: 851
Joined: February 24th, 2011, 4:20 am

Re: Improving the defensive capabilities of the AI

Post by Crow_T » November 10th, 2013, 12:40 am

I mentioned something similar a while back:
http://forums.wesnoth.org/viewtopic.php ... 05#p543521
Mattsc's response http://forums.wesnoth.org/viewtopic.php ... 05#p543578
But I think once the microAIs start getting some use the situation will be improved.

gooby
Posts: 154
Joined: August 8th, 2012, 6:47 am

Re: Improving the defensive capabilities of the AI

Post by gooby » November 10th, 2013, 12:56 am

Crow_T wrote:I mentioned something similar a while back:
http://forums.wesnoth.org/viewtopic.php ... 05#p543521
Mattsc's response http://forums.wesnoth.org/viewtopic.php ... 05#p543578
But I think once the microAIs start getting some use the situation will be improved.
Your idea is also interesting. I like it.

mattsc
Posts: 1121
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Improving the defensive capabilities of the AI

Post by mattsc » November 10th, 2013, 2:53 am

Hi gooby, thanks for the suggestions. Let me start by saying that I have no background in these things whatsoever (I don't even have a coding/programming background), so take everything I am saying for what it's worth (that is, not a lot).

What you write makes a lot of sense and over the last couple years I have tried to get defensive positioning working in a number of different ways. As you suspect, it's not that simple esp. in a general setting and while the principles of what should be done are often quite clear, doing it in practice is quite a bit more complicated. But here are some of the things I have tried that you could check out and let me know if you have comments.

Bottleneck Defense Micro AI: This one very strictly predefines the area of the map to defend, just as you suggest (I think). It works best with narrow bottlenecks but can, in principle, also be used for castles, mountain edges, river banks, etc. You can check it out by starting the Micro AI test scenario from the commandline

Code: Select all

wesnoth -t micro_ai_test
(replacing 'wesnoth' with whatever your Wesnoth executable is) and then choosing the Bottleneck Defense test scenario.

This one is in mainline, the next two require that you download the AI-demos add-on if you want to check them out. Get the version from the AI-demos github site though, not that on the add-ons server as the latter is quite out of date.

Prune Cart scenario: Start the AI-demos add-on and choose this scenario, then choose "watch the two AIs fight it out" and "stationary cart". It's one of my earlier attempts in defensive positioning along a mountain edge. Note that I stopped working on it in an unfinished state as I decided that the method used in it is too restrictive. So it's certainly not perfect, but I think you can see where I was trying to go with this.

Freelands Grunt Rush MP AI, a.k.a. Fred: Go to the "MP Rushes" scenario in AI-demos, which explains how to use Fred. Then let him play a game or two on Freelands against the RCA AI. Defensive positioning is just one part of Fred's behavior, but it is meant to be an important part. Note though that I just made a pretty significant change to how that works and things are pretty badly unbalanced and messed up at the moment, resulting in a lot of bad moves. You might want to give it a couple weeks and then come back to it, I am actively working on it.

So that's what I have tried so far. Those AIs pretty much do what you are suggesting, I think, in different ways and to varying degrees. And except for the Bottleneck MAI, all of this is still very much work in progress, so comments are always much appreciated.

Hope this addresses what you were posting. If I missed your point(s), just hit me over the head and tell me again. :)

gooby
Posts: 154
Joined: August 8th, 2012, 6:47 am

Re: Improving the defensive capabilities of the AI

Post by gooby » November 11th, 2013, 2:10 am

I'm just glad something like that is underway. Crow's idea was especially interesting as it reminds me of certain ideas in behavior-based robotics.

Post Reply