Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info mods forum | HOMM4: info CTG forum | HOMM5: info mods forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Library of Enlightenment > Thread: AI's skill priorities
Thread: AI's skill priorities This thread is 3 pages long: 1 2 3 · NEXT»
phoenix4ever
phoenix4ever


Legendary Hero
Heroes is love, Heroes is life
posted October 09, 2018 09:07 AM

AI's skill priorities

A human player which has played the game a couple of times knows that skills like Logistics, Offense and Earth Magic are always great skills to have, but what about AI? Does it also prioritize those skills or is it all random? It seems to me like AI always has Ballistics, (makes sense since most classes have high chance to learn the skill) but never Eagle Eye for example. What about the magic schools, does it for example like Earth better than Fire or is it all random?

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
zmudziak22
zmudziak22


Supreme Hero
Heroes 3 Fan
posted October 09, 2018 11:44 AM
Edited by zmudziak22 at 11:44, 09 Oct 2018.

i think ai pick random skills when they level up.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
bloodsucker
bloodsucker


Legendary Hero
posted October 09, 2018 12:20 PM

I agree, for all I've seen AI picks skills randomly. I've found many heroes without Wisdom and some magic heroes without any magic school. If exceptions apply to AI as I believe so, this wouldn't happen if it had any kind of priorities.
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted October 09, 2018 12:33 PM
Edited by AlexSpl at 12:34, 09 Oct 2018.

AI doesn't pick secondary skills randomly, but based on skill values, which are not just constants. I may describe the AI secondary skill choice algorithm later in this thread.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
phoenix4ever
phoenix4ever


Legendary Hero
Heroes is love, Heroes is life
posted October 09, 2018 12:40 PM

@Alex Sounds interesting, would be happy to learn about it.
What about Conflux' Magic University and other Universities?, I suspect AI don't choose skills randomly here, but I don't know exactly how it works.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted October 09, 2018 01:39 PM
Edited by AlexSpl at 13:43, 09 Oct 2018.

In short, AI evaluates all 28 secondary skills first. Then picks the right offered secondary skill if it's among (8 minus number_of_already_occupied_secondary_skill_slots) of most valued skills. Otherwise AI picks the left offered secondary skill.

What may be interesting indeed is how those values are calculated, and how AI, thus, prioritize secondary skills.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
bloodsucker
bloodsucker


Legendary Hero
posted October 09, 2018 01:44 PM
Edited by bloodsucker at 13:45, 09 Oct 2018.

Thanks, I knew this could become interesting... Please, don't forget to get in detail.

Too late.
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
bloodsucker
bloodsucker


Legendary Hero
posted October 09, 2018 01:49 PM

There is already a list of those values?
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
NimoStar
NimoStar


Responsible
Legendary Hero
Modding the Unmoddable
posted October 09, 2018 02:38 PM

I always assumed it was random too. Pretty interesting info.
____________
Never changing = never improving

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
bloodsucker
bloodsucker


Legendary Hero
posted October 09, 2018 02:45 PM
Edited by bloodsucker at 14:46, 09 Oct 2018.

AlexSpl said:
AI doesn't pick secondary skills randomly, but based on skill values, which are not just constants.


Sorry, I see you already stated values are not constants.
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted October 09, 2018 02:57 PM
Edited by AlexSpl at 15:07, 09 Oct 2018.

Quote:
There is already a list of those values?

No, they are not constants. Many secondary skill values depend on hero's army power (modified sum of AI_Values; is proportional to 1000 + Army_Power). The stronger army hero has, the higher value of secondary skill is. And some skill values depend on other factors. For example, the value of such a skill as Archery only depends on how many ranged units are in hero's army (is proportional to 500 + Ranged_Units_Power). I'll write all the formulas later.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted October 09, 2018 03:55 PM bonus applied by Maurice on 12 Oct 2018.
Edited by AlexSpl at 10:16, 12 Dec 2018.

[Updated]

0. Pathfinding
Value = [(1000 + Army_Power) * k / 4], where
k = number_of_passable_penalty_terrain_tiles / number_of_all_passable_tiles, for Basic Pathfinding;
k = number_of_passable_tiles_with_penalty_greater_than_125 / number_of_all_passable_tiles, for Advanced Pathfinding;
k = number_of_passable_tiles_with_penalty_greater_than_150 / number_of_all_passable_tiles, for Expert Pathfinding.

1. Archery
Value = [(500 + Ranged_Units_Power) * k], where
k = 16, for Basic Archery;
k = 7, for Advanced Archery;
k = 11, for Expert Archery.

2. Logistics
Value = [(1000 + Army_Power) * 1/10]

3. Scouting, 12. Necromancy, 21. Learning
Value = [(1000 + Army_Power) * 1/20]

4. Diplomacy
Value = [(1000 + Army_Power) * 1/100]

5. Navigation
Value = [(1000 + Army_Power) * k / 2], where
k = number_of_passable_water_tiles / number_of_all_passable_tiles.

6. Leadership, 9. Luck, 19. Tactics
Value = [(1000 + Army_Power) *  1/50]

7. Wisdom
Value = [the_strongest_spell_efficiency_delta(1, 1, 0, 0, 0, 0, 0) * Spell_Power * 1/2]
Note: here the first 1, as an argument, means +1 to Spell Power, and the second 1 means +1 to Spell Duration. See remarks in the end of this post.

8. Mysticism
Value = [the_strongest_spell_efficiency_delta(0, 0, 30, 0, 0, 0, 0) * 1/10]
Note: 30, as an argument, means +30 to Mana Points here. See remarks in the end of this post.

10. Ballistics
Value = [(1000 + Army_Power) * 1/8]

11. Eagle Eye
Value = [the_strongest_spell_efficiency_delta(1, 1, 0, 0, 0, 0, 0) * 1/5],
if a hero has Wisdom, otherwise 0.

13. Estates
Value = [AI_Player_Wealth_Factor * k], where
k = 725, for Basic Estates;
k = 725, for Advanced Estates;
k = 1550, for Expert Estates.
Note: see [7] in the end of this post for the formula for AI_Player_Wealth_Factor.

14. Fire Magic
Value = the_strongest_spell_efficiency_delta(0, 0, 0, 1, 0, 0, 0)

15. Air Magic
Value = the_strongest_spell_efficiency_delta(0, 0, 0, 0, 1, 0, 0)

16. Water Magic
Value = the_strongest_spell_efficiency_delta(0, 0, 0, 0, 0, 1, 0)

17. Earth Magic
Value = the_strongest_spell_efficiency_delta(0, 0, 0, 0, 0, 0, 1)

18. Scholar
Value = [the_strongest_spell_efficiency_delta(1, 1, 0, 0, 0, 0, 0) * Spell_Power * 1/5],
if a hero has Wisdom, otherwise 0;

20. Artillery
Value = 10 * Attack,
if a Ballista is equipped, otherwise 0.

22. Offense, 23. Armorer
Value = [(1000 + Army_Power) * 7/100]

24. Intelligence
Value = [the_strongest_spell_efficiency_delta(0, 0, 30, 0, 0, 0, 0) * Knowledge * 1/4]

25. Sorcery
Value = [the_strongest_spell_efficiency_delta(1, 1, 0, 0, 0, 0, 0) * Spell_Power * 1/20]

26. Resistance
Value = [(1000 + Army_Power) * 1/40]

27. First Aid
Value = 250,
if a First Aid Tent is equipped, otherwise 0.

Note: use max(1, min(Spell_Power, 99)), max(1, min(Knowledge, 99)), max(0, min(Attack, 99)) for computations.

* * *
the_strongest_spell_efficiency_delta() is quite a complex function* which operates with the AI_Values of spells. In short, it calculates the difference between:

a) the efficiency ("power") of the strongest spell, currently known to a hero,

and

b) the potential efficiency of the strongest spell with an offered secondary skill.

the_strongest_spell_efficiency_delta(1, 1, 0, 0, 0, 0, 0) = the_strongest_spell_efficiency("+1 to Spell_Power, +1 to Spell_Duration") - the_current_strongest_spell_efficiency

the_strongest_spell_efficiency_delta(0, 0, 30, 0, 0, 0, 0) = [1/3 * (the_strongest_spell_efficiency("+30 to Max_Mana_Points") - the_current_strongest_spell_efficiency)]


In general, it may be two different spells, and also the difference cannot be less than 10.


------------------------------------------------------------
* [0] AI doesn't use the following spells: Scuttle Boat, Visions, View Earth, Disguise, View Air, Quicksand, Land Mine, Force Field, Fire Wall, Sacrifice, Forgetfulness, Remove Obstacle. Their efficiencies are always 0.

The efficiencies of level 3-5 spells are 0 if Recanter's Cloak is equipped.

The efficiency of Titan's Lightning Bolt is always 1 (probably a bug).

* [1] The simplest formula for a spell efficiency is

spell_efficiency = [Army_Power * Spell_AI_Value * k],
if a hero can cast a spell at least once, otherwise 0; where

k = 0.009 + 0.001 * sqrt([Max_Mana_Points / Spell_Mana_Cost])

It works for some adventure spells such as Summon Boat, Fly, Water Walk, Dimension Door, Town Portal, and also for Earthquake.

Other fomulas might be quite cumbersome.

* [2] For such spells as Resurrection, Animate Dead, Hypnotize, Fire/Earth/Water/Air Elemental the following formula is used:

spell_efficiency = [Army_Power * Spell_AI_Value * k],
if a hero can cast a spell at least once, otherwise 0; where

k = min(3.9, ScaleFactor(min(13, [Max_Mana_Points / Spell_Mana_Cost])) * min(0.9, 10 * (Spell_Power + Effective_Magic_School_Level) / Army_Power))

ScaleFactor(N) =

N = 0: 0.00, N = 1: 0.83, N = 2: 1.53, N = 3: 2.11, N = 4: 2.59,
N = 5: 2.99, N = 6: 3.33, N = 7: 3.60, N = 8: 3.84, N = 9: 4.03,
N = 10: 4.19, N = 11: 4.33, N = 12: 4.44, N = 13: 4.53


* [3] For Magic Arrow, Ice Bolt, Lightning Bolt, Implosion, Frost Ring, Fireball, Meteor Shower:

spell_efficiency = [Army_Power * min(k1, k2)],
if a hero can cast a spell at least once, otherwise 0; where

k = 10 * (Spell_Power + Effective_Magic_School_Level) * Spell_AI_Value * Elemental_Orbs_Mod * Sorcery_Mod / Army_Power

k1 = k * ScaleFactor(min(13, [Max_Mana_Points / Spell_Mana_Cost]))


k2 =
            4.000, for k >= 4.800;
0.500 * k + 1.600, for 1.557 <= k < 4.800;
0.987 * k + 0.842, for 0.752 <= k < 1.557;
1.452 * k + 0.492, for 0.433 <= k < 0.752;
1.888 * k + 0.303, for 0.275 <= k < 0.433;
2.291 * k + 0.192, for 0.186 <= k < 0.275;
2.657 * k + 0.124, for 0.131 <= k < 0.186;
2.986 * k + 0.081, for 0.095 <= k < 0.131;
3.277 * k + 0.053, for 0.071 <= k < 0.095;
3.353 * k + 0.035, for 0.054 <= k < 0.071;
3.755 * k + 0.023, for 0.041 <= k < 0.054;
3.947 * k + 0.016, for 0.032 <= k < 0.041;
4.112 * k + 0.010, for 0.025 <= k < 0.032;
4.530 * k,         for k < 0.025.


* [4] For Chain Lightning and Inferno, the formula is the same as above, except k1 = 0.83 * k (here [Max_Mana_Points / Spell_Mana_Cost] is considered to be equal to 1).

* [5] For Death Ripple, Destroy Undead, and Armageddon:

spell_efficiency = max(0, [Resistant_Creatures_Power * min(k1, k2)] - (Army_Power - Resistant_Creatures_Power)),
if a hero can cast a spell at least once, otherwise 0; where coefficients are the same as in [3].

Resistant_Creatures_Power is the sum of [Damage_Resistance * AI_Value] of all creatures in AI's army. Damage_Resistance = 1 (100%) for creatures which are immune to a spell; Dwarves, Battle Dwarves, and Crystal Dragons have Damage_Resistance = 0.2 (20%), 0.4 (40%), and 0.2 (20%) respectively.

* [6] For all the remaining spells (most of them are buffs and debuffs) the following formula holds:

Single target spells

spell_efficiency = [Spell_AI_Value * Affected_Creatures_Power * min(7, Spell_Duration * [Max_Mana_Points / Spell_Mana_Cost]) * 1/700],
if a hero can cast a spell at least once, otherwise 0.

Max_Affected_Stacks_Number = max(1, min(Spell_Duration, [Spell_Duration * [Max_Mana_Points / Spell_Mana_Cost] * 1/7]))

Affected_Creatures_Power = sum of AI_Values of all creatures in AI's army* (which can be affected by the spell, if it's a buff; for debuffs, all creatures are considered to be potentially affected, as potential enemy's army is unknown).

* Note, that if AI's hero has more stacks than Max_Affected_Stacks_Number,
Affected_Creatures_Power = sum of AI_Values of the strongest Max_Affected_Stacks_Number stacks in AI's army.

Mass and AoE spells

The formula is the same as for the case of single target spells, except Max_Affected_Stacks_Number is always equal to Number_of_Stacks

* * *
Let's find spell_efficiency of Bless for both single target and mass version of the spell. Suppose AI hero, we are interested in, has Spell Power of 5, Knowledge of 3, Ring of the Magi, and the army of 10 Pikemen, 10 Archers, and 10 Griffins. Spell Duration is the sum of the hero's Spell Power and Ring of the Magi's bonus: Spell_Duration = 5 + 56 = 61, Max_Mana_Points = 3 * 10 = 30.

The single target case

Spell_Mana_Cost = 5
Spell_AI_Value = 10

a) Max_Affected_Stacks_Number = max(1, min(61, [61 * [30 / 5] * 1/7])) = max(1, min(61, 52)) = 52

It's way more than there are stacks in the army; also all of the hero's creatures can be affected by Bless, so Affected_Creatures_Power = 10 * 80 + 10 * 126 + 10 * 351 = 5570.

spell_efficiency = [10 * 5570 * min(7, 61 * [30 / 5]) * 1/700] = 557

b) Now let's take off Ring of the Magi, and decrease Spell Power to 2. Spell_Duration = 2 now.

Max_Affected_Stacks_Number = max(1, min(2, [2 * [30 / 5] * 1/7])) = max(1, min(2, 1)) = 1

It's less than there are stacks in the army. And that only cast goes to Griffins, as they are the strongest creatures in the army (with AI_Value = 10 * 351).

Affected_Creatures_Power = 10 * 351 = 3510

spell_efficiency = [10 * 3510 * min(7, 2 * [30 / 5]) * 1/700] = 351

The mass version case

Spell_Mana_Cost = 5
Spell_AI_Value = 11

a) spell_efficiency = [11 * 5570 * min(7, 61 * [30 / 5]) * 1/700] = 612
b) spell_efficiency = [11 * 5570 * min(7, 2 * [30 / 5]) * 1/700] = 612

* [7] The formula for AI_Player_Wealth_Factor is:

Let k = Needed_Gold / (Current_Gold + Gold_Income)

AI_Player_Wealth_Factor = Towns_Mod, if AI player has nothing to spend money on;
AI_Player_Wealth_Factor = k + (1 - k) * Towns_Mod, if AI player has enough gold to build/buy what he plans to;
AI_Player_Wealth_Factor = min(1 / Towns_Mod, k), if AI player doesn't have enough gold to build/buy what he plans to.

Towns_Mod = 0.00, if AI doesn't have any town;
Towns_Mod = 0.10, for 1 town;
Towns_Mod = 0.15, for 2 towns;
Towns_Mod = 0.20, for 3 towns;
Towns_Mod = 0.25, for 4 towns;
Towns_Mod = 0.30, for 5 towns;
Towns_Mod = 0.35, for 6 towns;
Towns_Mod = 0.40, for 7 towns;
Towns_Mod = 0.45, for 8 towns;
Towns_Mod = 0.50, for 9+ towns.

AI_Player_Wealth_Factor is recalculated every time AI spends money.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
NimoStar
NimoStar


Responsible
Legendary Hero
Modding the Unmoddable
posted October 09, 2018 04:43 PM

Interesting than diplomacy has lower value than Learning (and less army size dependent), I guess the AI is actually dumber than random
____________
Never changing = never improving

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted October 09, 2018 06:05 PM

Quote:
I guess the AI is actually dumber than random

This is how it's intended to be. Players should be satisfied No one would play the game where you cannot beat the AI. Look at chess. To beat a modern professional chess AI is quite an achivement, I'd say.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
phoenix4ever
phoenix4ever


Legendary Hero
Heroes is love, Heroes is life
posted October 09, 2018 06:40 PM

@Alex Not that I don't believe you, but where do you have those formulas from? (source?)

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted October 09, 2018 06:44 PM

Yes. You can check it yourself, for example, with LMOracle.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
phoenix4ever
phoenix4ever


Legendary Hero
Heroes is love, Heroes is life
posted October 09, 2018 06:57 PM

Okay, thanks.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted October 09, 2018 07:28 PM
Edited by AlexSpl at 20:30, 09 Oct 2018.

How to check? For example, you can play with Basic Pathfinding. The formula for Basic Pathfinding is

Value = [(1000 + Army_Power) * k / 4],
where k = number_of_passable_penalty_terrain_tiles / number_of_all_passable_tiles*

* For example, for a simple 36x36 map with two castles and with no underground level, k = number_of_passable_penalty_terrain_tiles / (36 * 36 - 2 * 12).

Draw a map with no penalty terrain. Find a hero/tree where you offered Basic Pathfinding as a new skill (in the right slot) at level-up with LMOracle. See which skill AI picks when there are no penalty terrain tiles on a map (it will never pick Basic Pathfinding). Then gradually increase the number of penalty terrain tiles, and you will eventually see that AI prefers Basic Pathfinding secondary skill over the left one.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
bloodsucker
bloodsucker


Legendary Hero
posted October 10, 2018 01:44 PM

Thx.
____________

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
NimoStar
NimoStar


Responsible
Legendary Hero
Modding the Unmoddable
posted October 10, 2018 09:34 PM

Quote:
This is how it's intended to be. Players should be satisfied No one would play the game where you cannot beat the AI. Look at chess. To beat a modern professional chess AI is quite an achivement, I'd say.


Not to nitpick or anything, but that is NOT intended. Plus millions of dollars and decades of work went into having a good chess AI. Whereas with Heroes AI probably a single guy with little playtesting did it in a couple months being paid a mediocre wage :V
____________
Never changing = never improving

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: « Prev Thread . . . Next Thread » This thread is 3 pages long: 1 2 3 · NEXT»
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.0799 seconds