Questions about some Micro AIs
Moderator: Forum Moderators
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.
Questions about some Micro AIs
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...
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 204 times
-
- TRV-The traders revoir la partie.gz
- (44.68 KiB) Downloaded 201 times
Last edited by nenau on November 11th, 2019, 8:12 am, edited 1 time in total.
My campaign : Pax Romana : The Rise of Vespasian
Re: Questions about a Micro AI: Wolves
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.
Possible other workarounds could be:
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.
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").
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.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Questions about a Micro AI: Wolves
Thank you for your answer and your suggestions
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.
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: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?
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)mattsc wrote:the only other solution I can come up with right now is to modify the MAI code itself
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.
My campaign : Pax Romana : The Rise of Vespasian
Re: Questions about a Micro AI: Wolves
You should be able to use [store_reachable_locations] withnenau 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)...
range=attack
for that.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.
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).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,
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Questions about a Micro AI: Wolves
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
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.SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Questions about a Micro AI: Wolves
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...
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...
My campaign : Pax Romana : The Rise of Vespasian
Re: Questions about a Micro AI: Wolves
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.
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.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Questions about some Micro AIs
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 ?
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 175 times
-
- TRV-The trumpets of Jericho revoir la partie.gz
- (53.32 KiB) Downloaded 169 times
My campaign : Pax Romana : The Rise of Vespasian
Re: Questions about some Micro AIs
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.
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.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Questions about some Micro AIs
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.
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.
My campaign : Pax Romana : The Rise of Vespasian
Re: Questions about some Micro AIs
Sounds good. A couple more quick comments:
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.
Using the default AI and forcing it to stay inside the zone could be done with thenenau 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.
[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.SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Questions about some Micro AIs
What I wanted to say was to use the stadard AI option to make the leader go to a destination. I usually use it when I want a leader to stay on his keep.mattsc wrote: ↑November 15th, 2019, 3:19 pm 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.
I remember that I had tried that at some point, but that didn't go so well. I think it's because when the AI has no way to the enemy leader, all the units just become passive, so when the leader enters the zone to avoid, the ai units freeze...mattsc wrote: ↑November 15th, 2019, 3:19 pm 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.
My campaign : Pax Romana : The Rise of Vespasian
Re: Questions about some Micro AIs
I have an other question, about the bottleneck MAI and the Goto MAI this time.
In the joined save, the point I want to raise happens between turn 12 and 15. The purple team wants to flee from the blue bears. 6 of them are holding the corridor with a bottleneck MAI, while all the other ones are supposed to head southwest (you'll need to remove the fog to see it). The problem is that it appears that the units with goto MAI don't move at all as the units with bottleneck are on their way...
Did I somehow miss something ?
In the joined save, the point I want to raise happens between turn 12 and 15. The purple team wants to flee from the blue bears. 6 of them are holding the corridor with a bottleneck MAI, while all the other ones are supposed to head southwest (you'll need to remove the fog to see it). The problem is that it appears that the units with goto MAI don't move at all as the units with bottleneck are on their way...
Did I somehow miss something ?
- Attachments
-
- TRV-Morituri revoir la partie.gz
- (46.66 KiB) Downloaded 195 times
-
- 11a_Gladiators.cfg
- (29.5 KiB) Downloaded 149 times
My campaign : Pax Romana : The Rise of Vespasian
Re: Questions about some Micro AIs
You missed that
[filter]
is not a valid input to the bottleneck MAI. It always uses all units of the side. So options would be to give the goto MAI a higher score (I saw the comment in the code why you did not do this, but it might still work well enough), or to split Side 4 into two sides. Or, you could make a local copy of the bottleneck MAI and add the filter to the code. That shouldn't be too hard to do either.SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
Re: Questions about some Micro AIs
When I looked at your replay, I noticed something else and I finally had time to confirm it. There's a problem with the Bottleneck MAI when units are so far "in front of" the line (i.e. in enemy territory) that they cannot get behind it in one move. The MAI just doesn't move those units at all and leaves them stranded. Apparently I had only ever tested this with units starting behind the bottleneck. That's clearly a bug and I will fix that.
SP campaigns: Galuldur's First Journey (1.12 & 1.14) & Grnk the Mighty (1.10 & 1.12)
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on
AI experiments: Micro AIs (wiki, forum thread, known/fixed bugs), Fred, AI-demos add-on