Programming Pokémon Showdown Damage Calculator

DaWoblefet

Demonstrably so
is a Smogon Social Media Contributoris a Top Researcheris a Tiering Contributoris a Battle Simulator Moderator
A wide number of issues with the current damage calculator exist which largely arise at a result of not being up-to-date with Generation 7 modifier order. I'll go through the non-Gen 7 issues first, then I'll address the Gen 7-specific bugs. Assume in these damage calculations both targets are at level 100.
  • Parental Bond
Parental Bond should run two independent strikes to calculate damage, not do a trivial damage = damage * modifier. Parental Bond causes the move to run an entirely new damage calculation and applies the baby hit modifier in between the spread move modifier and the weather modifier. As a result, there should be two independent sets of damage rolls displayed, as well as percent to KO being based on 256 combinations of damage rolls, not 16. Displaying it as a combination would require displaying potentially 256 damage rolls, so most damage calculators that implement Parental Bond accurately do something like this:
Accurate output:
152 Atk Parental Bond Kangaskhan-Mega Frustration vs. 252 HP / 152+ Def Amoonguss: 190-225 (43.98 - 52.08%) -- 6.65% chance to 2HKO (1089/16384)
(1st Hit: 153, 154, 156, 157, 159, 162, 163, 165, 166, 168, 171, 172, 174, 175, 177, 180; 2nd Hit: 37, 37, 39, 39, 39, 40, 40, 40, 40, 42, 42, 42, 43, 43, 43, 45)

PS damage calc:
152 Atk Parental Bond Kangaskhan-Mega Frustration vs. 252 HP / 152+ Def Amoonguss: 191-225 (44.2 - 52%) -- 12.5% chance to 2HKO
Possible damage amounts: (191, 192, 195, 196, 198, 202, 203, 206, 207, 210, 213, 215, 217, 218, 221, 225)
In addition, certain secondary effects that apply if a target has taken damage / target is not at full HP should be factored into the baby hit's calculation. These notably include: Shadow Shield / Multiscale, Assurance, Power-Up Punch.
Accurate output:
252 Atk Parental Bond Kangaskhan-Mega Crunch vs. 0 HP / 0 Def Shadow Shield Lunala: 280-334 (67.47 - 80.48%) -- guaranteed 2HKO
(1st Hit: 188, 190, 192, 194, 196, 198, 202, 204, 206, 208, 210, 212, 214, 216, 218, 222; 2nd Hit: 92, 96, 96, 96, 96, 100, 100, 100, 104, 104, 104, 104, 108, 108, 108, 112)

PS damage calc:
252 Atk Parental Bond Kangaskhan-Mega Crunch vs. 0 HP / 0 Def Shadow Shield Lunala: 235-277 (56.6 - 66.7%) -- guaranteed 2HKO
Possible damage amounts: (235, 237, 240, 242, 245, 247, 252, 255, 257, 260, 262, 265, 267, 270, 272, 277)
  • Unnecessary 0x1000 modifiers: these would affect cases of damage overflow (and generally speaking won't affect the calculation in any normal cases anyway, so are unnecessary)
- Soul Dew when not a Lati twin
- STAB when user doesn't have STAB

Generation 7 modifier order

From a cursory glance, the conditions for checking if a modifier should be applied is correct; it's moreso the order. The listed modifiers (BP, Attack, Defense, final modifiers, general damage modifiers), are taken from OZY's research, which is considered to be the authoritative research for Gen 7 and is what the simulator itself is using (or minimally should be using). I have listed these in the order they should be applied. If you have any questions about what I mean, or need test cases, let me know. Modifiers that are incorrect in the PS damage calculator are bolded.
  • Gen 7 BP modifiers
  1. Aura Break - 0xC00
  2. Rivalry and gender is not the same - 0xC00
  3. -ate Abilities - 0x1333
  4. Iron Fist - 0x1333
  5. Reckless - 0x1333
  6. Rivalry and gender is the same - 0x1400
  7. Battery - 0x14CD
  8. Sheer Force - 0x14CD
  9. Sand Force - 0x14CD
  10. Analytic - 0x14CD
  11. Tough Claws - 0x14CD
  12. Fairy Aura / Dark Aura - 0x1548
  13. Technician - 0x1800 (note that Technician will check if the previous modifiers would have pushed this above/below 60 BP)
  14. Flare Boost - 0x1800
  15. Toxic Boost - 0x1800
  16. Strong Jaw - 0x1800
  17. Mega Launcher - 0x1800
  18. Heatproof - 0x800
  19. Dry Skin - 0x1400
  20. Muscle Band - 0x1199
  21. Wise Glasses - 0x1199
  22. Type-boosting items - 0x1333
  23. Orbs - 0x1333
  24. Gems - 0x14CD
  25. Solar Beam / Solar Blade - 0x800
  26. Me First - 0x1800
  27. Knock Off - 0x1800
  28. Helping Hand - 0x1800
  29. Charge - 0x2000
  30. Facade - 0x2000
  31. Brine - 0x2000
  32. Venoshock - 0x2000
  33. Retaliate - 0x2000
  34. Fusion Bolt / Fusion Flare - 0x2000
  35. Grassy Terrain / Misty Terrain (defensive) - 0x800
  36. Electric / Grassy / Psychic Terrain (offensive) - 0x1800
  37. Mud Sport / Water Sport - 0x548
If base power exceeds 16 bits after the 1 BP check (i.e. greater than 65535), mod by 65536. Source.
  • Gen 7 Attack modifiers
+6/-6 boosts/drops
Hustle
  1. Slow Start (of note, don't forget that special Z-moves are affected by Slow Start) - 0x800
  2. Defeatist - 0x800
  3. Flower Gift - 0x1800
  4. Guts - 0x1800
  5. Overgrow / Blaze / Torrent / Swarm - 0x1800
  6. Flash Fire - 0x1800
  7. Solar Power - 0x1800
  8. Plus / Minus - 0x1800
  9. Steelworker - 0x1800
  10. Huge Power / Pure Power - 0x2000
  11. Water Bubble (offensive) - 0x2000
  12. Stakeout - 0x2000
  13. Thick Fat - 0x800
  14. Water Bubble (defensive) - 0x800
  15. Choice Band / Choice Specs - 0x1800
  16. Thick Club - 0x2000
  17. Deep Sea Tooth - 0x2000
  18. Light Ball - 0x2000
If the attack exceeds 16 bits after the 1 attack check (i.e. greater than 65535), mod by 65536. Source.
  • Gen 7 Defense modifiers
+6/-6 boosts/drops
Sandstorm & Rock-types
  1. Flower Gift - 0x1800
  2. Marvel Scale - 0x1800
  3. Grass Pelt - 0x1800
  4. Fur Coat - 0x2000
  5. Eviolite - 0x1800
  6. Assault Vest - 0x1800
  7. Deep Sea Scale - 0x2000
  8. Metal Powder - 0x2000
If the attack exceeds 16 bits after the 1 defense check (i.e. greater than 65535), mod by 65536. Source.
  • General damage modifiers
After calculating the base damage, apply these modifiers in order, according to OZY research.
  1. Spread move - 0xC00
  2. Parental Bond - 0x400
  3. Weather - 0x1800 for boosting, 0x800 for weakening
  4. Crit - 0x1800
  5. Random factor
  6. STAB (Adaptability) - 0x1800 (0x2000)
  7. Type effectiveness - So long as we only support two types, 0.25x-4x
  8. Burn - 0x800
  9. Final damage modifiers
  10. Z-moves into Protect - 0x400
  11. 1 damage modifier
  12. 16 bit constraint (maximum damage should never be higher than 65535)
  • Final damage modifiers
OZY research etc.
  1. Screens - Singles = 0x800, Doubles = 0xAAC
  2. Neuroforce - 0x1400
  3. Sniper - 0x1800
  4. Tinted Lens - 0x2000
  5. Multiscale / Shadow Shield - 0x800
  6. Fluffy (contact moves) - 0x800
  7. Friend Guard - 0xC00
  8. Solid Rock / Filter / Prism Armor - 0xC00
  9. Fluffy (Fire-type moves) - 0x2000
  10. Metronome (item) - you have this right
  11. Expert Belt - 0x1333
  12. Life Orb - 0x14CC
  13. Resist Berries - 0x800
  14. Doubled-power moves - 0x2000
  • 32-bit multiplication overflow
If a calculation ever exceeds 2^32 - 1, mod by 2^32. This has been proven to be possible during the base damage calculation, when applying any modifier after the base damage, during the random factor, and even during trivial modifiers (e.g. if there are no final modifiers, an implicit 4096/4096 is applied). This is in addition to the 16 bit constraints listed for BP, Attack, Defense, and damage at the very end.
  • Weight calculations
See SadisticMystic's research.
  1. Apply all Autotomizes (there is a weight minimum of 0.1kg).
  2. Apply Heavy Metal (there is no weight maximum)
  3. Apply Light Metal and Float Stone. There is still a weight minimum of 0.1kg. If the calculation results in a weight that extends to two decimal places, "floor" to one decimal place (e.g. 10.25 = 10.2, 10.24 = 10.2, and 10.26 = 10.2).
  • Speed calculations
See DaWoblefet's research.
  1. Apply boosts/drops (+6/-6) and floor.
  2. Apply all other Speed modifiers except paralysis and pokeRound.
  3. Apply paralysis and floor.
 

Earthworm

is a member of the Site Staffis a Community Leaderis a Community Contributoris a Tournament Director Alumnusis a Super Moderator Alumnusis a Tiering Contributor Alumnusis a Smogon Media Contributor Alumnusis the Smogon Tour Season 6 Championis a Past SPL and WCoP Champion
Community Leader
When I reduce the DVs for HP Water for this calculation the damage calculation doesn't change even though it should.


 

pre

shaving yaks and herding cats
is a Battle Simulator Administratoris a Community Leaderis a Programmer
Community Leader
Magnemite and Magneton are defaulting to just electric and not electric/steel in the calculator (in every gen)
Fixed.

When I reduce the DVs for HP Water for this calculation the damage calculation doesn't change even though it should.
Changing your HP/Atk/Def should have no affect on a Special Attack if I'm not mistaken, so I assume you mean "The calculator does not update the Hidden Power's type and base power based on changes to DVs?" (If you look, its still HP Ice 70). In the particular case of your screenshot, I believe 7/14/13/15/15/15 would still be base power 70, and Water has the same type effectiveness against Aerodactyl as Ice, so the end result should be the same in this case?

Please correct me if I'm misunderstanding - I've filed a bug to have changes to DVs/IVs reflected as changes to the Hidden Power type/BP, but for now you'll need to adjust the BP and type manually using the drop downs beside the move. :(

Import feature won't recognize Gastrodon-East
Thanks. This isn't a regression, we've never supported this AFAICT. I've filed a bug to make sure we have import/export parity with the teambuilder on the client, but this is going to take some time to implement :(. In the meantime you're stuck changing 'Gastrodon-East' to 'Gastrodon' before importing, sorry.
 

Earthworm

is a member of the Site Staffis a Community Leaderis a Community Contributoris a Tournament Director Alumnusis a Super Moderator Alumnusis a Tiering Contributor Alumnusis a Smogon Media Contributor Alumnusis the Smogon Tour Season 6 Championis a Past SPL and WCoP Champion
Community Leader
Changing your HP/Atk/Def should have no affect on a Special Attack if I'm not mistaken, so I assume you mean "The calculator does not update the Hidden Power's type and base power based on changes to DVs?" (If you look, its still HP Ice 70). In the particular case of your screenshot, I believe 7/14/13/15/15/15 would still be base power 70, and Water has the same type effectiveness against Aerodactyl as Ice, so the end result should be the same in this case?

Please correct me if I'm misunderstanding - I've filed a bug to have changes to DVs/IVs reflected as changes to the Hidden Power type/BP, but for now you'll need to adjust the BP and type manually using the drop downs beside the move. :(
Sorry for not being clear. When I reduce the HP and Def DVs on Zapdos, Zapdos should be taking more damage from Aerodactyl's Ancient Power (which it did in the battle I discovered this in).
 

pre

shaving yaks and herding cats
is a Battle Simulator Administratoris a Community Leaderis a Programmer
Community Leader
When I reduce the HP and Def DVs on Zapdos, Zapdos should be taking more damage from Aerodactyl's Ancient Power.
Fixed. Thank you for the bug report - really sorry you had to discover this in a battle! :(
 
Moves that lower user's stats (i.e. Leaf Storm, Superpower, Draco Meteor) seems to not working when clicking Twice or even 5 times to show the total damage output.
189287
 
  • Like
Reactions: pre

badabing

pocket monsta
is a Tiering Contributor Alumnus
damage calc stuck in "loading" for me. checked and javascript was enabled. all chrome settings at recommended. this has been going on for months
 

pre

shaving yaks and herding cats
is a Battle Simulator Administratoris a Community Leaderis a Programmer
Community Leader
i discovered an issue with the way stat boots and drops are measured in gsc. in gens 1 and 2 when you drop your speed stat by one stage it's dropped to 66/100 and not 67/100 like in gen 3 and above. the damage calc however implements 67/100 for gen 2
Thanks for the detailed bug report ("arrows and a GIF"!) - this is now fixed.

Mold Breaker should ignore unaware, but it currently does not in the calc:

252 Atk Mold Breaker Haxorus Devastating Drake (190 BP) vs. 252 HP / 252+ Def Quagsire: 271-321 (68.7 - 81.4%) -- guaranteed 2HKO after Leftovers recovery

+6 252 Atk Mold Breaker Haxorus Devastating Drake (190 BP) vs. 252 HP / 252+ Def Unaware Quagsire: 271-321 (68.7 - 81.4%) -- guaranteed 2HKO after Leftovers recovery

just throwing that out there
This should be fixed?
Screen Shot 2019-08-05 at 22.03.03.png



The calculator doesn't take in consideration Mold Breaker when against mons with Levitate
Hmm... I specifically made fixes to Mold Breaker yesterday, but maybe I didn't deploy the change. However, I've confirmed it appears fixed now:

189386


damage calc stuck in "loading" for me. checked and javascript was enabled. all chrome settings at recommended. this has been going on for months
Try turning off all your extensions maybe (or an incognito window)?
 
Last edited:

pre

shaving yaks and herding cats
is a Battle Simulator Administratoris a Community Leaderis a Programmer
Community Leader
Please see the screen shot I linked above in my edited post. But here's another one for you:

Screen Shot 2019-08-05 at 22.16.00.png


Please make sure you clear your cache/hard refresh to get the latest version of the calc!
 
Last edited:

pre

shaving yaks and herding cats
is a Battle Simulator Administratoris a Community Leaderis a Programmer
Community Leader
Is there a nodejs version? I'd really like to use this in my own project. I tried to convert it by hand, but it was taking forever, and once an update comes out, well, I'd be screwed.
There actually is now, soon to be released as @pokemon-showdown/calc on NPM.
 
Last edited:

pre

shaving yaks and herding cats
is a Battle Simulator Administratoris a Community Leaderis a Programmer
Community Leader
Moves that lower user's stats (i.e. Leaf Storm, Superpower, Draco Meteor) seems to not working when clicking Twice or even 5 times to show the total damage output.
This should now be fixed. :)
 

DaWoblefet

Demonstrably so
is a Smogon Social Media Contributoris a Top Researcheris a Tiering Contributoris a Battle Simulator Moderator
Wring Out / Crush Grip use the wrong formula for damage; it should be scaling HP to 4096s.

Here's an accurate formula representation:
189617


In JS, I'm pretty sure something like this would work:
Math.max(1, Math.floor(pokeRound((120 * 100 * Math.floor((defender.curHP * 4096) / defender.maxHP())) / 4096) / 100))

For a test case, Wring Out vs. 184/362 HP should have 60 BP, not 61 BP. The damage calculator currently returns this (incorrect):

0 SpA Smeargle Wring Out (61 BP) vs. 252 HP / 0 SpD Blissey: 9-12 (2.4 - 3.3%) -- possibly the worst move ever
 
  • Like
Reactions: pre
I could be completely wrong, and I don't know how to exactly use the showdown calc, but it looks like petal blizzard isn't in the calc. Thanks.
 
Hey, I was wondering if anyone else was getting this glitch. I was finding damage calculations for Galarian Weezing with its new ability. To simulate it, I just removed Levitate and Sheer Force, and yet Earthpower displays as doing 0% damage and the damage for Rock Slide doesn’t change when I change the ability to (Other).
https://imgur.com/a/8ownQjl
 
  • Like
Reactions: pre
I pasted an importable of a 1v1 team on the Import/Export text box, clicked the "Import" button, clicked on "Only show imported sets", and then tried to select a set from the newly imported Pokemon. It showed the Pokemon and the spread all right, but it doesn't seem to display the moves, but instead shows something like this
[21:11:22] Attid(UwU)de: In the damage calc
[21:11:40] Attid(UwU)de: When I import set(s), the set moves are not loading
[21:12:13] jetou :https://www.smogon.com/forums/threads/3593546
[21:16:58] Attid(UwU)de:https://imgur.com/loeG2kJ This shod be proof enough, right?
[21:17:37] jetou : Yes, they can reproduce it on their end, granted you explain the reproduction steps well enough.
Just wanted to make sure I did everything correctly......
 
Some moves, like morning sun, are completely left out of the damage calculator because very few people want to know how much damage morning sun does.
This made me think about a potential new feature for the Damage Calculator with healing, stat raising moves, and Protect (although would probably be somewhat niche).
It's where you can calculate if a move would be a 2HKO, 3HKO, ect. when factoring in Protect, Leftovers, Wish, Recover, and Calm Mind/Curse.
This would be useful in those scenarios where you have use a move like Leaf Storm/Super Power against a wall with recover, or in those moments where 2 left over recoveries turn a 2HKO into a 3HKO.
It can also create the NKO (Never Knock Out) as a move may be too weak initially, the opponent can heal/boost off any potential damage, or when your stats are dropping.
This probably would be too much effort to code for such a niche idea, but it would be interesting.
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top