1. Welcome to Smogon! Check out the Smogon Starters Hangout for everything you need to know about starting out in the community. Don't forget to introduce yourself in the Introduction and Hangout Thread, too!
  2. Welcome to Smogon Forums! Please take a minute to read the rules.

Programming Damage Calculator

Discussion in 'Technical Projects' started by DougJustDoug, Dec 24, 2009.

  1. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    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
  2. Smurf.

    Smurf.
    is a Past SPL Winner

    Joined:
    Nov 21, 2009
    Messages:
    655
    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.
  3. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    You must be doing a reverse calc for BP.

    Read the help on "Calculations" and "Reverse Calcs".
  4. wavedash

    wavedash

    Joined:
    Mar 7, 2009
    Messages:
    337
    Doug, some of the abilities listed under a Pokemon cannot be Skill Swapped or Role Played. Not all that important, but still.
  5. RBG

    RBG Got a long list of ex-lovers, they'll tell you I'm insane.
    is a Smogon Social Media Contributoris a Super Moderatoris a Site Staff Alumnusis a Smogon IRC AOp Alumnusis a Researcher Alumnusis a Tiering Contributor Alumnusis a Battle Server Moderator Alumnus
    Facebook Manager

    Joined:
    Jan 27, 2008
    Messages:
    3,369
    Read the calculator help next time:

    And the only ability that is not affected by Skill Swap, Role Play, and can't be Traced is Multitype.
  6. VKCA

    VKCA (Virtual Circus Kareoky Act)

    Joined:
    Jan 8, 2009
    Messages:
    3,668
    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?
  7. RBG

    RBG Got a long list of ex-lovers, they'll tell you I'm insane.
    is a Smogon Social Media Contributoris a Super Moderatoris a Site Staff Alumnusis a Smogon IRC AOp Alumnusis a Researcher Alumnusis a Tiering Contributor Alumnusis a Battle Server Moderator Alumnus
    Facebook Manager

    Joined:
    Jan 27, 2008
    Messages:
    3,369
    2 * 1.2 is in fact 2.4
  8. Philip7086

    Philip7086 Myuu
    is a Tutor Alumnusis a Tournament Director Alumnusis a Site Staff Alumnusis a Team Rater Alumnusis a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Researcher Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnusis Smogon Frontier's Factory Headis a Past WCoP Winneris a SPL Winnerdefeated the Smogon Frontier

    Joined:
    Jun 23, 2008
    Messages:
    3,083
    EB is 1.2x iirc, and LO is 1.3x
  9. VKCA

    VKCA (Virtual Circus Kareoky Act)

    Joined:
    Jan 8, 2009
    Messages:
    3,668
    I realize that, but I was under the impression that was not how it worked. But I could very easily be wrong.
    edit: Good to know. Thanks
  10. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    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.
  11. PT8Sceptile

    PT8Sceptile

    Joined:
    Feb 29, 2008
    Messages:
    21
    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?
  12. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    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.
  13. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    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?
  14. TEA_DEMON

    TEA_DEMON

    Joined:
    May 19, 2009
    Messages:
    2,466
    Trick Room has no effect on damage calculation, no. It only reverses attack order.
  15. POKEMONBATTLEBRAIN

    POKEMONBATTLEBRAIN

    Joined:
    Feb 14, 2008
    Messages:
    623
    No, Trick Room doesn't affect any damage output, it only affects what order the pokemon use their moves(slower pokes moving before faster ones).
  16. gamer_reloaded

    gamer_reloaded

    Joined:
    Oct 17, 2007
    Messages:
    70
    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!
  17. Sledge

    Sledge

    Joined:
    Oct 10, 2009
    Messages:
    330
    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!
  18. X-Act

    X-Act np: Biffy Clyro - Shock Shock
    is a Site Staff Alumnusis a Programmer Alumnusis a Smogon IRC SOp Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnusis an Administrator Alumnus

    Joined:
    Feb 17, 2006
    Messages:
    4,675
    Fixed.
  19. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    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.

    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.
  20. CardsOfTheHeart

    CardsOfTheHeart

    Joined:
    Aug 21, 2007
    Messages:
    1,970
    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?
  21. david stone

    david stone Fast-moving, smart, sexy and alarming.
    is a Site Staff Alumnusis a Smogon IRC AOp Alumnusis a Programmer Alumnusis a Super Moderator Alumnusis a Researcher Alumnusis a Contributor Alumnusis a Battle Server Moderator Alumnus

    Joined:
    Aug 3, 2005
    Messages:
    5,150
    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.
  22. Cost

    Cost

    Joined:
    Jan 30, 2009
    Messages:
    528
    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.
  23. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    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.

    Good catch. I'll probably link this to the "Ability Effect" checkbox.

    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).

    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.

    I totally missed this when implementing Light Screen and Reflect. It's easily fixed in the code. Good catch.
  24. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Smogon IRC SOp Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,098
    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.
  25. RBG

    RBG Got a long list of ex-lovers, they'll tell you I'm insane.
    is a Smogon Social Media Contributoris a Super Moderatoris a Site Staff Alumnusis a Smogon IRC AOp Alumnusis a Researcher Alumnusis a Tiering Contributor Alumnusis a Battle Server Moderator Alumnus
    Facebook Manager

    Joined:
    Jan 27, 2008
    Messages:
    3,369
    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 Viewing Thread (Users: 0, Guests: 0)