Programming Damage Calculator

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
We will use this thread to discuss programming issues related to the Damage Calculator. I haven't organized anything around the programming effort yet. So far, it's been a one-man show. But, I plan to put some structure in place later.

For the moment, we'll collect bug reports and chat about the coding design.

The whole thing is implemented in javascript, so anyone out there interested in and capable of helping should have no problem figuring how to "get the source code". I didn't obfuscate or compress anything. In development, I have the sources all split up functionally. When I get this stuff in SVN, it will be in a bit more manageable form.

Anyway, more to come later.

/edit: http://www.smogon.com/calc/

Just to make finding it easier. - obi
 
when i gave it a test run i used modest LO moltres using air slash on a standard bold milotic and it reported 100% minimum... When i click calculate it changed the base power of air slash from 75 to 212.
 

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
when i gave it a test run i used modest LO moltres using air slash on a standard bold milotic and it reported 100% minimum... When i click calculate it changed the base power of air slash from 75 to 212.
You must be doing a reverse calc for BP.

Read the help on "Calculations" and "Reverse Calcs".
 
Doug, some of the abilities listed under a Pokemon cannot be Skill Swapped or Role Played. Not all that important, but still.
 
Read the calculator help next time:

The calculator will list all Abilities for every pokemon, and allow them to be chosen, regardless of the selected Pokemon Species. This allows for accurate damage calculations to be performed for scenarios where a pokemon's Ability has been altered due to moves like Skill Swap, Role Play, etc.

The calculator will not restrict any Ability chosen, including special abilities like Wonder Guard, which cannot be transferred ingame.
And the only ability that is not affected by Skill Swap, Role Play, and can't be Traced is Multitype.
 

VKCA

(Virtual Circus Kareoky Act)
When doing a calc of t-tar hitting arcanine with stone edge the damage using an expert belt is different than using a stone plate. Iirc they should both be multiplying by 1.2. It says the damage is x2.4 instead of x2.2. Is it doing the expert belt calc, then doubling that because stone edge is super effective? or am I just having a laps in sannity?
 

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
When doing a calc of t-tar hitting arcanine with stone edge the damage using an expert belt is different than using a stone plate. Iirc they should both be multiplying by 1.2. It says the damage is x2.4 instead of x2.2. Is it doing the expert belt calc, then doubling that because stone edge is super effective? or am I just having a laps in sannity?
Read the details of the Damage Formula in X-Act and Peterko's article.

Stone Plate is a Base Power modifier. Expert Belt is in Mod3. Yes, they are both 1.2, but they are 1.2 in different places in the calc. Lumping this stuff together as "they are both 1.2 times damage" is somewhat inexact. And YES, because they occur in different places in the formula -- they can produce slightly different results due to rounding differences.

The fact that the Damage Calculator gets these differences right -- is a major reason for making the program in the first place.

The little (x2) or (x2.4) displayed above the Damage Amount field is NOT the definitive total multiplier applied to the damage calculation. There's no way I can cram all that stuff into the label above the field. I'm just giving people an idea if the move is SE or not. Since Expert Belt is part of the overall type-effectiveness part of the calc, it is included there. Tinted Lens, Solid Rock, etc are also in there -- which is the major reason I include Mod3 in that little label in the first place. I didn't want people bitching about Rhyperior getting hosed with damage, if I excluded Mod3 from that label. So, I made the choice to include Mod3 regardless -- even though it includes Expert Belt, and most people have no clue how the damage formula really works in this regard.

But yeah, the calc is correct. This is not a bug. It's a feature.
 
It looks like the calculator is missing the item Griseous orb. I can't find it in the item dropdown menu and the movesets of Giratina-O don't apparently have a default item. Is this a bug or is the boost to STAB moves it gives somehow intrinsically added to Giratina-O, since it's the only pokemon that can hold the orb in normal circumstances?
 

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
It looks like the calculator is missing the item Griseous orb. I can't find it in the item dropdown menu and the movesets of Giratina-O don't apparently have a default item. Is this a bug or is the boost to STAB moves it gives somehow intrinsically added to Giratina-O, since it's the only pokemon that can hold the orb in normal circumstances?
Nope. Just an oversight. I started this project before Platinum came out, and forgot to add that item. I'll update the data file. Good catch.


Edit: Fixed.
 

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
I figured I should post a few of the "Known Issues" that we uncovered during regular testing. The following moves, abilities, or battle conditions are not properly implemented in the Damage Calculator, and can have an effect on the accurate calculation of Damage. These issues are likely to be addressed at some point in the future:

  • Foresight
  • Miracle Eye
  • Gravity
  • Mold Breaker
The first three items are likely to be implemented as some kind of Attacker/Defender option. Mold Breaker is a pain in the ass. I'm not sure how I'll handle it.

Now that I'm thinking about Gravity, it has me wondering -- Does Trick Room affect damage calculation in any way?
 
Hidden Power is a bit finicky--after each time I hit 'calculate' HP kept resetting back to Dark-type. Also the IVs weren't changed in their entry field after altering the Hidden Power type. Minor gripe but annoying if you're testing out several different spreads for attacker/defender.

Great job DJD very thorough... thank you very much!
 
First off awsome calc, I'm just having one little problem. I try to open the file menu and it appears under the calc portion, as in, it is pretty much entirely hidden. Is anyone else having this problem or is it just me?

Edit: Thanks for the fix, it works great now!
 

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
Hidden Power is a bit finicky--after each time I hit 'calculate' HP kept resetting back to Dark-type. Also the IVs weren't changed in their entry field after altering the Hidden Power type. Minor gripe but annoying if you're testing out several different spreads for attacker/defender.

Great job DJD very thorough... thank you very much!
If you set the Hidden Power type, the calc will not back-calculate the IV's required for that HP. There are many combinations of IV's to produce a given Hidden Power, and the calculator has no idea which IV spread you want. So, the IV's not back-calculating is not a bug.

In general, please read the Help on Hidden Power. I wrote a LOT of help text regarding Hidden Power, because Hidden Power is very tricky in the calculator.

As for the Hidden Power type resetting when you press Calculate, please give me some more information to reproduce the bug. Give me the exact steps you do to create the problem.

The fact that the Damage Calculator gets these differences right -- is a major reason for loving you Doug.
Fixed.
Thanks, X-Act. As I mentioned in the "About" window in the calc -- without the damage formula research by you and Peterko, the calculator would not have been possible. Well... not an ACCURATE calculator, anyway.
 
A very minor and very hilarious issue just came up: every time I visit the calc's page, my Google Toolbar (Firefox) detects the language of the page as Catalan and offers to translate it. Do you have any idea what's going on there?
 

obi

formerly david stone
is a Site Content Manager Alumnusis a Programmer Alumnusis a Senior Staff Member Alumnusis a Smogon Discord Contributor Alumnusis a Researcher Alumnusis a Top Contributor Alumnusis a Battle Simulator Moderator Alumnus
In the help file for contents, the category should be EVs and IVs, not EV's and IV's.

I cannot find a way to get Unburden to activate, which matters for Gyro Ball.

"Typeless" should be an option for the Pokemon type, to account for things like a pure Flying Pokemon using Roost.

The use of a "mod" variable will lead to incorrect damage. You have to treat each element of the various "mod" variables as though they were individual multipliers (which is why I've argued against that form of writing in the article, as it leads to wrong conclusions). For instance, consider this:

A Pokemon uses a single target Water move (such as BubbleBeam) in the rain against a target with Light Screen / Reflect up, and it's 2v2. If the value before the mod is not divisible by 3, your damage will be one higher than it should be after the mod1 section. For instance,

species=Kyogre
ability=Drizzle
isTwoVsTwo=true
moveName=BubbleBeam
---
species=Smeargle
ability=Own Tempo
isLightScreen=true

This gives a value of 145 prior to the mod1 multiplication, which is indivisible by 3. Under the faulty "mod" system of multiplication, you end up with mod1 doing nothing, because the 2/3 Light Screen cancels out the 3/2 Rain boost. In reality, it first does the 2/3 Light Screen, lowering the value to 96, and then multiplies by 3/2, increasing the value to 144. This error is then carried through the rest of the formula.

However, I cannot test this error, as your calculator seems to take Reflect and Light Screen as always a 1/2 multiplier, rather than a 2/3 when 2v2 is checked. Quickly examining the source code does not reveal where the problem lies, unfortunately.
 
Does Intimidate work for anybody? I can't get it to work, even though it's not a big deal since a -1 boost on the attacking mon works fine.
 

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
In the help file for contents, the category should be EVs and IVs, not EV's and IV's.
I always use apostrophes for making abbreviations plural, although I know there is debate as to what is the current "commonly accepted rule" for this. I suspect that "EVs" is the form prescribed in the Smogon style guide, so it is reasonable for the Damage Calc to follow the same convention.

There are numerous style problems in the help files (for example, I used "pokemon", not "Pokemon" or "Pokémon", all over the place) that should be corrected at some point. This doesn't just apply to the words and spelling, but to the structure of headings, bullets, bolding, linking, etc.

When I first started with the help framework, I planned to just write all the content, and then edit for style later. As the help system grew into a massive project unto itself, I changed my game plan and I wrote the styling as I went. By the end of the help sub-project, after writing and rewriting hundreds of pages of help, and programming a huge framework for auto-linking pages, highlighting widgets, auto-opening dialogs and menus, and tracking history -- I was worn out. I really just wanted to get the damn thing done. Overall, the help section was a huge pain in the ass and I seriously doubt many people even bother to look at it. So, I'm not real eager to spend much more time on it.

But, replacing "EV's" and "IV's" with "EVs" and "IVs" is a pretty simple global replace, so I'll make a note to do it.

I cannot find a way to get Unburden to activate, which matters for Gyro Ball.
Good catch. I'll probably link this to the "Ability Effect" checkbox.

"Typeless" should be an option for the Pokemon type, to account for things like a pure Flying Pokemon using Roost.
If a pokemon does not have a type, then set Type 1 and Type 2 to blank. You have to do this with the Type Dialog, not in the Type Field Text -- since a blank text will be interpreted as "no entry" and it will revert to the previous type(s). But, you can remove typing in the dialog. Perhaps a special "Pokemon Type Word" could be implemented to make it easier to remove the types through the text. Or maybe I could just allow a blank in the text (but this has other programming complications, if I'm not mistaken).

The use of a "mod" variable will lead to incorrect damage. You have to treat each element of the various "mod" variables as though they were individual multipliers (which is why I've argued against that form of writing in the article, as it leads to wrong conclusions).
I was not aware that each component of the Mod variables were calculated and rounded separately. So yeah, I came to the exact wrong conclusion that you refer to. I'll need to change up several things in the calculator to handle this properly. I will do it though, because math accuracy is very important to me for the calculator. Thanks for pointing this out, Obi.

Your calculator seems to take Reflect and Light Screen as always a 1/2 multiplier, rather than a 2/3 when 2v2 is checked. Quickly examining the source code does not reveal where the problem lies, unfortunately.
I totally missed this when implementing Light Screen and Reflect. It's easily fixed in the code. Good catch.
 

DougJustDoug

Knows the great enthusiasms
is a Site Content Manageris a Top Artistis a Programmeris a Forum Moderatoris a Top CAP Contributoris a Battle Simulator Admin Alumnusis a Smogon Discord Contributor Alumnusis a Top Tiering Contributor Alumnusis an Administrator Alumnus
I fixed Unburden, and tied it to the Ability Effect boost. I also added some text to the help page on Ability Effect.

I reworked the way Mod1, Mod2, and Mod3 are done in damage calculations. It wasn't as hard as I thought it would be. If anyone has the time and patience to verify that they are calculating correctly, that would be great.

As for Reflect and Light Screen -- they were always taking 2v2 into account, but 2v2 must be checked on the same pokemon that has the Reflect option checked. After looking at it, I'm quite convinced that Two vs Two should not be categorized as an "Attacker Option", since it quite obviously affects defenders, if Screens are involved.

I'm considering replacing the Weather field with a dialog of "Field Conditions" or something. That dialog would include Weather, Two vs Two, Gravity, etc. -- anything that logically applies to all the pokemon on the field, not just one combatant. That was the logic behind placing Weather in a special place on the UI. Now I think I should probably expand on that. I don't know when I'll get around to it, but that's my current thinking.
 
2v2 Should be a universal modifier under field (if at all possible) because it effects some attacking moves (Surf has less BP, as well as EQ and Discharge I believe in 2v2)
 

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

Top