Page 1 of 2
Tactical AI improvements
Posted: Wed Feb 09, 2011 5:59 am
by yufra
I have been experimenting with some changes to the tactical AI to improve how attackarea and eventually beam talents are used. What I am toying with right now is to have talents expose their main targeting definition so the tactical AI code (and maybe even the right-click menu) can grab it and figure out how many allies and foes a talent will hit. To explain the current state I set up this scenario: I spawned a modified Hydra (with the tactical AI and updated Breath and the Ritch bolt) on the opposite side of a mold. Why the bolt? Well it offers an alternative to the AoE breath attacks.
So the tactical AI goes through the talents and notices that the breath attacks will hit both an ally and a foe. I set a "ally_compassion" variable in the Hydra's ai_state which lets it know to heavily penalize against hitting allies, which is why they have such a small individual weight. I also changed the want.attackarea to use the ally/foe count from the highest weighted ATTACKAREA talent.
Code: Select all
============================== TACTICAL AI 3-headed hydra
3-headed hydra 1796 tactical ai talents can use Flamespit T_RITCH_FLAMESPITTER_BOLT attack weight 3.2100473305314
[DEBUG] hit an ally!
[DEBUG] hit a foe!
3-headed hydra 1796 tactical ai talents can use Lightning Breath T_LIGHTNING_BREATH_HYDRA attackarea weight 0.72013894538279
[DEBUG] hit an ally!
[DEBUG] hit a foe!
3-headed hydra 1796 tactical ai talents can use Poison Breath T_POISON_BREATH attackarea weight 0.18487997710712
[DEBUG] hit an ally!
[DEBUG] hit a foe!
3-headed hydra 1796 tactical ai talents can use Acid Breath T_ACID_BREATH attackarea weight 0.17515352346404
Tactical ai report for 3-headed hydra
* attackarea 0.21553645107043
* attack 4.79288167818
Tactical choice: attack T_RITCH_FLAMESPITTER_BOLT
The result? The ATTACK bolt is selected over the ATTACKAREA breaths. This is still really early, but I think it is the start for more accurate handling of AoE talents. Here is hoping!
EDIT: Oh, and I need to figure out how/if the GO_MELEE option is being used. Doesn't appear to be used right now...
EDIT2: Actually, I just realized that a negative want means the tactical category will be ignored. I changed that and now the bolt alternative isn't even necessary as seen in this quote...
Code: Select all
============================== TACTICAL AI 3-headed hydra
[DEBUG] hit an ally!
[DEBUG] hit a foe!
3-headed hydra 1796 tactical ai talents can use Lightning Breath T_LIGHTNING_BREATH_HYDRA attackarea weight 0.43717408436517
[DEBUG] hit an ally!
[DEBUG] hit a foe!
3-headed hydra 1796 tactical ai talents can use Poison Breath T_POISON_BREATH attackarea weight 0.079304709091517
[DEBUG] hit an ally!
[DEBUG] hit a foe!
3-headed hydra 1796 tactical ai talents can use Acid Breath T_ACID_BREATH attackarea weight 0.032451238890851
Tactical ai report for 3-headed hydra
[ATTACK] attacking with innate combat
Re: Tactical AI improvements
Posted: Thu Feb 10, 2011 10:42 pm
by Marcotte
That would indeed be a good improvement for ToME, especially it often happens that the player is fighting along creatures with AOE effects (summoners or alchemists being the main cases).
I'm planning on implementing something similar for intelligent casters in BOB (you can check that the targeting information for abilities is already accessible), but I haven't done it so far (I don't even let the AI check if there is anyone in the way of a bolt ability, but that's somewhat on purpose).
By the way, implementing something like using dummy projection also have the extra benefit of teaching the AI to cast ball spells when the target is just out of range, as long as the ball spread will reach them. And it will allow them to benefit from the off-by-one distance bug too (that one could lead to funny result with range-1 spells).
Re: Tactical AI improvements
Posted: Fri Feb 11, 2011 2:40 am
by yufra
Marcotte wrote:That would indeed be a good improvement for ToME, especially it often happens that the player is fighting along creatures with AOE effects (summoners or alchemists being the main cases).
Yup, that is one of the main hopes I have for this project.
By the way, implementing something like using dummy projection also have the extra benefit of teaching the AI to cast ball spells when the target is just out of range, as long as the ball spread will reach them. And it will allow them to benefit from the off-by-one distance bug too (that one could lead to funny result with range-1 spells).
It is true, I have already increased the "range" of spells by the sum of both range and radius in for the purposes of deciding if the tactical AI should attempt the dummy projection. After that the dummy projection collects the number of foes and allies hit, does some math and weights the talent with the result. I think I have all of the talents/code in place, but due to the scale of the change testing this is going to be tricky.

Re: Tactical AI improvements
Posted: Fri Feb 11, 2011 4:21 pm
by yufra
Alright, a bit on the technical side. I have changed the current behavior of "friendlyfire" to "selffire" and added a "friendlyfire" option. This allows you to differentiate talents between hitting the source of the talent (now selffire) and all allies (now friendlyfire). There are also two variables that can be set in the ai_state table of NPCs, "self_compassion" and "ally_compassion." These default to 5 and 1, respectively, and are weights that bias against ATTACKAREA if it would hit you or an ally, respecively. These can be set to range from "servile behavior" (low self_compassion, high ally_compassion) to "me first" (high self_compassion, 0 ally_compassion), to "psychopath" (0 self_compassion and ally_compassion).
Enough of technical talk, here is an example that will intrigue most players: the alchemist and his golem. I started Testme the Alchemist and immediately switched control to the golem to test how the new AI works. At first there was nothing in sight:
Code: Select all
============================== TACTICAL AI Testme
Testme 142 tactical ai talents can use Infusion: Regeneration T_INFUSION:_REGENERATION_2 heal weight 2.4343428021592
Testme 142 tactical ai talents can use Rune: Manasurge T_RUNE:_MANASURGE_1 mana weight 1.9145789156229
Testme 142 tactical ai talents can use Infusion: Wild T_INFUSION:_WILD_3 defend weight 36.681561663639
Testme 142 tactical ai talents can use Gift of the Pureborn T_HIGHER_HEAL heal weight 24.821997264353
Tactical ai report for Testme
[PARTY AI] following master Testme
But then a grey rat sneaks up on Testme and:
Code: Select all
[LOG] Giant grey rat crawls poison onto Testme.
Now I haven't played with the DEFEND AI at all, but it does the right thing:
Code: Select all
============================== TACTICAL AI Testme
Testme 142 tactical ai talents can use Infusion: Regeneration T_INFUSION:_REGENERATION_2 heal weight 3.2991020740246
[DEBUG] hit an ally!
[DEBUG] hit a foe!
[DEBUG] hit self!
Testme 142 tactical ai talents can use Throw Bomb T_THROW_BOMB attackarea weight 0.75636969218239
Testme 142 tactical ai talents can use Rune: Manasurge T_RUNE:_MANASURGE_1 mana weight 1.833423985742
Testme 142 tactical ai talents can use Channel Staff T_CHANNEL_STAFF attack weight 1.5122363507949
Testme 142 tactical ai talents can use Infusion: Wild T_INFUSION:_WILD_3 defend weight 36.733531647309
Testme 142 tactical ai talents can use Gift of the Pureborn T_HIGHER_HEAL heal weight 24.269180612905
Tactical ai report for Testme
* defend 3.0117904259987
* attack 2.6219430768068
Tactical choice: defend T_INFUSION:_WILD_3
And once he is defended, Testme sets about to do some damage. Note that while deciding the tactical weight for T_THROW_BOMB (0.42) there is a dummy projection that shows he would hit an ally (the player controlled golem) as well as a foe, resulting in a low weight and a negative want (not shown) so ATTACKAREA is discarded as an option (not shown in the Tactical ai report segment).
Code: Select all
============================== TACTICAL AI Testme
Testme 142 tactical ai talents can use Infusion: Regeneration T_INFUSION:_REGENERATION_2 heal weight 3.2852049698747
[DEBUG] hit an ally!
[DEBUG] hit a foe!
Testme 142 tactical ai talents can use Throw Bomb T_THROW_BOMB attackarea weight 0.42556243010719
Testme 142 tactical ai talents can use Rune: Manasurge T_RUNE:_MANASURGE_1 mana weight 1.2698157574577
Testme 142 tactical ai talents can use Channel Staff T_CHANNEL_STAFF attack weight 2.0026311470617
Testme 142 tactical ai talents can use Gift of the Pureborn T_HIGHER_HEAL heal weight 24.515816430242
Tactical ai report for Testme
* attack 2.5209391415002
Tactical choice: attack T_CHANNEL_STAFF
So far so good. What if I move the golem out of the way?
Code: Select all
============================== TACTICAL AI Testme
Testme 142 tactical ai talents can use Infusion: Regeneration T_INFUSION:_REGENERATION_2 heal weight 2.4064778485031
[DEBUG] hit a foe!
Testme 142 tactical ai talents can use Throw Bomb T_THROW_BOMB attackarea weight 2.9873212289445
Testme 142 tactical ai talents can use Channel Staff T_CHANNEL_STAFF attack weight 1.2158420071735
Testme 142 tactical ai talents can use Gift of the Pureborn T_HIGHER_HEAL heal weight 24.550599283563
Tactical ai report for Testme
* attackarea 2.3617680636236
* attack 2.0506774491828
Tactical choice: attackarea T_THROW_BOMB
Success! The tactical AI respects allies and hitting itself (not shown) with AoE. Note that the AI will not shift the targeting off of the target to optimize the number of foes versus number of enemies, so for example if you are facing a radius 1, selffire AoE enemy and always stay adjacent to it the AI will never shift the target off to the side to hit you and not it. The easier solution to that one is to give some escape talents, though.

Re: Tactical AI improvements
Posted: Fri Feb 11, 2011 4:37 pm
by Grey
This highlights something we need in the game - psychopath alchemist enemies!
More seriously though, cool work, with a lot of good potential for improving the current AI.
Re: Tactical AI improvements
Posted: Fri Feb 11, 2011 5:18 pm
by edge2054
Great work yufra, I look forward to testing it with a Paradox Clone

Re: Tactical AI improvements
Posted: Sat Feb 12, 2011 6:48 pm
by yufra
Alright, it is time for extensive testing. Edge got an earlier version of this patch and between the two of us we found and squashed some bugs, but in order to test it all I need more bodies on the problem. Definitely report any Lua errors you see in this thread, but also report more subtle things. For example, wyrms were not breathing over their progeny because I had forgotten to remove their "ally_compassion" setting. Thanks!
Re: Tactical AI improvements
Posted: Mon Feb 14, 2011 8:26 pm
by yufra
Here is an updated patch.
Re: Tactical AI improvements
Posted: Tue Feb 22, 2011 11:34 pm
by yufra
Alright, the changes are in SVN now... let me know how it goes!
Re: Tactical AI improvements
Posted: Thu Feb 24, 2011 11:24 pm
by tiger_eye
Just wondering, does "friendlyfire" account for resistances of allies? I don't think a fire drake would have any problem breathing a cone of fire onto their brethren...
Re: Tactical AI improvements
Posted: Fri Feb 25, 2011 1:27 am
by yufra
tiger_eye wrote:Just wondering, does "friendlyfire" account for resistances of allies? I don't think a fire drake would have any problem breathing a cone of fire onto their brethren...
Currently friendlyfire does not account for resistance since the tactical AI has no concept of resistances or damage types. I am not sure if we will add this feature since it is an obvious one to add, but we must be wary of having tactical AI do too much and risk slowing things down. Currently drakes simply ignore allies and breath willy-nilly.
Re: Tactical AI improvements
Posted: Fri Feb 25, 2011 1:43 am
by Marcotte
yufra wrote:Currently friendlyfire does not account for resistance since the tactical AI has no concept of resistances or damage types. I am not sure if we will add this feature since it is an obvious one to add, but we must be wary of having tactical AI do too much and risk slowing things down. Currently drakes simply ignore allies and breath willy-nilly.
I don't think this feature will have much impact, CPU-wise. It pretty much changing the way hits are counted from:
to
Code: Select all
nb_foes_hit = nb_foes_hit + math.max(0, 100 - act.resists[damage_type])
, so the overhead should be minimal. The only issue is that you add yet another field to talents to tell the AI what damage_type it is using, which can get complicated for some talents (like alchemist bombs).
Re: Tactical AI improvements
Posted: Fri Feb 25, 2011 3:25 am
by yufra
Marcotte wrote:The only issue is that you add yet another field to talents to tell the AI what damage_type it is using, which can get complicated for some talents (like alchemist bombs).
Yes, that is the issue... but I already updated most talents to have targets so why not damage types? I am not terribly concerned about alchemist bombs, that can be handled by having damage_type be a function just like target/range/radius can be now. The side effect would be that the tactical AI would also take into account the player's resistances... which is a good thing as well. So... when I am feeling up to it.

Re: Tactical AI improvements
Posted: Wed Mar 16, 2011 3:02 pm
by marvalis
Summoner ai problems: in b21, with the new ai, there are a few problems:
* Flamespitter seems to run away at all times, usually it is inappropriate.
* Turtle does not seem to use taunt as often as before.
* Turtle tries to escape
Code: Select all
============================== TACTICAL AI turtle
turtle 22449 tactical ai talents testing Shell Shield T_SHELL_SHIELD
turtle 22449 tactical ai talents testing Taunt T_TAUNT
turtle 22449 tactical ai talents can use Taunt T_TAUNT protect weight 20.59069955933
turtle 22449 tactical ai talents testing Attack T_ATTACK
Tactical ai report for turtle
* escape 4.5681988651445
He should be tanking not running :3
Code: Select all
============================== TACTICAL AI ritch flamespitter
ritch flamespitter 22720 tactical ai talents testing Flamespit T_RITCH_FLAMESPITTER_BOLT
[DEBUG] hit a foe!
ritch flamespitter 22720 tactical ai talents can use Flamespit T_RITCH_FLAMESPITTER_BOLT attack weight 600.30854163899
ritch flamespitter 22720 tactical ai talents testing Equilibrium Pool T_EQUILIBRIUM_POOL
ritch flamespitter 22720 tactical ai talents testing Attack T_ATTACK
[DEBUG] hit a foe!
ritch flamespitter 22720 tactical ai talents can use Attack T_ATTACK attack weight 120.67806006543
Tactical ai report for ritch flamespitter
* escape 12.678125669323
* attack 2.0078181265197
No matter how high attack and flamespit are, the AI still prefers to run for it.
Re: Tactical AI improvements
Posted: Thu Mar 17, 2011 4:46 pm
by yufra
Great report marvalis, thanks. I will be looking at the tactical AI this weekend, and hopefully have those things hammered out soon.