AI behaviour query
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.
- Spannerbag
- Posts: 535
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
AI behaviour query
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
To try and force them to move I added an ai
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
If anyone does have any suggestions I'd be very grateful!
Thanks in advance!
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!
Re: AI behaviour query
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
2. You say that you use
As for your other question, some Micro AIs do take
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.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
- Spannerbag
- Posts: 535
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: AI behaviour query
Hi mattsc,
Thanks as ever for taking the trouble to reply, much appreciated!
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.
Would the fast ai also honour
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
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!
Thanks as ever for taking the trouble to reply, much appreciated!
Yep, your assumption is correct; the events all have
first_time_only=no
.Yup, I use a few avoids
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.
Thanks, that's very useful - I might see how much quicker gameplay is with the fast ai. It might also not have this issue?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.
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
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!
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: AI behaviour query
If you're usingSpannerbag 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.
[modify_ai]
to delete or add [avoid]
rules, then any AI algorithms that honour [avoid]
rules should automatically use the currently-active ones.Re: AI behaviour query
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.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.
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 Thanks, that's very useful - I might see how much quicker gameplay is with the fast ai. It might also not have this issue?
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!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...
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
- Spannerbag
- Posts: 535
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: AI behaviour query
Thanks for the clarification, appreciatedCeltic_Minstrel wrote: ↑September 24th, 2019, 12:28 pmIf you're usingSpannerbag 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.[modify_ai]
to delete or add[avoid]
rules, then any AI algorithms that honour[avoid]
rules should automatically use the currently-active ones.
- Spannerbag
- Posts: 535
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: AI behaviour query
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 themattsc 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.
[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 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
Thanks, I'll let you know when it finally goes live... if I live that long
Cheers!