AI confused by units added to its recall list

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
skeptical_troll
Posts: 500
Joined: August 31st, 2015, 11:06 pm

AI confused by units added to its recall list

Post by skeptical_troll »

I've been bugged by the following problem:
In a SP scenario I want the AI side to only have some particular units available, so I am adding them on prestart to its recall list, expecting them to be recalled by the AI leader. I thought this was pretty basic, but it's not working. I played around and found few weird things.
this is how I set the ai side:

Code: Select all

    [side]
        side=2
        controller=ai
        persistent=yes #just to have a recall list
        team_name=yunotrecall
        x,y=18,11
        recruit=Footpad,Poacher #added for testing purposes, I wanted to see if the AI at least recruits something
        type=Dark Adept
        recall_cost=20
        {GOLD 160 200 240}
    [/side]
and to add units to the recall list on prestart I do something like (originally I used an insert_tag, but I tested this as well)

Code: Select all

{REPEAT 10 (
[unit]
      side=2
      type=Spearman
      x,y=recall,recall
[/unit]
)}
What happens is:
  • the AI doesn't recruit or it only recruits/recalls scouts, in this case footpads.
  • Tweaking 'villages_per_scout' in the [ai] tag changes the number of recruits, confirming this.
  • if I decrease the recall_cost for the ai, to let's say 15 or below, it will happily start recalling.
  • I confirmed this behavior both in 1.12.6 and 1.13.8 (I don't have more recent versions on this machine), although it seems to vary with other conditions as well.
  • If I undroid the AI I can recruit/recall normally as much as I want
What am I missing? It seems to me that this is connected to how the AI decides whether to recruit or not, but why having units in the recall list would alter the behavior so much? I tried to use the AI_DEACTIVATE_SAVE_GOLD macro, but didn't have any effects.
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: AI confused by units added to its recall list

Post by beetlenaut »

skeptical_troll wrote: March 29th, 2018, 12:19 pmTweaking 'villages_per_scout' in the [ai] tag changes the number of recruits, confirming this.
You can set this to zero and use a recruitment_pattern to make sure it still recruits some scouts.
skeptical_troll wrote: March 29th, 2018, 12:19 pmif I decrease the recall_cost for the ai, to let's say 15 or below, it will happily start recalling.
Probably it's just judging the spearmen not to be worth 20 gold. Try putting some swordsman or other level-2 units on the recall list and see if that works.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
skeptical_troll
Posts: 500
Joined: August 31st, 2015, 11:06 pm

Re: AI confused by units added to its recall list

Post by skeptical_troll »

beetlenaut wrote: March 29th, 2018, 2:32 pm Probably it's just judging the spearmen not to be worth 20 gold. Try putting some swordsman or other level-2 units on the recall list and see if that works.
I wouldn't blame the AI for that, but what I can't really explain is why it doesn't recruit footpads and poachers. By adding a recall list I simply added a recruit options. And in any case, if recalling was the only possibility as in my original plan, why just sit idle?

Also, I tried what you suggested and it turned out to be even more confusing. If they are swordsmen than only one is recalled. If it's red mages, pikemen or even amazing fire dragons with upkeep=0, then again no recalls at all. :hmm: :|
I'm really clueless at this point. A workaround is to set recall_cost=5 and divide the previous initial gold by 4, but still I have no idea of what is going on.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI confused by units added to its recall list

Post by mattsc »

That does indeed sound strange. You could try to start Wesnoth with the --log-debug=ai/recruitment command-line option. This will produce a lot of debug output to stdout (or maybe stderr, I forgot since they go to the same place on my system) which might or might not contain some clues as to what is going on.

Alternatively, you could send me (post here or PM) the scenario where this is happening and I can have a look. I likely won't get to that for a few days though (and I would start with the above step).
User avatar
skeptical_troll
Posts: 500
Joined: August 31st, 2015, 11:06 pm

Re: AI confused by units added to its recall list

Post by skeptical_troll »

Alright, I attach a minimal add-on to test the behavior. In this case it does recruit if I put a lvl 2 in the recall list. I report below the output from --log-debug=ai/recruitment when I do and do not include spearman to the ai recall list. I'm not able to understand very well what's going on, but it seems that the 'score' is differently normalised if there are the units in the recall list or not.
output with recalls:
output without recalls and no problems:
Attachments
test_recruit_ai.tar.gz
(2.14 KiB) Downloaded 184 times
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI confused by units added to its recall list

Post by mattsc »

Thanks for posting this. I've been poking around the recruit/recall code a bit and there's a logic error in it. In a nutshell, the recruiting candidate action (CA) evaluates whether a recall is "worth it" after it decides that the recall is what it wants to do. If that evaluation comes out negative, it ends up doing nothing. That counts as a failed recruit and black lists (disables) the CA, meaning that no other recruiting or recalling can happen that turn.

I'll have to think about how best to fix this. In the meantime, the work-around, as you have found, is to set the recall cost to less than the gold cost of the units you want to recall. I'll figure out a fix for 1.13.14 (1.13.13 was tagged this morning, so it won't be in that).

Thanks for helping us identify this problem!
User avatar
skeptical_troll
Posts: 500
Joined: August 31st, 2015, 11:06 pm

Re: AI confused by units added to its recall list

Post by skeptical_troll »

Glad that you found out where the problem was. I'll go on with that workaround then. Thanks for looking into this!
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI confused by units added to its recall list

Post by mattsc »

After looking into this some more, there really are two issues (as already pointed out by skeptical_troll). The first is that sometimes, when the AI decides that a recall is not worth it, it also abandons recruiting for the rest of the turn. This is clearly a bug and was fixed in commits 1597a2ce and 01194139. This will be in Wesnoth 1.13.14, which is just about to be released.

The second issue is the AI not doing anything if its only possible recruit/recall action is to recall units that it does not consider worth it. That's actually a feature, rather than a bug, albeit an unfortunate one. Meaning, there are situations (scenarios) in which one would want the AI to sit on the money and wait for something to happen and others in which it should recall if that's the only thing it can do. Now, the intuitive thing for it to do would be the latter, but the former is not wrong behavior. Thus, this needs to be considered a feature rather than a bug and unfortunately we're in a feature freeze now, so this cannot be changed any more for 1.14 (esp. since there is a way to deal with this by lowering the recall cost; or alternatively one could also increase the cost for the unit).

To summarize the latter, it will have to stay as it is for the 1.14 stable series. For 1.15, we will change the default behavior so that the AI recalls in this case, with a configurable parameter to revert back to the 1.14 behavior.
User avatar
skeptical_troll
Posts: 500
Joined: August 31st, 2015, 11:06 pm

Re: AI confused by units added to its recall list

Post by skeptical_troll »

Thanks, I'm glad to know that it's fixed.

Regarding the second point: I understand why it is considered in a feature in the standard case, but shouldn't the macro {AI_DEACTIVATE_SAVE_GOLD} force the AI to recruit anyway (I don't know if it actually does so now, after the bug fixes) ? If it doesn't I'd rather consider it a bug than a feature, only in this specific case.
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: AI confused by units added to its recall list

Post by mattsc »

skeptical_troll wrote: April 17th, 2018, 2:35 pm Regarding the second point: I understand why it is considered in a feature in the standard case, but shouldn't the macro {AI_DEACTIVATE_SAVE_GOLD} force the AI to recruit anyway (I don't know if it actually does so now, after the bug fixes) ? If it doesn't I'd rather consider it a bug than a feature, only in this specific case.
Well, while that is not said specifically on the wiki, it's really set up to spend the gold on recalls/recruits after the individual recallable units were considered worth it (and the implicit assumption was that there are always units that qualify, for example by always having at least one unit type to recruit). Again, there's not really a "right" or "wrong" here, there are situations where you want one behavior, and others when you want the opposite. It's really a question of which behavior makes more sense as the default (and I agree with you that the current setting is not intuitive, but it's not wrong per se).

In case that did not come across, I consider this quite unfortunate. If we had discovered this earlier, we'd have changed the default behavior for 1.14 also. However, it is not at all unlikely there there is UMC out there that makes use of this, either knowingly or unknowingly. We simply cannot announce that we are in a feature freeze and tell people to start uploading their add-ons to the 1.14 server, and then change something that might break someone's scenario unless it is clearly and indubitably a bug. Unfortunate timing, but it is what it is; especially if there are ways to work around it.
Post Reply