1. New to the forums? Check out our Mentorship Program!
    Our mentors will answer your questions and help you become a part of the community!
  2. Welcome to Smogon Forums! Please take a minute to read the rules.

Programming Base Stats Damage Calculator

Discussion in 'Technical Projects' started by Steinhauser, Feb 26, 2009.

  1. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    Since I started playing, I never enjoyed using damage calculators. Having never paid close attention to Pokémon's actual stats, I found looking them up or converting them from base stats every time was a huge hassle. Then I read X-Act's Damage Stats method of quick and painless calculations using only a Pokémon's base stats. I was overjoyed, as base stats are so much easier to remember; like many people I have a lot of the common ones already memorized. In no time at all I had cobbled together a bare-bones calculator based on the Damage Stats formula, and for a while it served me just fine.

    But after a couple of in-match screw-ups due to the calculator's inaccuracy, as well as needing more accurate calcs for analysis writing, I decided I required the precision of a real calculator. And I thought, why couldn't I make a calculator that takes base stats, converts them internally, and then puts them through the full damage calc formula? As far as I knew it hadn't been done (though I never really checked). So that's what I did, and it works pretty well.

    Anyway, without further ado:


    Features:

    Fully Comprehensive: 100% accurate damage calculator, with every option and factor that might ever be applicable, while keeping the basic options compact and simple. Converts base stats automatically - no more going back and forth between a stat calculator (or Shoddy team builder) and a damage calculator.

    Save & Load: Save a set of attacker or defender stats for quick reference. Keep your whole team, and common metagame threats, on file - no need to look anything up in the heat of battle.

    Will It KO? Calculates likelihood of a OHKO, 2HKO or 3HKO given various factors. Good for analysis writing as well as mid-battle risk management.

    Base Damage Calculator: Calculate the exact base power of moves like Gyro Ball, Eruption and Reversal.

    Stat Calculator: Simple and effective stat calculator. Turns the base stat, EVs, IVs, nature, boosts, etc. into the raw number you need.

    Instructions:

    The main part of the program is pretty straightforward - enter the base stats for the attacker and defender based on either physical or special damage (Attack / Defense, or Sp. Attack / Sp. Defense, plus HP). Then put in the EVs for each stat (the ^^ and vv buttons max/min out each EV set). Add in any Atk and Def boosts (from +6 to -6), whether each Pokémon has a positive, negative, or neutral nature for their corresponding stat, the base power of the move and whether it is STABed or not, and the weakness/resistance based on typing.

    Item is the last field and the only one that might seem confusing. The "item type" is one of four categories, each of which affects the damage formula in a slightly different way.

    - "Life Orb" includes Life Orb and Metronome.

    - "Choice" includes Choice Band, Choice Specs, Thick Club, Light Ball, Soul Dew and Deepseatooth.

    - "Plate" includes all plates and other type-boosting items, Muscle Band, Wise Glasses, and Adamant and Lustrous Orbs.

    - "Expert Belt" includes only Expert Belt.

    In the "Weak / Resist" field, there is an option that reads "x1 (resist + weak)". This applies only to Pokémon who resist and attack with their first type, and are weak to it with their second type - for example, Swampert taking a Surf, or Gyarados taking an Ice Beam - and provides maximum calculator accuracy for these Pokémon. In all other instances (including "weak + resist", such as Gyarados taking a Grass Knot) use "x 1".

    More comprehensive instructions forthcoming (including those for the other apps), possibly as a readme.txt file.

    v. 1.1

    The "Additional Options" menu lists various abnormal factors - weather, Crits, Burn, Me First, offensive abilities like Guts and Pure Power, defensive abilities like Thick Fat, defensive items, and the like.

    Note that a category won't be counted unless it is checked, including any of the drop-down menu categories. (Even if an ability is selected in the drop-down menu, it will not be applied unless it is also checked).

    v. 1.11

    Critical Hit damage ignores defense boosts and attack drops.

    v. 1.2

    Level and IV modification is finally here! It is now a full-blown, 100% functional damage calculator.

    v. 1.3

    Base Power Calculator, available under Tools. Claculate the base power of Gyro Ball, Flail / Reversal, Grass Knot / Lowkick, Eruption / Water Spout, and Crush Grip / Wring Out, given the necessary information.

    Also, ability to display damage done in HP, as well as percentile, for exact measurement.

    v. 1.4

    Added "Will it KO?" feature, which calculates likelihood of a OHKO, 2HKO or 3HKO. Keep in mind a 3HKO calculation takes a few seconds (it has to process the entire damage formula several thousand times).

    Added buttons to max out EVs quickly.

    Also added the stat calculator, which is as basic as it looks/sounds.

    v. 1.41

    Fixed "Additional Options" so it will follow alongside the main window when moved. Same with "Will It KO". Added readme file in case a feature is confusing or unclear.


    (And finally: no more rapidshare! Direct download.)
  2. darkie

    darkie mfw i see alison brie
    is a member of the Site Staffis a Contributor to Smogon Social Mediais a Smogon IRC AOPis a Super Moderatoris a Contributor to Smogonis a CAP Contributor Alumnusis a Smogon Media Contributor Alumnusis a Battle Server Moderator Alumnus
    Public Relations

    Joined:
    Dec 25, 2005
    Messages:
    6,118
    This looks really nice, but I'll take a closer inspection after school!
  3. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    Downloaded and this looks very, very useful, a few things though:
    Your link to the file is broken. There is a "http://www.<br .com/>%0A" before the actual address.

    "However, some abilities, like Pure Power, can be replicated by using Choice Band item damage."
    What if you want a Pokemon with both? Or Pure Power+Life Orb?

    I really like the ease of use for this calculator. No more switching back and forth between Shoddy's team builder to get stats and Libelldra's calc and for most calculations its fine and great.
    But the lack of all the "extra" features (Ability, Weather, Screens, Level (for Little Cup), Critical Hit, Burnt (if you have an Atk boost/drop and are burnt it could be confusing), Me First boost, Sand SpDef Boost, and defensive items) is a bit of a turn off. I know you want to keep the clean interface, but would it be possible to have it so that you could click a button called "Advanced Options" or something and those popped up?
  4. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    Yes, absolutely. If people find this useful then including something like an Advanced Options pop-up tab will be my next priority.

    The link formatting is being annoying so it's just a plain URL now.

    I'm glad this is going over well so far, as this is my first such project.
  5. MagicMaster87

    MagicMaster87

    Joined:
    Nov 24, 2008
    Messages:
    1,182
    There's actually such a damage calculator included as part of CardsOfTheHeart's Excel spreadsheet set, and it does have all those extra options like weather, ability, status, etc..

    However, I can certainly see this as being useful once you add in those extra options eric suggested (I also think they should be added), as not everyone uses or even has Excel, and it's a bit annoying at times to have to go through all the pop-up messages Excel gives me about macros and external data and whatnot...

    A few questions about this program:

    1.) What language is it written in? Or more to the point, does it work cross-platform (i.e., Windows, Mac, and Linux)?
    2.) Are you able to type in the numbers, or do you have to use the arrow keys?
    3.) Can you explain the Weak/Resist thing a bit more? Does it simply range from x0.25 (4x resist) to x4 (4x weakness), or what? Your explanation makes it sound rather complex...
  6. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    1. It's written in C#. I don't know how compatable it is with systems other than Windows, nor (in the case they aren't) how to make them compatable, unfortunately.

    2. You can type in the numbers. In ther next version I hope to have a convenient tab-through feature as well. (You can tab through currently, but it doesn't highlight each value for easy editing so it's not very fun.)

    3. It's almost as simple as you said; the values range from x0.25 to x4, with x1 in the middle. All Pokémon will fall in one of those values, EXCEPT Pokémon that are dual-type, and whose first type resists the attack but whose second type is weak to it.

    So a Gyarados taking an Ice Beam would use the "x1 (resist + weak)" modifier, since its first type (Water) resists Ice while its second type (Flying) is weak to Ice. If the same Gyarados were to take a Grass Knot instead, it would use the "x1" modifier, since its first type is weak to the attack while the second resists it.

    The difference is minute, sometimes not even present, and is due to the game rounding down after halving the first value, then doubling it again. Since the damage will never differ by more than 1 hp, an on-the-fly player could probably ignore the "x1 (resist + weak)" modifier altogether if he doesn't want to think about it.

    For everyone else, it may seem a bit confusing at first but overall I think it's a quicker and easier system than having to input how each of the defender's two types fare against the attack (like in Libelldra's calc, for example).
  7. 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
    On a not-so-related note, I'm glad you found my damage base stats thread helpful.
  8. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    I did indeed, it was the inspiration for this program.

    Version 1.1 is out, which adds additional options.
  9. MagicMaster87

    MagicMaster87

    Joined:
    Nov 24, 2008
    Messages:
    1,182
    Very nice, it's looking good so far from the pictures. Once my laptop gets fixed, I'll be sure to actually try it out.

    Another question: What's the "Self KO" option for?
  10. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    Brilliant!
    There is one more thing, would it be possible to have the Level as adjustable? I ask this mainly because I play Little Cup (its at Lv. 5), it would be very nice to have a calculator as convenient as this for calculations. Also Jumpman said that there was some error on Libelldra's Calc at low levels so we are reluctant to use that one.

    Self-KO will be for moves like Explosion. The base power is 250, but it halves the oponents defence to give almost exactly 500. But not exactly.

    Edit: After a little testing it seems that crits don't bypass Def boosts/Atk drops. This is easily remedied by the person using the Calc (just set raised Def to 0, and lowered Atk to 0) but should probablty be noted in the OP.
  11. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    I was going to put it into this release, along with an IV setting for non-31 IVs, but I realised I had no idea how actual stats were based on base stats except at level 100. I will definately consider it for the next instalment after some research. (Is there a document with the formula?)

    Absolutely, good catch. I made Reflect/LS become ignored during crits, but forgot about attack boosts. Should be simple to fix.

    Edit: Fixed. v. 1.11 is up.
  12. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    There is an article with the formula here: http://www.smogon.com/dp/articles/stats
    The key parts to know are:

    For determining a Pokemon's HP, you use the following formula:


    HP = ((2 * BaseStat + IV + (EV / 4)) * Level / 100 + Level + 10)


    And:



    If you want to find a stat that isn't HP, then you use the following formula:


    Stat = (((2 * BaseStat + IV + (EV / 4)) * Level / 100 + 5) * Nature)


    And thanks for adding levels, this will really help with the LC analysis. Using a calc that we think is wrong does not help..


    Cool, downloading and testing. If I find anything else I'll say.
    Did you make crits ignore Attack drops and Defence boosts, but not Attack boosts or Defence drops?
  13. Coronis

    Coronis Backie Jerkhart
    is a Battle Server Moderator
    Mentor

    Joined:
    May 25, 2008
    Messages:
    1,583
    Crits definitely pass the other pokemons defensive boosts. Vaporeon vs +6 sp.def suicune Vaporeon used Hidden Power! It's super effective! Suicune lost 8% of it's health. Vaporeon used Hidden Power! It's super effective! A critical hit! Suicune lost51% of it's health.

    Anyway, I shall download this, if I can (mac).
  14. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    eric:

    Formula: Thanks! I will get on it. After this is implemented my program's functionality should rival any other calc's.
    Crits: Aye. They do not ignore Attack boosts or Defense drops.

    Evil Lord:

    Let me know how it works on your Mac.

    In other news there is a small bug when attempting to calculate damage when some combination of base power, base Attack and offensive ability is selected. If you encounter a scenario where a Pokémon with an offensive ability is turning up a damage score of 0% - 0%, turn off the ability (uncheck it), press the calculate button, then turn it back on and recalculate.

    Edit: v. 1.2 is here, and includes level and IV settings!
  15. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    Even brillianter!

    Ill do some more testing and see if I can find anything else. Checking it against the Damage Formula for possible additions/changes.

    I don't suppose you plan to add double battle features? If you did there would be Helping Hand, TVT modifier (weakens moves that hit more than one opponent to 75%. Not fully researched.), a change in the effectiveness of Reflect under 2V2 conditions.

    There are a few rare moves and situations that are not accounted for, they almost always will not matter but if you want to go for perfection then: Technician, Charge, Mud/Water Sport, Spit Up (For this move the variable R is always 100, but the user can simply take max damage). The last three are so rare that they do not matter, I just mentioned them for completeness.

    I was also wondering, to go along with this would it be possible to make an applet that calculated the power of the variable moves? Things like Crush Grip/Wring Out, Eruption/Water Spout, Grass Knot/Low Kick (maybe with a table of weights for Pokemon?), Reversal/Flail.
    The other variable power moves are easy to work out in your head, and these are simple enough with a calculator but it would be nice for people who want a shortcut to avoid going back and forth from a stat calculator (like Shoddy's team builder) and a calculator.

    Ill do some testing for accuracy against Libelldra's one see how closely they match up and edit any differences I find in here.
  16. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    I could indeed add doubles features, perhaps as a secondary pop-up.

    I thought I had included Technician but I guess I forgot to put it on the list (actually I included the code, if you type it in the word it works). I'll include it in the next release. The rest of those options can be implemented too, but I don't think they're used competetively enough to warrant the space they would take up. However if I get more requests for those features specifically I can surely put them in. ("Obscure Options" tab?)

    A variable-damage attack calculator is a viable idea and I will consider it. Perhaps as a menu item. "Tools > Variable Damage Calculator"
  17. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    Doubles features could probably be included in the "Additional Options" tab, there would only be a few extra check boxes so a another popup seems unnecessary.

    The extra options are not needed at all, though maybe a list of things that are not included could be added to your OP?

    And yes, that would be a good place for a variable damage calc if you want to add it.

    In all the tests I've done so far it seems to give the same numbers as Libelldra's calc, this is good because that has been confirmed as correct at Lv. 100 but according to Jumpman16:
    I will do more testing and compare the results of the calculations from both with ones by hand from the Damage Formula when I get time.
  18. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    Thanks for the testing you're putting into this. Even as of right now I'm not sure how accurate my calc is at lower levels, though it follows the formula as far as I can see.

    It turns out I have a lot of time on my hands, so I'm going to implement everything listed. (That square of space in the bottom right is just big enough for 2v2 options and obscure options.) Also coming is a list of actual damage in HP as well as the percentile, which might be helpful (especially in LC and for accuracy-testing purposes).
  19. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    No prob, you're making the calc. I just get to use it. And make a few suggestions.

    Cool, if you have lots of time there is another feature that could be useful to some people, % chances of 1KOs and 2KOs. I don't know how complicated that would be though and it would probably use quite a bit of space.
    Its the only thing that Libelldra has but you don't right now. Also, if you do want to add it maybe it could be done in a different way that's less space intensive and can provide more information?
    Instead of saying: X chance of a 1KO, X Chance of a 1KO with Leftovers, X chance of a 1KO with Sandstorm, X chance of a 1KO with SR, X chance of a 1KO with SR+Leftovers then the same for 2KOs (this is how its shown there) it may be better to have a box that you put in how much damage you need done (in % or actual HP) and it gives you the probability. You could either have a check box for SR/Leftovers/Sand(or hail) or let the person using the calc do that.

    I am not sure if its needed, but its an idea.

    And Lv. 100 calcs seem to match so far. Still trying more things.
    Also, Swarm is not on the list but works if you type it. Same as Tech.

    Edit:
    Ok, not good. With this newer version its giving totally different calcs, I don't know if I am doing something wrong. gimme a min to work out what's going on.

    Edit2: lol, my mistake. I left +1 attack on libelldra. Yes, its working perfectly.

    Edit 3: Ok, first inconsistency at Lv. 100. With the base atk/def/HP at 100 and a Choice Band with STAB activated no EVs in anything Libeldra gives:
    354 Atk vs 236 Def & 341 HP (100 Base Power): 162 - 192 (47.51% - 56.30%)
    While your Calc gives:
    Damage: 47.51% - 56.31%.

    The max damage is 0.01% different. I am sure its not due to a setting being wrong as they gave exactly the same number for STAB without CB and CB without STAB. Will edit in more when/if I find them.

    Edit4: Another error of 0.01%, maybe its a rounding error or something like that? It seems so small that even a single HP would be less. Anyway: Same stats as before, Blaze, Weather and Crit:
    236 Atk vs 236 Def & 341 HP (150 Base Power): 324 - 382 (95.01% - 112.02%)
    Yours:
    Damage: 95.02% - 112.03%.

    Without Crit, with Blaze and Weather:
    236 Atk vs 236 Def & 341 HP (150 Base Power): 162 - 191 (47.51% - 56.01%)
    Yours:
    Damage: 47.51% - 56.02%.

    Blaze on its own agrees, Weather on its own agrees, Crit on its own agrees.

    Edit 5: Huge Power/Pure Power on its own gives:
    (42.23% - 49.85%)
    Yours
    Damage: 42.23% - 49.86%.

    Ok, that's enough.
  20. darkie

    darkie mfw i see alison brie
    is a member of the Site Staffis a Contributor to Smogon Social Mediais a Smogon IRC AOPis a Super Moderatoris a Contributor to Smogonis a CAP Contributor Alumnusis a Smogon Media Contributor Alumnusis a Battle Server Moderator Alumnus
    Public Relations

    Joined:
    Dec 25, 2005
    Messages:
    6,118
    Check the actual HP damage for that last calc, eric. It may be that the two calculators round differently.
  21. MagicMaster87

    MagicMaster87

    Joined:
    Nov 24, 2008
    Messages:
    1,182
    I don't see how it could be anything other than simply rounding differently. You'd need 1000HP for 0.1% to equal a single point of HP; there's no way 0.01% is going to make any difference for 300-400HP stats, especially when Pokemon always rounds down.
  22. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    Steinhauser's one does not show actual damage, just %. But yes, that is probably the reason.

    I agree. Its not enough for a single HP, you would need 10000+ HP for it to change anything. However it is a inconsistency, however minor, so I thought it would be worth mentioning.
  23. Steinhauser

    Steinhauser

    Joined:
    Jun 5, 2007
    Messages:
    378
    Ahh, goodie.

    Aboslutement. I've thought about this since the beginning, but never with an idea of how to implement it. Your idea is good. I am thinking of something like: a button that says, "Can it KO?" When clicked, a pop-up or tab lets you specify the opponent's remaining HP, in either % or hit points, and it will return the % chance of a KO.

    Already fixed in my latest instalment, which will be uploaded shortly.

    Regarding 0.01%s, that is indeed a rounding issue and not an accuracy issue. The hit point totals are the same. (New feature by the way, HP damage display.) Either way, I can fix it if that is the convention for damage calcs, no problem.
  24. eric the espeon

    eric the espeon maybe I just misunderstood
    is a Forum Moderator Alumnusis a Researcher Alumnusis a CAP Contributor Alumnusis a Tiering Contributor Alumnusis a Contributor Alumnus

    Joined:
    Aug 7, 2007
    Messages:
    3,694
    Makes sense, people should know that SR is 12.5% and SS/Hail/Leftovers are 6.25% per turn. One problem I see is that the value R does not have uniform probability, this is minor so you don't have to include it but:
    Another may be that working out the chance of a move 2-3KOing, especially including SR and/or Leftovers/SS, could be quite difficult. Asking it the chance of doing 50% or 33.33% would not get you very far.

    Maybe have it like this (note, I have no idea if this is impractical from a programming point of view.):

    A button that opens a pupus or menu or something, maybe "Chance to KO"? that gives you these options:

    Previous damage
    Box that you can put numbers in. Drop down menu with % damage or HP damage as options.

    Attacks to KO
    Box that you put the number of turns you want to attack for. For a 1KO you put 1, 2KO 2 ect.. If its left blank then it could jump to the lowest possible number of turns.

    Checkbox for leftovers
    Checkbox for SS/Hail
    Maybe a checkbox for SR, but then you have the complexity of different type effectiveness. Probably best to just make people put the % in by hand.

    And it returns your % chance to KO over that many turns. Now that would be very, very cool.

    Nice.

    I don't think its a problem. Libelldra's one does it the other way but unless someone specificity goes looking for it like I did and does the same calculation on both it should be fine, and even then all they will notice is a difference so small it is entirely insignificant.

    Downloading newest version and testing.
  25. Archer

    Archer

    Joined:
    Dec 22, 2007
    Messages:
    101
    This looks great. I just finished mine, but you beat me to the punch releasing it. :D
    You may want to redo the layout; you made the program by adding on sections, so everything is a bit of a mess. Maybe if you put the IVs and level in the main Attacker/Defender sections and separate the actual "calculate" section. Forgive me if I missed it, but what programming language was this done in?

Users Viewing Thread (Users: 0, Guests: 0)