[AI] my first attempt at altering goals

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
white_haired_uncle
Posts: 1226
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

[AI] my first attempt at altering goals

Post by white_haired_uncle »

I'm looking at ai for the first time, and I'm a bit overwhelmed. The wiki seems like more of a reference than a guide, describing some interesting pieces, but not how to put them together.

I have a scenario which I think will provide a good example to get me started, as I have the same basic need for many others. You (player) start in the SW. Two enemy leaders are in the NE, recruiting tons of drakes. If you move your army toward the center of the map to use the river it's a glorious bloody battle, which is exactly what I want.

The problem is that your leaders are pretty much invincible and can move one hex after attack. So the easy solution is just leave your army safe out of range while the leaders carve their way through the mass of drakes and kill the enemy leaders. Almost every drake will stand around in a huge pack surrounding your leaders. Boring, and virtually no risk to your army.

So I want to tell the enemy "put more focus on attacking canrecruit=no". But not, "completely ignore the human leaders, allowing them to assassination our leaders). Seems "simple" enough, two goals (or aspects??): attack canrecruit=no / protect leader. I can see how to do each, but I don't know how to express that both are important, but I want you to emphasize one more than you do by default.

In this case, there are two enemy sides. I could just give them different goals, but I won't learn anything from that.

If, for some reason I can't give two goals (I think I can, are these facets?), I'm considering candidate_actions so some drake types focus on X, while others focus on Y. I actually want to understand this anyway as I have other uses for it (e.g. units with arcane attacks focus/avoid enemies with active_ability=X -- where X is an ability the ai doesn't understand).

Help?

TIA
Speak softly, and carry Doombringer.
white_haired_uncle
Posts: 1226
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [AI] my first attempt at altering goals

Post by white_haired_uncle »

Hmm, I can't even get this to work. It shows up in :inspect, but the AI heads in the opposite direction (towards my heroes).

Code: Select all

[ai]
    [goal]
        name=target_location
        id=git
        [criteria]
            x,y=13,11
        [/criteria]
        value=20
    [/goal]
[/ai]
Looking into the logging for clues, I think I see that it has accepted what I've provided:

Code: Select all

Setting mode to 1920x1011
20240401 02:57:11 info ai/config: loaded AI config: Default AI (RCA)
20240401 02:57:11 info ai/config: loaded AI config: Old Default AI (1.14 version)
20240401 02:57:11 info ai/config: loaded AI config: Experimental AI
20240401 02:57:11 info ai/config: loaded AI config: Dev AI: Idle AI
20240401 02:57:11 info ai/config: loaded AI config: Dev AI: Default AI (RCA) with Alternate Recruiting
Checking lua scripts... ok

20240401 02:57:30 debug ai/config: side 2: config contains:
[ai]
        [goal]
                id = git
                name = target_location
                value = 20
                [criteria]
                        x = 13
                        y = 11
                [/criteria]
        [/goal]
[/ai]

20240401 02:57:30 debug ai/config: side 2: applying default configuration
20240401 02:57:30 info ai/config: side 2: expanding simplified aspects into full facets
20240401 02:57:30 info ai/config: side 2: doing final operations on AI config
20240401 02:57:30 info ai/config: side 2: merging AI configurations
A short while later, a unit moves (away from target, towards my leaders):

Code: Select all

# the only enemy on this side (2) that can move this turn:

20240401 03:05:56 debug ai/stage/rca: Evaluating candidate action: candidate action with name [ai_default_rca::goto_phase]
20240401 03:05:56 debug ai/stage/rca: Evaluated candidate action to score 0 : candidate action with name [ai_default_rca::goto_phase]
20240401 03:05:56 debug ai/stage/rca: Evaluating candidate action: candidate action with name [default_recruitment::recruitment]
20240401 03:05:56 debug ai/stage/rca: Evaluated candidate action to score 0 : candidate action with name [default_recruitment::recruitment]
20240401 03:05:56 debug ai/stage/rca: Evaluating candidate action: candidate action with name [ai_default_rca::move_leader_to_goals_phase]
20240401 03:05:56 info ai/ca/testing_ai_default: ai_default_rca::move_leader_to_goals_phaseEmpty or Nonexistent goal found
20240401 03:05:56 debug ai/stage/rca: Evaluated candidate action to score 0 : candidate action with name [ai_default_rca::move_leader_to_goals_phase]
20240401 03:05:56 debug ai/stage/rca: Evaluating candidate action: candidate action with name [ai_default_rca::move_leader_to_keep_phase]
20240401 03:05:56 debug ai/stage/rca: Evaluated candidate action to score 0 : candidate action with name [ai_default_rca::move_leader_to_keep_phase]
20240401 03:05:56 debug ai/stage/rca: Evaluating candidate action: candidate action with name [mai_fast_combat]
20240401 03:05:56 debug ai/stage/rca: Evaluated candidate action to score 0 : candidate action with name [mai_fast_combat]
20240401 03:05:56 debug ai/stage/rca: Evaluating candidate action: candidate action with name [ai_default_rca::get_healing_phase]
20240401 03:05:56 debug ai/stage/rca: Evaluated candidate action to score 0 : candidate action with name [ai_default_rca::get_healing_phase]
20240401 03:05:56 debug ai/stage/rca: Evaluating candidate action: candidate action with name [mai_fast_move]
20240401 03:05:56 debug ai/stage/rca: Evaluated candidate action to score 20000 : candidate action with name [mai_fast_move]
20240401 03:05:56 debug ai/stage/rca: Ending candidate action evaluation loop because current score 20000 is greater than the upper bound of score for remaining candidate actions 19900
20240401 03:05:56 debug ai/stage/rca: Executing best candidate action: candidate action with name [mai_fast_move]
20240401 03:05:56 info ai/actions:  check_before partial move by side 2 from location 19,14 to location 35,3

20240401 03:05:56 info ai/actions:  check_before full move by side 2 from location 19,14 to location 35,3

20240401 03:05:56 info ai/actions: start of execution of: full move by side 2 from location 19,14 to location 35,3
I assume by these messages that this unit made it to 'Move to targets CA' and didn't get distracted by combat, etc, like the wiki warns about, and that it chose a move target different than the one I gave it. I have no idea why, or where to look to find out. And I don't know what this "mai_fast_move" is that it seems to have preferred to my goal (or perhaps my goal is a part of mai_fast_move, but wasn't chosen, or ...?).
Speak softly, and carry Doombringer.
white_haired_uncle
Posts: 1226
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [AI] my first attempt at altering goals

Post by white_haired_uncle »

Well, according to https://wiki.wesnoth.org/RCA_AI#The_Can ... the_RCA_AI move_to_targets should be the CA with score 20,000. But in :inspect/side2/ai/stages for 20,000 I see name=mai_fast_combat where I would expect (and that's not saying much) to see name=ai_default_rca:move_to_targets based on the wiki and what I see for other stages.

Okay, instead of modifying an existing scenario, let's make the simplest singleton possible. Now in :inspect I see 20000 as ai_default_rca:move_to_targets and in the console log

Code: Select all

20240402 13:01:15 debug ai/stage/rca: Evaluated candidate action to score 20000 : candidate action with name [ai_default_rca::move_to_targets_phase]
20240402 13:01:15 debug ai/stage/rca: Ending candidate action evaluation loop because current score 20000 is greater than the upper bound of score for remaining candidate actions 10000
20240402 13:01:15 debug ai/stage/rca: Executing best candidate action: candidate action with name [ai_default_rca::move_to_targets_phase]
20240402 13:01:15 debug ai/stage/rca: Disabling candidate action because it failed to change the game state: candidate action with name [ai_default_rca::move_to_targets_phase]
I guess that's a clue?

Hmm, I think I made it too simple. The AI has only a leader. No keep, so I don't understand why he's not moving, but I gave him a peon and it actually followed my orders!

And so, hours of wasted effort later... Someone set ai_type=fast_ai in a global configuration that is read into every scenario from another file.
Speak softly, and carry Doombringer.
User avatar
Celtic_Minstrel
Developer
Posts: 2241
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [AI] my first attempt at altering goals

Post by Celtic_Minstrel »

white_haired_uncle wrote: March 31st, 2024, 2:24 pm So I want to tell the enemy "put more focus on attacking canrecruit=no". But not, "completely ignore the human leaders, allowing them to assassination our leaders). Seems "simple" enough, two goals (or aspects??): attack canrecruit=no / protect leader. I can see how to do each, but I don't know how to express that both are important, but I want you to emphasize one more than you do by default.
Goals don't affect who the AI attacks. They only control where the AI will move. This is probably still fine, as once they've moved towards the targeed units, there's a high chance that they'll choose those units to attack, but just keep that in mind.

If you want the AI to de-emphasize the leader, there is an easier way than goals, although this still only affects movement; in fact it's used to influence special internal goals automatically created by the engine. You can set leader_value to a lower value (the default is 3, meaning leaders are 3 times as valuable as regular units).
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Spannerbag
Posts: 538
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: [AI] my first attempt at altering goals

Post by Spannerbag »

white_haired_uncle wrote: April 2nd, 2024, 4:47 pm ...
Hmm, I think I made it too simple. The AI has only a leader. No keep, so I don't understand why he's not moving, but I gave him a peon and it actually followed my orders!...
Hmm, as you're giving the ai drakes who can fly this probably won't help much.
However I sometimes find that changing the map to make some routes more or less inviting can, with trial and error (mostly the latter in my case!), help in persuading the ai to behave in the way you want it to.
That said, I've also seen the ai make what seem to me to be... odd target choices (but then I haven't dug into the whys and wherefores which probably explains why I'm such a lousy player...).

This is probably too clunky and extreme to work as you want but you could embed a [filter] inside [avoid] so that all drakes avoid the leaders?
If you specify, say, radius=1 (Edit: or a larger radius if 1 isn't enough...) then the leaders should be able to move->attack nearby drakes but many will, presumably, be out of range.
This in conjuction with the other measures mentioned by people cleverer than me might get close to what you want?

You could even justify it in-game by having some random drake (probably a leader) say something along the lines of:
"Cull the weakest first and isolate their leaders! Once their army is gone we will overwhelm these two fools!", depending on how much moustache twirling you want in your dialogue. :)

Just a thought.

Cheers!
-- Spannerbag
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