AI behaviour query

The place to post your WML questions and answers.

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.
Post Reply
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

AI behaviour query

Post by Spannerbag »

Hi,
Apologies if this isn't the right forum to post an ai-related query...

I'm slowly creeping towards finishing my campaign, but I have a query regarding some frustrating ai behaviour whilst testing/balancing the last playable scenario. This scenario spawns random enemy units. At this stage of testing they are all assigned to (enemy) side 2. This works fine.

Here's the thing: some of these units appear on the map a good distance from the player's units (at least at this stage in testing).
At first they move off and look for something to kill but later on they just sit there (they are created with moves=0 and on a turn refresh).
To try and force them to move I added an ai [goal] but they still get stuck in stasis.

Is this a known behaviour with the ai? If so, does anyone know if there is a workaround?
I'd rather not use a micro ai (e.g. fast ai) as I need to use [avoid] and I don't think the micro ais honour these? (Please correct me if I'm wrong).
Unfortunately, prior posts have confirmed that it's not feasible to post savegame+scenario.cfg+map as there are loads of custom units, traits etc. plus this final scenario is fairly chunky (just over 7500 lines though there are quite a few comments and whitespace lines in that!).

If anyone does have any suggestions I'd be very grateful!

Thanks in advance!
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI behaviour query

Post by mattsc »

Hi,

This does not sound like "standard" AI behavior, but like something else is going on. Unfortunately, without you posting a test case it is essentially impossible to tell what that might be, but I'll make two mostly random guesses anyway:

1. Do you maybe have first_time_only=no in the event that sets moves to zero? I assume not because the units move initially, but mentioning it anyway.

2. You say that you use [avoid] tags. The AI sometimes has problems with those, depending on how they are set up. The AI does not move units around zones to be avoided when considering moving units toward a goal. It finds a path for a unit and if the move-to hex lies in the zone to be avoided, the move is discarded. This is due to the way how path finding works in Wesnoth and as far as I know, there's no simple way around that. (If I remember correctly, there's even an issue posted about this on Wesnoth' github page.) So if that's what's happening in your case then yes, that is a known issue. [avoid] tags have to be used with great care.

As for your other question, some Micro AIs do take [avoid] tags into account. This is listed in the "optional keys" sections of the individual Micro AIs on the wiki. The Fast MAI happens to be one of those that does respect the default AI [avoid] tag as you can see here.
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: AI behaviour query

Post by Spannerbag »

Hi mattsc,

Thanks as ever for taking the trouble to reply, much appreciated!
mattsc wrote: September 23rd, 2019, 3:59 pm This does not sound like "standard" AI behavior...

1. Do you maybe have first_time_only=no in the event that sets moves to zero? I assume not because the units move initially, but mentioning it anyway.
Yep, your assumption is correct; the events all have first_time_only=no.

mattsc wrote: September 23rd, 2019, 3:59 pm 2. You say that you use [avoid] tags. The AI sometimes has problems with those...
Yup, I use a few avoids :doh:

I kinda thought it was something to do with path finding because it didn't happen straight away but rather in the early teens (turn 13, 14 etc.).
Once it happened, all subsequent spawned units at that location were also affected. The scenario begins with a high unit count and by these turns the map is probably even busier - but not hugely so. I suspect that by this stage the engine (or maybe my probably under powered laptop!) is creaking under the weight of multiple possible pathways and each unit's pathway blocks another? I dunno...

I did try a few things but wasn't able to remove this behaviour.

mattsc wrote: September 23rd, 2019, 3:59 pm As for your other question, some Micro AIs do take [avoid] tags into account. This is listed in the "optional keys" sections of the individual Micro AIs on the wiki. The Fast MAI happens to be one of those that does respect the default AI [avoid] tag as you can see here.
Thanks, that's very useful - I might see how much quicker gameplay is with the fast ai. It might also not have this issue?
Would the fast ai also honour [modify_ai]? The avoids are deleted and (some) re-instated during the scenario.

Had I encountered this issue earlier I might've spent more time on it but I've been stuck on this last scenario for *ages* (months!) ...and it still needs a bit more design/code/test :augh:
So... for now, I reverted back to dialogue+income (not as good/obvious as spawning - but it works).
If I ever get the damn thing finished, I might re-visit this then...

Again, thanks for your comments.

Cheers!
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: AI behaviour query

Post by Celtic_Minstrel »

Spannerbag wrote: September 23rd, 2019, 10:08 pm Would the fast ai also honour [modify_ai]? The avoids are deleted and (some) re-instated during the scenario.
If you're using [modify_ai] to delete or add [avoid] rules, then any AI algorithms that honour [avoid] rules should automatically use the currently-active ones.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI behaviour query

Post by mattsc »

Hi Spannerbag, just a couple more quick things:
Spannerbag wrote: September 23rd, 2019, 10:08 pm I kinda thought it was something to do with path finding because it didn't happen straight away but rather in the early teens (turn 13, 14 etc.).
Once it happened, all subsequent spawned units at that location were also affected. The scenario begins with a high unit count and by these turns the map is probably even busier - but not hugely so. I suspect that by this stage the engine (or maybe my probably under powered laptop!) is creaking under the weight of multiple possible pathways and each unit's pathway blocks another? I dunno...

I did try a few things but wasn't able to remove this behaviour.
One quick test would be to remove all [avoid] tags. If that changes the behavior, you know it's the avoids, if not, it's somewhere else. That won't tell you what to do about it, but it will narrow down the potential causes of the problem.
Spannerbag wrote: September 23rd, 2019, 10:08 pm Thanks, that's very useful - I might see how much quicker gameplay is with the fast ai. It might also not have this issue?
The Fast MAI deals with avoided regions somewhat differently than the default AI, but there could still be problems depending on the exact setup. So it might or might not work better for you. Avoided regions are difficult to deal with in a one-size-fits-all manner.
Spannerbag wrote: September 23rd, 2019, 10:08 pm So... for now, I reverted back to dialogue+income (not as good/obvious as spawning - but it works).
If I ever get the damn thing finished, I might re-visit this then...
When you have the first version of your add-on published, you could then share scenario saves without having to worry about missing content. I or somebody else could then more easily help you trying to figure this out. Good luck with finishing your campaign!
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: AI behaviour query

Post by Spannerbag »

Celtic_Minstrel wrote: September 24th, 2019, 12:28 pm
Spannerbag wrote: September 23rd, 2019, 10:08 pm Would the fast ai also honour [modify_ai]? The avoids are deleted and (some) re-instated during the scenario.
If you're using [modify_ai] to delete or add [avoid] rules, then any AI algorithms that honour [avoid] rules should automatically use the currently-active ones.
Thanks for the clarification, appreciated :)
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Spannerbag
Posts: 535
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: AI behaviour query

Post by Spannerbag »

mattsc wrote: September 24th, 2019, 6:59 pm Hi Spannerbag, just a couple more quick things:

...

One quick test would be to remove all [avoid] tags. If that changes the behavior, you know it's the avoids, if not, it's somewhere else. That won't tell you what to do about it, but it will narrow down the potential causes of the problem.
IIRC I did something similar awhile ago (I've spent so long on this I'm getting consufed...) and I seem to recall that it did fix the issue... however, me being me, I couldn't leave it alone, so I re-visited the [avoids] and realised one was derived from a location filter macro and was overkill. I changed that and it seems to have stopped the original issue with units never moving :D
So I have spawned units and it works well. Thanks for your help, much appreciated as ever.

However... I also made other changes and there's now a very long pause at the end of the ai turn. The screen scrolling freezes and the wait cursor comes up. However I think I know why this happens: the last side with visible units is side 8 and I think side 9 is doing something (this is a slightly oddball side as it's units are all guardians and it's allied to two opposing enemy sides to get the behaviour I want). I suspect there's some processing of that side going on... When I get to (re)testing that segment of the scenario I'll have to see if this lag then goes away.

So, fingers crossed, I think I'm good :)

mattsc wrote: September 24th, 2019, 6:59 pm Good luck with finishing your campaign!
Thanks, I'll let you know when it finally goes live... if I live that long :roll:

Cheers!
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.17, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Post Reply