Questions about some Micro AIs

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
nenau
Posts: 108
Joined: May 12th, 2017, 5:46 pm

Questions about some Micro AIs

Post by nenau » October 7th, 2019, 6:28 pm

Hello,

I am using the Wolves MAI in one of my campaigns. This AI manages several groups of bandits (I don't use multi pack, the different bandits bands are just different sides). They're chasing traders (who use goto MAI), and the player has to protect the traders.

I join a replay and the wml.

I quite like the way everything is working AI-wise, I just have a problem with the fact that the bandits tend to attack the player too much in my opinion, resulting in the fact that the packs do split (see the first 2 or 3 turns for example). I don't want to use attack_only_prey or avoid_type as afaik it would make the bandits totally avoid the player.
Do you know if there is a way to reduce aggressivity towards a player in particular? Or any other workaround?

One Idea I had was to use attack_only_prey=yes, and then the situation requires it, switch to attack_only_prey=no. But I don't know if it's easily doable...
Attachments
08a_Traders.cfg
(15.43 KiB) Downloaded 30 times
TRV-The traders revoir la partie.gz
(44.68 KiB) Downloaded 23 times
Last edited by nenau on November 11th, 2019, 8:12 am, edited 1 time in total.

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

Re: Questions about a Micro AI: Wolves

Post by mattsc » October 7th, 2019, 8:18 pm

Hey nenau,

Thanks for the feedback. It's good to see people using the Micro AIs and making suggestions for improvements. I looked at your replay and I see what you mean.
nenau wrote:
October 7th, 2019, 6:28 pm
Do you know if there is a way to reduce aggressivity towards a player in particular?
Unfortunately, that's not possible. That's a limitation of the Wesnoth AI in general, not of this Micro AI in particular (caused by the fact that the default AI's attack candidate action is used for the "wolves").
nenau wrote:
October 7th, 2019, 6:28 pm
One Idea I had was to use attack_only_prey=yes, and then the situation requires it, switch to attack_only_prey=no. But I don't know if it's easily doable...
Changing the Micro AI in this way is definitely possible with [micro_ai]action=change, the problem is determining the condition when this should be done. Maybe something like: change behavior once any bandit of the group (or all of them) get within X hexes of the closest trader?

Possible other workarounds could be:
  • Spawn the bandits only in locations that are out of range of any of the player's units. That would make them work at a group for at least one turn.
  • Add a Goto Micro AI on top of the Wolves MAI that deactivates once the bandits get close enough to a trader. I guess that kind of negates the whole point of using the Wolves MAI in the first place.
  • Use attack_only_prey=yes and set up an additional Simple Attack MAI that attacks after the Wolves MAI is done moving units. That way the bandits would head toward the traders preferentially, but still attack any enemy units next to which they happen to end up.
  • Or you could set up [avoid] tags around player's units, or groups thereof, that you do not want attacked.
None of those are perfect, and I don't know if any of them is good enough for your purposes. If not, the only other solution I can come up with right now is to modify the MAI code itself. That's certainly possible and I can help you with it (or do it for you; don't know how much Lua you know). If so, please describe in as much detail as possible what kind of behavior you would like and I'll see what I can do.

nenau
Posts: 108
Joined: May 12th, 2017, 5:46 pm

Re: Questions about a Micro AI: Wolves

Post by nenau » October 9th, 2019, 5:44 pm

Thank you for your answer and your suggestions
mattsc wrote:Changing the Micro AI in this way is definitely possible with [micro_ai]action=change, the problem is determining the condition when this should be done. Maybe something like: change behavior once any bandit of the group (or all of them) get within X hexes of the closest trader?
I think for the short term I should try to do that. The condition could be "all the members of the pack are in range of an unit of the player and none of them is in range of a trader". That would ensure that the pack has a chance to stay grouped. Actually, I am unsure how to do that in WML (test wether an unit can move close to an other one)...
mattsc wrote:the only other solution I can come up with right now is to modify the MAI code itself
This would indeed be a way better long-term solution. Maybe this MAI could use a third option for attack_only_prey that would make the pack normally avoid non-prey units, except if it is cornered and has nothing better to do. I don't know if it's easy to do or not, but I think all the members of the pack should always do the same thing (all of them attack a non-prey or none of them does)

I have already used lua, but never for wesnoth, so it would take me some time to learn, and I don't think I will be able to code what I described soon, but if you think this idea is good for you too implement into the micro AI, I'd be glad to test it.

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

Re: Questions about a Micro AI: Wolves

Post by mattsc » October 11th, 2019, 4:39 pm

nenau wrote:
October 9th, 2019, 5:44 pm
I think for the short term I should try to do that. The condition could be "all the members of the pack are in range of an unit of the player and none of them is in range of a trader". That would ensure that the pack has a chance to stay grouped. Actually, I am unsure how to do that in WML (test wether an unit can move close to an other one)...
You should be able to use [store_reachable_locations] with range=attack for that.
nenau wrote:
October 9th, 2019, 5:44 pm
but I think all the members of the pack should always do the same thing (all of them attack a non-prey or none of them does)
I don't know about "always". The motivation for the original behavior is that these are animals that follow their instincts, rather than some sort of plan or strategy. So if a wolf comes into range of a prey, it goes for it no matter whether that splits up the pack. I did it like that intentionally (and, in fact, the scenario of Grnk which uses this MAI makes use of that). But I can agree that it would be nice if what you describe were an option.
nenau wrote:
October 9th, 2019, 5:44 pm
This would indeed be a way better long-term solution. Maybe this MAI could use a third option for attack_only_prey that would make the pack normally avoid non-prey units, except if it is cornered and has nothing better to do. I don't know if it's easy to do or not,
Doing something along those lines should be possible and probably not too hard, but I'll have to think about the details. I'll do that and get back to you (not right away though, there are other things I need to take care of first).

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

Re: Questions about a Micro AI: Wolves

Post by mattsc » October 13th, 2019, 8:41 pm

I've had a first look at this and I am not sure that the Wolves MAI is the right AI to use here. It is set up to spread the "wolves" out in a line roughly perpendicular to the direction in which the target is located, and as a result, they don't make much progress toward the target. This seems particularly bad when there are 4 units to control, and when they are trying to cross the river.

Have you tried using the MAI with attack_only_prey=yes? I played through a few turns like that while not even moving the player's units after the first turn, and I did not particularly like the behavior. I suggest you check that out and let me know what you think. If this is what you want, I'll work on some separate attack setup along the lines of what you suggested (it shouldn't be too hard; multi-pack wolves already as an attack action that does not spread out the wolves). But if not, we should probably come up with a different solution that is not using the Wolves MAI; or not only using it. I'm sure we can find something that will work for this scenario, I just don't want to spend too much effort on the Wolves AI if that is not actually working all that well.

nenau
Posts: 108
Joined: May 12th, 2017, 5:46 pm

Re: Questions about a Micro AI: Wolves

Post by nenau » October 15th, 2019, 5:11 pm

Thank you for taking time to help me with my AI issues.

I tried what you suggested. They stay grouped while moving, which is part of the behaviour I am seeking for. But when it comes to attacking, they tend to do it separately, while I would prefer them to do it all together. This behaviour indeed suits better for a scenario where the key is to lure the enemies separately.
What you said about the river reminds me that I had noticed that they tend to stack on one side of the river without really crossing it efficiently.

That being said, I don't see a better suited MAI for what I want to do...

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

Re: Questions about a Micro AI: Wolves

Post by mattsc » October 16th, 2019, 7:02 pm

Okay, if that's the moving behavior you like, that's good. I think we can also improve the efficiency of crossing the river by changing a couple of the parameters in the code. I'll see how hard it is to combine this with the attacks of the multi-pack wolves. Shouldn't be too bad, but until I try that's just a guess, so no promises. ;)
nenau wrote:
October 15th, 2019, 5:11 pm
That being said, I don't see a better suited MAI for what I want to do...
Just FYI, it doesn't have to be an existing MAI. One of the nice thing about these Lua AIs is that you can modify and combine them at will and include them directly in campaigns even if they are not part of mainline. I'll get back to you with what I find.

nenau
Posts: 108
Joined: May 12th, 2017, 5:46 pm

Re: Questions about some Micro AIs

Post by nenau » November 11th, 2019, 8:41 am

Hello, here is an other scenario using a micor AI. It is a siege scenario and I wanted the player to be forced to actually attack the enemy citadel.
For that purpose, there are static guardians (just guys with movement cost > move points) and zone guardians with filter_location_enemy 1 hex wider as filter_location. Replay and code are joined.

There are a few subtleties :
* At some point, the AI abandons the eastern shore of the river to retreat across the walls
* To prevent the guardians to jump in the river and get slaughtered, their move cost on water is 99.

I am quite satisfied because this AI combination gives a feeling that is IMHO too rare in campaigns : the need to attack a stronghold instead of simply waiting for the enemy to rush out to their death. However, there are points that could be modified :

* The 99 move cost on water hack. Could it be possible to achieve the same by a nicer way ?
* The static guardians are a waste of income once the player has opened a way through the fortification. It would be better with an AI that positions its units in front of the enemy units and inside the zone to protect. Does such an AI exist ?
Attachments
10_Jericho.cfg
(15.5 KiB) Downloaded 8 times
TRV-The trumpets of Jericho revoir la partie.gz
(53.32 KiB) Downloaded 8 times

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

Re: Questions about some Micro AIs

Post by mattsc » November 12th, 2019, 4:08 pm

nenau wrote:
November 11th, 2019, 8:41 am
* The 99 move cost on water hack. Could it be possible to achieve the same by a nicer way ?
First, in my opinion that's not all that dirty a hack but a perfectly good method for achieving this. However, if you do not want to do it that way, this can also be achieved with a very minor change to the Zone Guardian MAI. There are two parts to this AI. First, the patrolling of the zone. That uses a normal standard location filter and you could exclude water terrain in it. (And maybe you set up the zone so that it does not include water hexes in the first place, I did not check.) The second part are the attacks and there is indeed not way to exclude certain hexes in the current version. However, modifying the code so that water terrain is excluded is trivial (it's essentially a one-liner), so you could use a modified version of the MAI in your campaign, just as we did in the other scenario. Let me know if you want to do that and I'll show you how.
nenau wrote:
November 11th, 2019, 8:41 am
* The static guardians are a waste of income once the player has opened a way through the fortification. It would be better with an AI that positions its units in front of the enemy units and inside the zone to protect. Does such an AI exist ?
There is no such AI. Something like that (defensive positioning of units; or any sort of complex spatial reasoning) is difficult to do in general for an AI. I could have a look at doing some simplified version of this for this scenario, but I'd need more information from you in that case. Looking at your replay, I'd probably try something different first, though. Given that by that time the player's units are quite close to the AI leader, I'd just free the guardians and let them attack. If you wanted to control which units they attack, you could use the Simple Attack Micro AI set to attack enemies close to the AI leader first. And for the farther away guardians, you could add a Goto MAI toward the own leader that kicks in after attacks, so that the units don't go chasing villages or something (although there are other ways to accomplish that too).

Let me know if you'd like help with any of that. No matter which way you choose though, you will first need to decide on a criterion on when to let those guardians loose, and whether that applies to all of them or just a subset.

nenau
Posts: 108
Joined: May 12th, 2017, 5:46 pm

Re: Questions about some Micro AIs

Post by nenau » November 15th, 2019, 6:26 am

Hi, Thanks for the answer. I will try to implement what you suggested about the water. It will be a good exercise to start messing around with AI stuff.

About the static guardians, I will think about the idea to free them at some point. What is more, the leader could use in my opinion a leader_goto AI in order to force him to stay on his keep...

I know it is quite complex to design an AI that blocks the enemy (a quick look at the code of the AI Fred convinced me) The idea I had was an AI that behaves as the standard AI, that goes towards the enemy, but with an interdiction to leave the zone to defend. That would create a mass of AI units in front of the player's units.

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

Re: Questions about some Micro AIs

Post by mattsc » November 15th, 2019, 3:19 pm

Sounds good. A couple more quick comments:
nenau wrote:
November 15th, 2019, 6:26 am
About the static guardians, I will think about the idea to free them at some point. What is more, the leader could use in my opinion a leader_goto AI in order to force him to stay on his keep...
If you really just want him to stay on the keep, you don't need an MAI for that. You could make him passive or set moves to zero in a turn refresh event. In the former case he won't do anything, in the latter he'll still attack enemies that end up next to him.
nenau wrote:
November 15th, 2019, 6:26 am
I know it is quite complex to design an AI that blocks the enemy (a quick look at the code of the AI Fred convinced me) The idea I had was an AI that behaves as the standard AI, that goes towards the enemy, but with an interdiction to leave the zone to defend. That would create a mass of AI units in front of the player's units.
Using the default AI and forcing it to stay inside the zone could be done with the [avoid] tag. Note though that that applies to all units, you cannot selectively apply it to a subset of the units. So if that does not work, let me know and I'm sure we can figure out something else.

Post Reply