Comparison of different AIs

General feedback and discussion of the game.

Moderator: Forum Moderators

Post Reply
sacredceltic
Posts: 55
Joined: October 20th, 2013, 4:07 pm

Comparison of different AIs

Post by sacredceltic »

Hi,

I can't find a documentation explaining the different strategies implemented in the different AIs available for Wesnoth. Could somebody point me to ressources on that topic ?
Also, are there other alternative AIs that can be added to Wesnoth ? Where can I find their description ?

Thank you
benjam
Posts: 11
Joined: August 1st, 2015, 5:53 pm

Re: Comparison of different AIs

Post by benjam »

...
Last edited by benjam on November 22nd, 2015, 10:18 pm, edited 2 times in total.
User avatar
Xara
Posts: 270
Joined: December 26th, 2014, 12:23 am
Location: Beijing

Re: Comparison of different AIs

Post by Xara »

In /data/ai/ais/ai_default_rca_strong.cfg, it writes:

Code: Select all

#textdomain wesnoth-ai
{core/macros}
[ai]
    id=ai_default_rca_strong
    description=_"Multiplayer_AI^Strong AI (RCA)" # wmllint: no spellcheck
    # RCA := Register Candidate Action; more info at http://forums.wesnoth.org/viewtopic.php?p=419625#p419625
    version=10710
    [stage]
        id=main_loop
        name=ai_default_rca::candidate_action_evaluation_loop
        {AI_CA_GOTO}
        {AI_CA_RECRUITMENT}
        {AI_CA_MOVE_LEADER_TO_GOALS}
        {AI_CA_MOVE_LEADER_TO_KEEP}
        {AI_CA_COMBAT}
        {AI_CA_HEALING}
        {AI_CA_VILLAGES}
        {AI_CA_RETREAT}
        {AI_CA_MOVE_TO_TARGETS}
        {AI_CA_LEADER_SHARES_KEEP}
    [/stage]

    ### Aspects for a strong AI ###

    {AI_SIMPLE_ALWAYS_ASPECT recruitment_diversity 0.8}
    {AI_SIMPLE_ALWAYS_ASPECT recruitment_randomness 0}
    {AI_SIMPLE_ALWAYS_ASPECT villages_per_scout 0}
    {AI_ASPECT recruitment_save_gold {AI_DEACTIVATE_SAVE_GOLD} }
[/ai]
The only difference between a normal AI and a strong AI is:

Code: Select all

    ### Aspects for a strong AI ###

    {AI_SIMPLE_ALWAYS_ASPECT recruitment_diversity 0.8}
    {AI_SIMPLE_ALWAYS_ASPECT recruitment_randomness 0}
    {AI_SIMPLE_ALWAYS_ASPECT villages_per_scout 0}
    {AI_ASPECT recruitment_save_gold {AI_DEACTIVATE_SAVE_GOLD} }
So the only difference is a better recruitment.
It pronounces Sha'ha, not Zara.

Feedback Thread of my Add-ons
mattsc
Inactive Developer
Posts: 1217
Joined: October 13th, 2010, 6:14 pm

Re: Comparison of different AIs

Post by mattsc »

benjam seems to have forgotten to put in the link, but I assume it's this thread and that I am one of the persons mentioned.

There are descriptions and links to the main Wesnoth AIs in the first few sections of the AiWML wiki page. That, and the links therein, is pretty much all that exists, as far as I know. There are a few other AIs that are available in mainline, but they are all either very minor variations on the same theme, or they were experiments that served a very specific purpose and/or never got finished and might not even work any more.
Xara wrote:Seems that's no obvious difference.
Yes, the so-called "strong AI" is one of those very minor variations (just slightly different recruiting parameters) from the default. It is clearly named incorrectly (for example, the Experimental AI, even just its recruiting, is way stronger than this one) and should, in my opinion, be removed entirely or at the very least be renamed.


Edit: I forgot to address this:
sacredceltic wrote:Also, are there other alternative AIs that can be added to Wesnoth ? Where can I find their description ?
If you mean as a scenario designer, you can use the Micro AIs mentioned on the AiWMl wiki page for that. For MP game AIs, those mentioned in the thread above are the only semi-complete MP AIs that I am aware of. If you don't want to go through a 400+ post thread, you can find a more recent update on one of them here.
sacredceltic
Posts: 55
Joined: October 20th, 2013, 4:07 pm

Re: Comparison of different AIs

Post by sacredceltic »

Thank you for your replies. I am surprised that the answers point to mainly technical programming of these AIs. I expected to read about the principles (ie the analysis) prevailing upon the programming and justifying or explaining the principles that have been retained.
My view is these AIs are pretty weak (I'm not a very good player, but I nevertheless ALWAYS win against any of the 3 AIs and I find it frustrating...), and I suppose these weaknesses lie in the strategic principles on which these AIs are based, rather than bugs in their programming. I have no doubt the people who designed them are brillant programmers, but are they brilliant strategists ? It seems, considering the lack of ressources, that these strategic principles are kept like "secrets", although they have little strategic value. I suggest these principles should be discussed, in order to improve them.
sacredceltic
Posts: 55
Joined: October 20th, 2013, 4:07 pm

Re: Comparison of different AIs

Post by sacredceltic »

For instance, how is "recruitment diversity" stronger than "recruitment non-diversity" ? If all your map is aquatic, what you definitely need are aquatic creatures, better suited to that terrain. I can't see how recruitment diversity is a universal advantage. It has to be suited to the conditions (terrain, type of enemies and even time of the day, if the enemy is close to the keep...)
benjam
Posts: 11
Joined: August 1st, 2015, 5:53 pm

Re: Comparison of different AIs

Post by benjam »

There are more than the 3 default AIs (default, strong, experimental). Install the AI add-on from the add-ons server and play against the one named Fred. Feel free to compare its strength to the others :)
Gotten intrigued by your initial post and its following responses, I have digged a little in the forum. It is quite interesting what one can find, see http://forums.wesnoth.org/viewtopic.php?f=10&t=37878
User avatar
Alarantalara
Art Contributor
Posts: 786
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Comparison of different AIs

Post by Alarantalara »

sacredceltic wrote: My view is these AIs are pretty weak (I'm not a very good player, but I nevertheless ALWAYS win against any of the 3 AIs and I find it frustrating...), and I suppose these weaknesses lie in the strategic principles on which these AIs are based, rather than bugs in their programming. I have no doubt the people who designed them are brillant programmers, but are they brilliant strategists ? It seems, considering the lack of ressources, that these strategic principles are kept like "secrets", although they have little strategic value. I suggest these principles should be discussed, in order to improve them.
Fundamentally all three AIs that come with the game share a lot of similarities.
The only differences between default and strong are recruiting, with a slightly different set of parameters passed into the same algorithm. As I recall, the recruiting algorithm itself is designed primarily around being customizable by scenario developers to create interesting battles, with a set of parameters intended to create a fun experience by providing an assortment of enemies to fight against. When the default and strong AIs fight each other, the slightly different choice of units gives the strong AI a slight advantage, thus its title of strong.

The experimental AI is somewhat different.
It has a completely different recruiting algorithm that was designed to emulate the choices of a good human player, where good was, "met the approval of ladder players with a rating > 2000 (Rigor, nelson)", especially in the first few turns.
As such, it tries to pick units that counter both what is on the battlefield and that the opponent could recruit. As it gains more units relative to the enemy, it picks harder hitting units, even at a cost of fragility to break through enemy lines.

Unlike the other recruitment algorithm, it also chooses where the units are recruited in order to maximize the number of villages that can be captured and if it knows the leader will be moving to a "better" keep, it will under-recruit at the first keep to project more forward power, recruiting just enough to capture all villages. This change alone gives it a 100% win rate against both the other AIs on Arcanclave Citadel.

It also adjusts its recruitment based on map size, favouring faster units on larger maps, trusting that the economy advantage from capturing more villages will more than offset the price.

It knows about poison and avoids recruiting units that depend on it for damage if the enemy is immune.

It also looks at the expected cost of the unit over the next few turns, which prevents the recruitment of too many fast weak units unless the additional gold from an expected capture of a village is enough to offset the increased cost.

Time of day is taken into account and it prefers units that will reach the current closest enemy at the favoured time of day. This allows for a slight bias towards saurians during the day and drakes at night (because they'll reach the fight at the right time).

Because the AI can't use them well, it doesn't accurately measure the damage done by a unit with berserk, causing them to almost never be recruited. Sorry.

There's also a small amount of randomness to allow two units that are almost equally good according to the evaluation to be chosen evenly instead of only picking the first one every time.

There may be more ideas in the recruitment algorithm, but I haven't looked at it in awhile.

Other than recruitment, there are a few other differences in the experimental AI.
It prefers to capture villages over fighting. This weakens it somewhat in raw fighting but it tends to get enough extra gold that this is actually to its advantage vs another AI. As written, it's probably too focused on villages.

If a healer is not used to attack, it will try to heal units instead of positioning to attack later.

Units retreat to villages/healers when injured, but again there's little attempt to identify when it would be better not to in order to finish off multiple enemies in an area.

The leader will move to different keeps, providing a forward force. Sometimes this works very well, especially at the beginning of the game, but it keeps moving later, which sometimes gets it killed. It might be worth stopping this behaviour after turn 3-4 or trying to identify the best keep rather than picking a close one that's not the current one as a way to improve it.

There's also an explicit poison attack routine that tries to poison unpoisoned units instead of repeatedly poisoning the same one.

Other than those changes, it too is the same, with the same attack and advance algorithms after the modifications above.

Edit:
Many of the extreme biases in the experimental AI come from the fact that it still uses a lot of the default AI code and thus can't ask it what the default action would be and compare possible moves. It has to decide whether the alternative is better without knowing the default choice.

Fred, the algorithm that mattsc is working on, uses the same recruitment code as the experimental AI, but replaces the rest of the AI entirely. It thus represents a truly different approach to how attacking, movement and choosing between them is done.

Also, take a look at data/ai/lua/generic_recruit_engine.lua if you want to understand the ideas behind them.
For non-programmers, the lines starting with -- are comments that explain what the following instructions are intended to do. They should give a better idea of exactly what it's doing.
User avatar
Temuchin Khan
Posts: 1790
Joined: September 3rd, 2004, 6:35 pm
Location: Player 6 on the original Agaia map

Re: Comparison of different AIs

Post by Temuchin Khan »

Xara wrote:So the only difference is a better recruitment.
Sometimes it isn't even better, just different. In my experience, the "Strong" AI never drafts Legionnaires for the Lavinian Legion, but relies entirely on Bowmen and Cavalry.
sacredceltic
Posts: 55
Joined: October 20th, 2013, 4:07 pm

Re: Comparison of different AIs

Post by sacredceltic »

One strong weakness I noticed with experimental AI is the following : it doesn't defend the recruitment position within a castle, so it's easy, once the AI leader moves away from it, to fill in the gap and bar it from recruiting. It's easy, for instance, to invade an AI opponent's castle with your own leader, if you have gold, and to recruit directly from the opponent's castle.
Post Reply