• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Best way to calculate fight power?

Status
Not open for further replies.
Level 13
Joined
Mar 29, 2012
Messages
530
JASS:
function hAI_GetUnitFightPowerAgainstUnit takes unit u1, unit u2 returns real
    local real sourceHp = GetWidgetLife(u1)
    local real targetHp = GetWidgetLife(u2)
    local real sourceWeaponDamage = hAI_GetUnitWeaponDamageToUnit(u1, 1, u2) // u1 weapon damage against u2
    local real targetWeaponDamage = hAI_GetUnitWeaponDamageToUnit(u2, 1, u1) // u2 weapon damage against u1
    local real sourceAttackInterval = BlzGetUnitAttackCooldown(u1, 1)
    local real targetAttackInterval = BlzGetUnitAttackCooldown(u2, 1)
    local real fightPower = 0.
 
    set fightPower = ?
 
    return fightPower
endfunction
JASS:
function hAI_GetGroupFightPowerAgainstGroup takes group g1, group g2 returns real
    local real fightPower = 0.
   
   
   
    return fightPower
endfunction
I don't know how standard wc3 melee AI do calculation in engaging a combat, so I need your suggestion about what's the best way to calculate the fighting power, starting from a unit against a unit.
 
Last edited:
fightPower2 = life1 / (dmg2 / cooldown2) // Should be how many secs required for u2 to kill u1
fightPower1 = life2 / (dmg1 / cooldown1) // Should be how many secs required for u1 to kill u2


// if returned value is negative, u1 should lose fight, if it is positive, u1 should win fight, the higher/lower it is the better/worst the difference is
return fightPower1 - fightPower2
 
Level 13
Joined
Mar 29, 2012
Messages
530
fightPower2 = life1 / (dmg2 / cooldown2) // Should be how many secs required for u2 to kill u1
fightPower1 = life2 / (dmg1 / cooldown1) // Should be how many secs required for u1 to kill u2


// if returned value is negative, u1 should lose fight, if it is positive, u1 should win fight, the higher/lower it is the better/worst the difference is
return fightPower1 - fightPower2
That could be great, but what's a better way when it comes to comparing fight power between a group of units against another group?
 
Level 13
Joined
Mar 29, 2012
Messages
530
How do I pick and compare each units in g1 against each units in g2? For example, u1 from g1 should be compared against which unit in g2 if g2 has 12 units and g1 has 10 units.
What should I consider to be used as comparing condition between a unit from both groups?

Sorry if my english isn't clear enough.
 
Level 6
Joined
Aug 28, 2015
Messages
213
Usually you use the total number of resources, sum of Health of each unit and the average value of the factors of the group Damage Per Second/ Heal per second ect. and then you compare (Health[g1] / DPS[g2]) - (Health[g2] / DPS[g1]) if it is greater then 0 the first group is stronger if it is less the second group wins.
There should be also other factors like is there a healer in the group then you would need to add to the health the amount of potential heal using the result number as approximate fighting time.
Code:
G1{
-Soldier{Health = 150, DPS = 45},
-Soldier{Health = 250, DPS = 45},
-Sniper{Health = 200, DPS = 60}
}
G1{Health = 600 // (150 + 250 + 200), DPS = 50 //(45 + 45 + 60) / 3}

G2{
-Knight{Health = 480, DPS = 60},
-Priest{Health = 200, DPS = 20}
}
G2{Health = 680 // (480 + 200), DPS = 40 // (60 + 20) / 2}
That would result to:
(600 / 40) - (680 / 50)

15 seconds to kill G1 - 13.6 seconds to kill the G2 = 2.15 is over 0, so the G1 wins after about 13 seconds
but the priest can heal so we have to recalculate again.
lets say the Priest is full of mana just to make it easier.
Code:
G2{
-Knight{Health = 480, DPS = 60},
-Priest{Health = 200 , DPS = 20},
-PriestHeal{Health = 90 } = HealPerSecond * (FightTime div Cooldown)*Cooldown // 45 Heal with 5 second cooldown is 45/5 = 9HPS *(13 div cooldown(5) = 2)*Cooldown
 = 10
G2{Health = 770 // (480 + 200 + 90), DPS = 40 // (60 + 20) / 2}
That would result to:
(600 / 40) - (770 / 50)
15 - 15.4 = -0.4 is smaller then 0, so G2 would win after a 15.5 second fight.

Looks like I made this values like that this gonna happen ;)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
One could work out net survival time.

One works out the total DPS and total HP for both groups. One then works out how long it would take the DPS of the opposing group to kill the total HP of the group. One then compares these two times. The group with the shortest survival time will likely lose.

When computing health, armor should be factored in. One could even factor in armor types but the logic for that would get messy.

This does not factor in abilities or area damage. Hence it is still possible for a group with low health and low DPS to win through area damage or ability advantages.
 
Level 13
Joined
Mar 29, 2012
Messages
530
Okay, I understand what to do, thank you for your suggestions.

Besides that, how do I calculate the DPS dealt by each unit of a group against all units of the other group? Since the damage dealt to units of the other group can be different depending on the armor type they have.

hAI_GetUnitWeaponDamageToUnit(whichUnit, weaponId, targetUnit)
This function returns the exact weapon damage of a unit against targetUnit. (takes into account the armor damage reduction of targetUnit)
Weapon damage --> [ mindamage + ((maxdamage - mindamage) / 2) ] -> Median of weapon damage range.
 
Last edited:
Level 6
Joined
Aug 28, 2015
Messages
213
I would suggest for area damage /ability/ buffs ect. To add a extra value that will be the sum out of the weight you have to give each of this factors maybe you can even dynamicly change this weights on game runtime.
I would suggest to have a base value as fix point and calculate something like range, area size ect. in relation to it.
 
Status
Not open for further replies.
Top