Making the AI faster

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
Nyanyanyan
Posts: 53
Joined: May 11th, 2018, 10:40 pm

Making the AI faster

Post by Nyanyanyan »

Playing very big multiplayer maps with a lot of units will make even the Default AI go excruciatingly slow, so I was wondering if it was possible to make the AI go faster in any way, even at the cost of worse performance, strategically.
I am not very experienced in AI WML, so I have no idea if this is possible or how I could archive it.

Any help is appreciated.
Author of Age of Lords and the Revolution and Civil War and Expendable Leaders 2 multiplayer mods.
User avatar
Helmet
Posts: 138
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Making the AI faster

Post by Helmet »

I recently posted an AI question to the forum, so I've been reading about AI behavior. I can't answer your question with a code example, but I do know that the answer to your question is yes, the AI can go faster.

From the Wesnoth Wiki:
https://wiki.wesnoth.org/Micro_AIs (ai_type=fast_ai)
(Version 1.13.0 and later only)

This AI is meant as a fall-back AI for scenarios where there are so many units that attacks and moves done by the default AI are slow with long delays before each move.
Follow the link and check it out. I think you need to use a "micro ai."
User avatar
Nyanyanyan
Posts: 53
Joined: May 11th, 2018, 10:40 pm

Re: Making the AI faster

Post by Nyanyanyan »

I tried applying the fast_ai micro ai to every side in an AI vs AI game but they're still incredibly slow on big maps.

Here's my code.

Code: Select all

[modification]
    id=Fast AI Enabler
    name=_"Fast AI Enabler"
    description=_"Enables the Fast Micro AI for MP matches, making the AI play worse but faster (who would have guessed?)."
    require_modification=yes	
[event]
id=fast_ai_enabler
name=prestart
first_time_only=no
        [store_side]
            [filter]
            [/filter]
            variable=fast_ai_enabler_variable
        [/store_side]
        {FOREACH fast_ai_enabler_variable i}
		[micro_ai]
			side=$fast_ai_enabler_variable.side
			ai_type=fast_ai
			action=add
			leader_attack_max_units=6
		[/micro_ai]
        {NEXT i}
        {CLEAR_VARIABLE fast_ai_enabler_variable}
[/event]
[/modification]
Did I do something wrong?
Author of Age of Lords and the Revolution and Civil War and Expendable Leaders 2 multiplayer mods.
User avatar
Hejnewar
Posts: 132
Joined: September 17th, 2016, 11:01 am

Re: Making the AI faster

Post by Hejnewar »

Do you use "Accelerated speed" in preferences? It can speed up animations and save you lots of time.
User avatar
Pentarctagon
Project Manager
Posts: 4536
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Making the AI faster

Post by Pentarctagon »

There's also the Skip AI Moves preference if the issue is the time the movements/animations are taking.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Nyanyanyan
Posts: 53
Joined: May 11th, 2018, 10:40 pm

Re: Making the AI faster

Post by Nyanyanyan »

No, those aren't the issue. It's the actual time the AI takes to make decision.
Author of Age of Lords and the Revolution and Civil War and Expendable Leaders 2 multiplayer mods.
Shiki
Developer
Posts: 309
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Making the AI faster

Post by Shiki »

[store_side] expects a side filter, without using a [filter_side] tag - so, just what one put's usually into a [filte_side] tag, but in a [store_side] tag. Btw, [filter] is always a unit filter.
The [filter] tag is not a valid tag inside a side filter. I'm not sure what the engine does in this case, but maybe it lead to your side filter evaluating to false, and thus the micro ai not being applied. If you don't specify anything for filtering, your code will match all sides. Try your code without these two lines again. (and maybe use [foreach] instead of {FOREACH})

When you use the :inspect command, you can also see information about an sides AI. Most micro ais will add a new Candidate Action into the list shown under "stages" - with this micro AI one I'm not sure.

There's also another way to speed up the AI. The normal AI has a paramter simple_targeting.
You can also check with inspect if it was applied correctly.
Try out the dark board theme.
User avatar
Nyanyanyan
Posts: 53
Joined: May 11th, 2018, 10:40 pm

Re: Making the AI faster

Post by Nyanyanyan »

Shiki wrote: October 15th, 2020, 4:44 pm [store_side] expects a side filter, without using a [filter_side] tag - so, just what one put's usually into a [filte_side] tag, but in a [store_side] tag. Btw, [filter] is always a unit filter.
The [filter] tag is not a valid tag inside a side filter. I'm not sure what the engine does in this case, but maybe it lead to your side filter evaluating to false, and thus the micro ai not being applied. If you don't specify anything for filtering, your code will match all sides. Try your code without these two lines again. (and maybe use [foreach] instead of {FOREACH})

When you use the :inspect command, you can also see information about an sides AI. Most micro ais will add a new Candidate Action into the list shown under "stages" - with this micro AI one I'm not sure.

There's also another way to speed up the AI. The normal AI has a paramter simple_targeting.
You can also check with inspect if it was applied correctly.
I did that, but it didn't make the game any faster and sadly I couldn't see anything in the inspection windows that would show me that fast ai is enabled.

I tried simplifying the code even more to prevent any mistakes but I'm not sure if it works now. At least the map still isn't playable.

Code: Select all

[modification]
    id=Fast AI Enabler
    name=_"Fast AI Enabler"
    description=_"Enables the Fast Micro AI for MP matches, making the AI play worse but faster (who would have guessed?)."
    require_modification=yes	
[event]
id=fast_ai_enabler
name=side turn 1
first_time_only=no
		[micro_ai]
			side=$side_number
			ai_type=fast_ai
			action=add
		[/micro_ai]
		[print]
		text="Fast AI Enabled"
		size=300
		duration=3000
		[/print]
[/event]
[/modification]
Author of Age of Lords and the Revolution and Civil War and Expendable Leaders 2 multiplayer mods.
mattsc
Developer
Posts: 1171
Joined: October 13th, 2010, 6:14 pm
Location: Hidden on the hex behind Fred

Re: Making the AI faster

Post by mattsc »

If the Fast MAI is enabled, you should see the following in the AI Component Structure inspect dialog for the side (scroll down to the bottom). Note the three candidate actions starting with "mai_fast_".
Attachments
fast_mai.jpg
Post Reply