A.I. (Sonny 2017)

A.I., short for Artificial Intelligence, is implemented in allies and enemies in Sonny (2017). When it is an A.I. controlled unit's turn, the A.I. will pick an ability that the unit will use depending on the situation of the battle. As an example, A.I. units are more likely to heal if they or another team member has low HP, assuming they have a healing ability equipped. How it works is that the A.I. will simulate using all of the A.I. units available abilities on respective valid targets. Each valid Ability-Target pair is then assigned a score. After performing the simulation, the A.I. will pick the pair with the highest score. The ability from that pair is then used on the target specified by the same pair.
==A.I. Types==
There are three A.I. types in Sonny (2017), Logical, Normal and Chaotic. A majority of A.I. units have the Normal A.I. type, with only a few having a different type. An A.I. type has three attributes, which differs between types:
*The chance that the A.I. will assign random A.I. score bonuses to abilities.
*The chance that the A.I. will lock on a random enemy instead of the enemy with the lowest HP percentage, thereby granting a score bonus for that target.
*How many turns the lock persist until the A.I. rolls the random enemy lock chance again.
Generally, Logical enemies are less random than Normal, and Chaotic is the opposite. The following table shows the values of each A.I. attribute, for each type:
A.I. Attribute 	A.I. Types	A.I. Types	A.I. Types
A.I. Attribute 	Logical 	Normal 	Chaotic
Random Ability Score Chance	20% 	50% 	85%
Random Enemy Lock Chance 	20% 	50% 	100%
Turns Locked 	2 	2 	0
All the A.I. attributes does is assign A.I. score bonuses, so it's not a guarantee that the A.I. will "act randomly". For example, if the difference of HP between two valid targets is large, then the A.I. will almost always pick the lower HP target even if the enemy lock is not on them. This is because the score bonus from the enemy lock is typically smaller than the bonus gained from targeting targets with low HP percentage.
The following A.I. units have the Logical A.I. type:
*Veradux
*Dr Herregods
*Kara
*ZPCI Medic
*Zakk
The following A.I. units have the Chaotic A.I. type:
*Jungle Walker
*Titan
All other A.I. units have the Normal A.I. type.
==Order of Execution==
When an A.I. unit's turn begins, the A.I. will perform the following actions in order.
===Listing Available Abilities===
The very first thing the A.I. does is finding all available abilities and puts them on a list. There are a few conditions that must be met for an ability to be considered "Available". These being that the ability
*is not on cooldown,
*is not a passive,
*must have at least one valid target alive.
If all three conditions are met, then the ability is added to the list.
===Performing Probability Rolls===
The A.I. performs the Random Ability Score roll, with the chance determined by the A.I. type as mentioned above.
On their first turn, the A.I. will perform the Random Enemy Lock roll and lock on to either the enemy with the lowest HP percentage, or a random enemy. Note that if the A.I. chooses to lock on to a random enemy, then the enemy with the lowest HP percentage can still be selected. Furthermore, if the A.I. chooses to lock on to the lowest HP, but sees that all enemies are at full HP, then it will not apply a lock at all. On subsequent turns, if a lock already exists, the A.I. will first check if the Turn Lock duration has expired before rolling. If it hasn't, then the A.I. will skip the roll.
===Pre-Simulation Bonuses===
For each ability in the list, the A.I. will iterate over all alive units that also are valid targets for respective ability, thus initiating the Ability-Target pair. It then performs this step, the simulation, and lastly the post-simulation bonus step in order before moving on to the next Ability-Target pair, until all pairs have been simulated.
The following bonuses are added to the A.I. Pre-Score Factor:
*Random Ability Score roll succeeded: Random number between 0 and 1 is added
*Target is the current Enemy Lock: +0.25
*Target is the last Enemy that the player (Sonny) targeted: +0.25
Different Ability-Target pairs can have different Pre-Simulation bonuses, due to the random function call and having different targets.
===Performing Simulation===
For the current Ability-Target pair, the A.I. simulates using the ability on the target to get an estimate of damage/healing dealt. The damage/healing will be used as the base of the score. Right before it performs the simulation, the A.I. checks if the target's relative HP is between the specified A.I. HP interval of the ability. If it's not, then the score is set to 0 and both the simulation and the post-simulation modifiers a skipped. If the target's HP is within the specified interval, then the A.I. will begin simulating it. Note that while the game does support a minimum HP threshold and a maximum HP threshold, the former is never used by any ability.
There are a few key differences between simulating an ability and executing it:
*All ability animations are skipped.
*Auras and buffs are not triggered, however passive effects that affect damage/healing are taken into account.
*No critical hit check is performed. Instead, the A.I. calculates the average damage/healing dealt with critical chance considered. By default the crit chance is 15% and critical damage/healing is 150%, which means an average damage/healing multiplier of 1.075.
*Additional score modifiers are applied depending on if the ability damages or heals the target:
**The damage score is multiplied with 1.35 if the A.I. detects that the ability is a Killing Blow (including the average critical damage multiplier from above):
**The healing score is limited by the target's HP difference between max HP and current HP. If the healing ability has excess healing (healing amount > HP difference), then the excess healing won't contribute to the score. Regardless of there is excess healing or not, the healing score is multiplied with 1.5. The following calculations details the procedure of calculating the new healing score:
***\text{[HP Difference]} = \text{[Max HP]} - \text{[Current HP]}
***x = \min(\text{[Healing Score]}, \text{[HP Difference]})
***\text{[Relative Excess Healing]} = \dfrac{\text{[Healing Score]} - x}{\text{[Healing Score]}}
***\text{[New Healing Score]} = 1.5\cdot\text{[Healing Score]}\cdot(1 - \text{[Relative Excess Healing]})
After calculating the damage/healing score, the Pre-simulation bonus multiplier is then applied:
\text{[A.I. Score]} = \text{[Damage/Healing Score]}\cdot(1 + \text{[Pre-Simulation Bonus]})
===Post-Simulation Modifiers===
The A.I. applies a bunch of different score modifiers after performing the simulation. There are a total of 8 post-simulation modifiers that can be applied, in the following order:
*Missing HP Bonus: Always applies. The A.I. Score is multiplied with a factor between 1 and 2, depending on how low the target's HP is.
**\text{[New A.I. Score]} = \text{[Old A.I. Score]}\cdot(1 + \text{[Relative Missing HP]})
*Cooldown Bonus: Only applies to attacks and abilities that deal no damage/healing (≥ 0% scaling). Each turn of cooldown adds 20% of the casters Base Stat to the A.I. Score.
**\text{[New A.I. Score]} = \text{[Old A.I. Score]} + 0.2\cdot\text{[Base Stat]}\cdot\text{[Cooldown]}
*Ability A.I. Score Bonus: Always applies, and is by default 0. The A.I. Score Factor is an attribute of each ability.
**\text{[New A.I. Score]} = \text{[Old A.I. Score]} + \text{[Base Stat]}\cdot\text{[A.I. Score Factor]}
*Ability A.I. Score Mod: Always applies, and is by default 1. The A.I. Score Mod is an attribute of each ability.
**\text{[New A.I. Score]} = \text{[Old A.I. Score]}\cdot\text{[A.I. Score Mod]}
*Buff Melee Score Factor: Only the buff applied by Deadly Wrap and Super Deadly Wrap uses this factor, which is set to a very low negative value, practically guaranteeing that the A.I. caster will not use a melee ability.
**\text{[New A.I. Score]} = \text{[Old A.I. Score]} + \text{[Base Stat]}\cdot\text{[Melee Score Factor]}
*Duplicate Buff: If the target has the same buff, with the same element, as the buff the ability applies, then the A.I. score is halved.
**\text{[New A.I. Score]} = 0.5\text{[Old A.I. Score]}
*Buff Attack Score Factor: Wound and Chain Bolt applies a buff that increases the A.I. score, if the ability has non-negative scaling (≥ 0%) and the target has said buff. Envelope, Constrict and Volt Snare applies a buff that decreases the A.I. score instead.
**\text{[New A.I. Score]} = \text{[Old A.I. Score]} + \text{[Base Stat]}\cdot\text{[Attack Score Factor]}
*Target Score Mod: The Target Score Mod is a unit attribute, and the last one that is applied to the A.I. score. By default this is 1, and only Mana Orb uses a different value, namely 0. 
**\text{[New A.I. Score]} = \text{[Old A.I. Score]}\cdot\text{[Target Score Mod]}
After applying all applicable bonuses, the A.I. then moves on the next Ability-Target pair and calculates the A.I. score for that pair. When all Ability-Target pair scores have been calculated, the A.I. moves on to the next step.
===Pick Ability from List===
Now, all available Ability-Target pairs have been assigned a score. From that list, the A.I. will then pick the Ability-Target pair with the highest score, and execute said ability against the target. However, if the list
*happens to be empty (ex. All abilities on cooldown), or
*all pairs have a score that is 0 or below (ex. Due to the Snare buff),
then the A.I. tells the unit to skip their turn.
==General A.I. Actions==
*Even if the A.I. does manage to get a successful Random Ability Score and/or Random Enemy Lock roll, it doesn't guarantee that the A.I. unit will behave any differently than if the A.I. failed these rolls. Generally, a large difference in damage reduction between enemy targets and a large difference in Power scaling between abilities will reduce the actual chance of A.I. units behaving differently than "attacking weakest enemy with highest damage". A very small difference in both areas would make the A.I. behave more random.
*A.I. units tend to use their highest damaging attack that is available. If they possess a healing ability, and one of their teammates or themselves are on low HP, then they'll likely prefer healing instead.
*Some abilities have an A.I. Score Factor greater than 0, to make the A.I. unit use these first despite the fact that higher damaging attacks are available. Example being Rage, which has 0% Power scaling and applies the Berserk buff (+300% Power). It has an A.I. Score Factor of 5.
*Use the Wound on an enemy you want Sonny's allies to attack. The allies will almost always target enemies affected by the Bleed buff (Take damage on hit and increases Attack Score Factor). Note that the buff also make allies with healing abilities less likely to use them, due to the increase in the A.I. score for Attacks. Any buff that decreases Defense has a similar effect to Wound, although it becomes less reliable the higher the target's Defense is.
*Use the Snare buff (-80% Speed on hit and reduced Attack Score Factor) for the opposite effect of Wound. Keep in mind that the Snare buff does not prevent the allies from using AoE abilities, as long as there is a different valid target for it.
==Examples==
Note: The following math formulas are not visible in the mobile view, use the desktop mode to reveal them. All calculation results are shown rounded to 3 decimal places, but in the next calculation the real value is used.
===Veradux First Turn===
During Zone 1 Stage 2, Sonny and Veradux faces a single Hulk Zombie. Assume Veradux gets the first turn. Veradux has three abilities available in the first turn: Attack, Electro Bolt and Heal. Area Heal has a starting cooldown of 5, meaning it won't be added to the list.
Veradux Level 4 stats:
*Base Stat: 65.255
*Power including starting items (+25): 32.839 + 25 = 57.839 (Shown as 58)
*Lightning Power: 25%
*Nature Power: 25%
Hulk Zombie Level 4 stats:
*Damage taken from Defense calculation: 77.378%
*HP: 856.470
Veradux has the Logical A.I. type, which means Veradux acts less random than most enemies. Assume that the Random Ability Score Roll failed, meaning no random score bonus is assigned. Because all enemies are at full HP, no enemy lock is assigned
*"Attack"-"Hulk Zombie":
**100% Power scaling, against Hulk Zombie's 77.378% damage taken: 57.839\cdot 0.77378 = 44.755
**Average damage with crits included is 1.075: 44.755\cdot 1.075 = 48.111
**48.111 damage is not enough to kill a full HP (856.470) Hulk Zombie, so no Killing Blow bonus.
**No Pre-Bonus is applied.
**All Post-Simulation are either not applicable to this current situation or have the default value, meaning no bonus gained here.
**The final A.I. score of "Attack"-"Hulk Zombie" is 48.111
*"Electro Bolt"-"Hulk Zombie":
**185% Power scaling, with 25% Lightning Power, against Hulk Zombie's 77.378% damage taken: 57.839\cdot1.85\cdot1.25\cdot 0.77378 = 103.495
**Average damage with crits included is 1.075: 103.495\cdot 1.075 = 111.257
**111.257 damage is not enough to kill a full HP (856.470) Hulk Zombie, so no Killing Blow bonus.
**No Pre-Bonus is applied.
**Electro Bolt has a 3 turn cooldown, hence it gets the cooldown bonus: 111.257 + 0.2\cdot 65.255\cdot 3 = 150.410
**The final A.I. score of "Electro Bolt"-"Hulk Zombie" is 150.41
*"Heal":
**Score automatically set to zero for both valid targets (Sonny & Veradux) since both their HP is above Heal's HP threshold (100% > 65%).
**The final A.I. score of "Heal"-"Sonny" and "Heal"-"Veradux" is 0.
As such the list of scores, sorted with the largest score first, is:
*"Electro Bolt"-"Hulk Zombie": 150.41
*"Attack"-"Hulk Zombie": 48.111
*"Heal"-"Sonny": 0
*"Heal"-"Veradux": 0
"Electro Bolt"-"Hulk Zombie" has the highest score, and thus the A.I. will pick Electro Bolt and use it on Hulk Zombie
===Veradux Healing===
In the same stage as above, the Hulk Zombie has been damaged to 75% HP. It uses Heavy Strike against Sonny, leaving Sonny with just 10% HP left but also temporarily increasing it's damage taken significantly. It is Veradux's turn, and assume Veradux is above 65% HP and that both Electro Bolt and Area Heal is on cooldown.
Same stats are used as above, with the addition of the 450% extra damage taken from the buff applied by Heavy Strike. Assume Sonny has the Fighter Helm and Storm Cloak equipped for the Vitality bonus.
Sonny Level 4 stats
*HP with Fighter Helm (+15 Vitality) and Storm Cloak (+64 Vitality) equipped: 347.392 + 15\cdot 7 + 64\cdot 7 = 900.392 (Shown as 901)
Hulk Zombie Level 4 stats:
*Extra Damage taken: +450%
Same roll results are applied here. Hulk Zombie is not at full HP and thus the enemy lock is on them. Since a couple of turns has expired, it can be assumed that Sonny has attacked Hulk Zombie at some point, thereby applying the Player Lock bonus as well, for a total of +0.5 Pre-simulation bonus.
*"Attack"-"Hulk Zombie":
**100% Power scaling, with the 450% damage taken buff: 57.839\cdot 5.5\cdot 0.77378 = 246.151
**Average damage with crits included is 1.075: 246.151\cdot 1.075 = 264.612
**264.612 damage is not enough to kill a half HP (428.235) Hulk Zombie, so no Killing Blow bonus.
**A +0.5 pre-bonus is applied: 264.612\cdot 1.5 = 396.918
**The 50% Missing HP post-bonus is applied: 396.918\cdot 1.25 = 496.147
**The final A.I. score of "Attack"-"Hulk Zombie" is 496.147
*"Heal"-"Sonny":
**325% Power scaling - 50, with 25% Nature Power: (57.839\cdot 3.25 - 50)\cdot 1.25 = 172.471
**Average damage with crits included is 1.075: 172.471\cdot 1.075 = 185.406
**Since it's assumed Sonny is missing 90% HP, it can be assumed that there will be no excess healing due to the healing being smaller than the HP difference (900.392\cdot 0.9 = 810.353). As such the healing score will not be penalized at this stage. The healing score is multiplied by 1.5: 185.406\cdot 1.5 = 278.109
**No pre-bonus is applied.
**The 90% Missng HP post-bonus is applied: 185.406\cdot 1.9 = 528.407
**The final A.I. score of "Heal"-"Sonny" is 528.407
*"Heal"-"Veradux":
**Score automatically set to zero since target HP is above Heal's HP threshold (> 65%).
**The final A.I. score of "Heal"-"Veradux" is 0.
As such the list of scores, sorted with the largest score first, is:
*"Heal"-"Sonny": 528.407
*"Attack"-"Hulk Zombie": 496.147
*"Heal"-"Veradux": 0
"Heal"-"Sonny" has the highest score, and thus the A.I. will pick Heal and use it on Sonny.
===Scavenger Attacking===
Assume Sonny and Veradux is facing a lone Level 6 Scavenger, and it's the Scavenger's turn. Both Sonny and Veradux have full HP and Level 6, and for simplicity sake assume that Sonny and Veradux have no equipment.
Sonny Level 6 stats:
*Damage taken from Defense calculation: 139.286%
*HP: 511.027
Veradux Level 6 stats:
*Damage taken from Defense calculation: 126.072%
*HP: 540.433
Scavenger Level 6 stats:
*Power: 51.804
Let's assume that the Random Enemy Lock roll actually succeeds, and the lock is applied on Veradux.
*"Bloody Claw"-"Sonny"
**80% Power scaling against Sonny's 139.286% damage taken:51.804\cdot 0.8\cdot 1.39286 = 57.725
**Average damage with crits included is 1.075: 57.725\cdot 1.075 = 62.054
**62.054 damage is not enough to kill a full HP (511.027) Sonny, so no Killing Blow bonus
**No pre-bonus is applied.
**No post-bonus is applied.
**The final A.I. score of "Bloody Claw"-"Sonny" is 62.054.
*"Bloody Claw"-"Veradux"
**80% Power scaling against Veradux's 126.072% damage taken:51.804\cdot 0.8\cdot 1.26072 = 52.248
**Average damage with crits included is 1.075: 52.248\cdot 1.075 = 56.166
**56.166 damage is not enough to kill a full HP (511.027) Sonny, so no Killing Blow bonus
**A +0.25 pre-bonus is applied: 56.166\cdot 1.25 = 70.209
**No post-bonus is applied.
**The final A.I. score of "Bloody Claw"-"Sonny" is 70.209.
As such the list of scores, sorted with the largest score first, is:
*"Bloody Claw"-"Veradux": 70.209
*"Bloody Claw"-"Sonny": 62.054
"Bloody Claw"-"Veradux" has the highest score, and thus the A.I. will pick Bloody Claw and use it on Veradux. If the Random Enemy Lock failed instead, the A.I. would've picked "Bloody Claw"-"Sonny" instead due to it having a higher score in that situation.
Category:Sonny (2017)
Category:Game Mechanics
Category:Game Mechanics (Sonny 2017)