Questions about a Micro AI: Wolves

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: 106
Joined: May 12th, 2017, 5:46 pm

Questions about a Micro AI: Wolves

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 5 times
TRV-The traders revoir la partie.gz
(44.68 KiB) Downloaded 5 times

mattsc
Posts: 1117
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: 106
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: 1117
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: 1117
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: 106
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: 1117
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.

Post Reply