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 Program for massive damage calculations, finding team weaknesses and more

Discussion in 'Technical Projects' started by Pokemonniac, Sep 27, 2010.

  1. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    Here's program I made. This is in fact the very first program I have ever coded. I started it about year ago as a self learning project for python language. So today I decided to share with you, because I hope some people will find it useful. Here's quick instructions how to make it work:

    Instructions for installation in this post.
    For more detailed instructions for windows with pics here.

    How to run program.

    1) Double click GUI_new (or GUI_old, iv_calc) file. Program should start soon. If not make sure your system opens file with python3.1.

    2) From command line: Go to command line. Move to the folder where program is located. Type 'GUI_new.py' (for windows) or 'python3.1 GUI_new.py' (for other OSes). Use this way if you encounter problems, so you can see error messages from command line.

    3) Create shortcut/shortcut key. In linux use command 'python3.1 /path/to/WeaknessProgram/GUI_new.py' for launcher / shortcut key. In windows create a shortcut for GUI_new file. Right-click shortcut -> properties -> Shortcut -> Shortcut Key.

    Here's short description of what this program is (hopefully) capable of:

    1) Calculating team resistances

    Simple way to calculate your teams resistances.

    2) Searching team weaknesses

    Find biggest threats for your team. Program can read directly shoddy battle and netbattle teams (that are in .txt file). More info found on help page.

    3) Find counters for Pokemons

    Find common counter for Pokemons(sets).

    4) Metagamecalculator ( for offensive Pokemon)

    Do massive calculations for all Pokemons in a given tier. More info on help page. Useful if you want to proof usefullness of your new set by doing damage calculations and so on.

    5) Metagamecalculator ( for defensive Pokemon)

    Like previous, but calculates how much tier will deal damage to you.

    6) Optimizing EV-spreads

    Optimize defensive or offensive EV spreads. Give program conditions you want your Pokemon to survive or conditions you want opponent not to survive and program finds the EV spread (with least EVs) for you.

    8) Update

    Update tier lists and Pokemon sets. Currently all files are up to date, so you don't have to update yet.

    9) Simple damage calculator

    Your ordinary damage calculator with attacking and defending Pokemon.

    10) Add new Pokemon set

    You can add new Pokemon sets used by program here.


    (11) Debugging choice (only in command line)

    This option can be used to check weird behaviour of team weakness search.)

    Note for those intrested in coding:

    I didn't first intent this for shared in smogon. Also because I'm not a native english speaker, most of namings are not making any sense for most of you (since they're not in english) and most of the stuff doesn't have english commentary. If you're intrested how some particular things work just PM me (or post here), and I can translate comments and other stuff to english for you.

    Note for grammar experts who like to fix grammar:

    All english text is located in file English.py. You're more than welcome to correct spelling/grammar issues.
  2. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    Update

    I have made a big update. If you already have the old program just download Update.zip from site and replace all the old files with new files (and if not follow the instructions in first post and install that first). I have now made a graphical user interface in new version. You can run it by doubleclicking file named GUI(.py) in windows. You can also make a shortcut for it in windows. In linux you can make a launcher with command "python3.1 /path/to/program/GUI.py". The command line version should still work if you prefer it. Those intrested I made graphical interface with tkinter which comes with python standard library so no need to install extra stuff.

    I also made new IV calculator. The principle is same than in OmegaDonut's Excel stat chart, I just added few things making it easier and faster to use . You can start it by doubleclicking ivcalc(.py) file (and you can make shortcut/launcher for it same way you did with GUI). Heres an example how to use IV calculator
    [​IMG][​IMG][​IMG][​IMG][​IMG][​IMG]
  3. Donny Mae.

    Donny Mae.

    Joined:
    Sep 20, 2009
    Messages:
    213
    This is very impressive, props to you man.
  4. Professor Lamb

    Professor Lamb

    Joined:
    Oct 4, 2010
    Messages:
    187
    Hello, I'm having some trouble opening up the program.

    I have Windows 7, downloaded Python 3.1.2, downloaded the WeaknessProgram file, downloaded the Update file, and then unzipped the files.

    However, whenever I click on something, a black box appears and then disappears. And whenever I try to run Python, a white box with stuff in it comes up. What do I do from there? It's the IDLE one too. The white box which I see is below:

    [​IMG]
  5. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    Not sure what's wrong from that yet but try these things. Try to run the program (GUI.py or MainProgram.py) with IDLE. First open IDLE (start -> all programs -> python3.1 -> IDLE). Then open either of those files with IDLE (file -> open). When you have opened that file run it with IDLE (press F5 or Run -> Run Module). Then if it fails again check the IDLE screen (the one you posted pic of) and copypaste the error message it shows here.

    Edit: Also make did you first extract the WeaknessProgram.zip and after then Update.zip. If not then you replaced new files with old ones and it won't work. If you did that then unzip that Update.zip file again.
  6. Professor Lamb

    Professor Lamb

    Joined:
    Oct 4, 2010
    Messages:
    187
    Alright, it had a pretty big error message.

    I'll post a screenshot of it.

    [​IMG]

    It basically has the same error message for each Pokémon.

    And then on the bottom is says this:

    Traceback (most recent call last):
    File "C:\Users\Mehdi\Downloads\Update\Counter1.py", line 3, in <module>
    import Voittaja
    File "C:\Users\Mehdi\Downloads\Update\Voittaja.py", line 3, in <module>
    from Pokedatabase2 import *
    File "C:\Users\Mehdi\Downloads\Update\Pokedatabase2.py", line 37, in <module>
    while ouluku<len(ou):
    NameError: name 'ou' is not defined
    >>>
  7. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    ^ Did you unzip both WeaknessProgram.zip and then Update.zip?

    You should have a file for every Pokemon (for example pikachu.py and abomasnow.py) and tier (these files are only on WeaknessProgram.zip). So first unzip WeaknessProgram.zip and after that Update.zip and then it should work.

    EDIT: Also did you try if the command line version starts? If it starts you can also try to update everything from it and then see if it starts to work.
  8. rav3n_zero

    rav3n_zero

    Joined:
    Nov 18, 2010
    Messages:
    153
    The program seems great, but I can't have access to the code files. I've tried your link but only this shows up: 403 Forbidden - You don't have permission to access /~majukayh/KP/ on this server.

    Am I doing something wrong?
  9. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    You didn't do anything wrong. There were some changes on server making it forbidden, but I changed it and now everyone should have access. Also if anyone is wondering I am planning to make next update after english names are released and there'll be new smogon sets in that update.
  10. rav3n_zero

    rav3n_zero

    Joined:
    Nov 18, 2010
    Messages:
    153
    Had access now and tested. Pretty interesting! Gotta say the interface could be improved, but as for what matters (the information it contains) the program is excellent. Props to you and a Luvdisc.

    Tested with a mono bug team I was playing around, and it showed some weaknesses I was not even aware about. Cool!

    Certainly waiting for the next update. :)
  11. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    I decided to upload program already even though all english names are not yet released. Rest of english names will be added in next update. Currently only all Pokemons have their english names (and also japanese names). I also added windows executable so you can use program without installing python in windows.

    Installing and using Windows version:

    1) Download WeakWindows.zip (http://users.jyu.fi/~majukayh/KP/)
    2) Unzip the archive
    3) Also unzip either Data1.zip or Data2.zip which are inside WeakWindows.zip and extract their files to same folder where zip file was located. *
    4) Start program from file GUI_new.exe (I have tested with Windows 7 64 bit version.)

    *) In Data2.zip there are all 4 gen sets available if you run program in 5th gen mode. In Data1.zip there are only sets created for 5th gen in 5th gen mode (if you run 4 gen all 4 gen sets are available of course though).

    Other operation systems:

    Download archive WeaknessProgram.zip and either Data1.zip or Data2.zip. Extract WeaknessProgram.zip and Data files to same folder. Install python3.1 or newer (tested only with 3.1), in some cases you have to also install tkinter library. For running the program use instructions in first post, expect change GUI with GUI_new. Tested this method in Windows7 64 bit, linux Mint 10 64 bit and debian 6.0 with freeBSD kernel and worked fine with all. Haven't tested with Mac OS, but I assume it works the same way.

    What's new:

    1) New Graphical user interface (GUI_new), which I strongly recommend (the old is GUI_old). Now you choose your options from menu -> functions. Now the required data is asked in main window instead of separate windows. This way if you wan't to change one small parameter you don't have to give all info again. You can now also change some colour themes in preferences if you don't like the default theme. (Command line version haven't been develobed and it might contain some major bugs so I recommend not to use it).

    2) You can now give att boosts, screens and so on in both metagamecalculators and simple damage calculator.

    3) More accurate calculations. I have found and repaired many bugs and I believe calculations now are pretty accurate. I created almost 100 different test situations and program passed them all. Also item Balloon is now added to program.

    4) Data is saved completely differently. Now all changing data (sets, tiers, preferences) are in .txt files and they can be easily edited (don't use notepad though, it doesn't recognice line changes probebly, instead use wordpad, gedit or similar). For example file a4.txt contains 4 gen set data of all Pokemons starting with a. Pokemon sets are saved now in standard form and can be easily edited if nesseccary. Also now old sets are not deleted when updating. This way your own sets can be savely saved in these files and will not be deleted. In graphical version you can easily add new set to database (add -> add new set) and this way you can be sure it's saved correctly. After reboot you your new sets are available same way all other sets. Also these sets are used in metagamecalculators and also when finding weaknesses.

    Note: You can't update 5th gen sets currently. Program searches sets (for 5th gen) from ww.smogon.com/bw/pokemon and naturally doesn't find anything (as of yet). All new 5th gen sets in program are taken from these forums from 5th gen analysis section.

    If any problems check first the help section in program and if it doesn't provide solution post your problem here (and tell exactly what you did, what is the problem, what operating system you are using, what python version you are using).
  12. AlcadeiasX

    AlcadeiasX

    Joined:
    Sep 23, 2010
    Messages:
    38
    Um...i've tried every method you've mentioned and haven't come up with any results, if you have a YT account please make a video? I'm totally new to this GUI Interface what-you-call-it thing. Please?
  13. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    Windows instructions

    Here's picture guide for installing windows version, hopefully it helps. I have now downloaded the file WeakWindows and it's in my desktop. First right-click it and choose Extract all.
    [​IMG]
    Next choose where to extract files
    [​IMG]

    Then extract Data1 or Data2 file.
    [​IMG]
    Extract files in same folder where to program is
    [​IMG]
    Now find GUI_new file and run it (with enter or double-click for example)
    [​IMG]
    Then choose run when windows shows warning
    [​IMG]
    Program should look something like this now (looks little different for different systems)[​IMG]
    On background it says that those files are missing because there are not any sets for 5th gen for those files so they aren't created yet. And lastly here's example how to use metagamecalculator.
    [​IMG][​IMG][​IMG][​IMG][​IMG]

    And here's instructions how to run it from command line (so you can see the error messages if they happen). First go to start menu and type "cmd" to search and open command line (cmd)
    [​IMG]

    Then move to folder where program is. Run it with GUI_new.exe (if you downloaded windows version) or with GUI_new.py (if you downloaded source).

    [​IMG]

    Here I first runned it normally and then deleted some file and it showed some error message.

    And here's also quick instructions how to make shortcut and shortcut key for program (in example I have windows version, but it works same way for source code).

    First right-click GUI_new.exe and choose create a shortcut

    [​IMG]

    Now right-click the shortcut (I moved it to desktop) and choose Properties.

    [​IMG]

    From properties go to shortcut -> Shortcut key:

    [​IMG]

    Click the box and give shortcut key by typing it there (must have ctrl+alt). Then apply and OK. Now program can be run easily with shortcut key.
    [​IMG]
  14. AlcadeiasX

    AlcadeiasX

    Joined:
    Sep 23, 2010
    Messages:
    38
    That hurt on the eyes but thanks! It now works.
  15. Chubbs

    Chubbs

    Joined:
    Nov 29, 2010
    Messages:
    231
    Sweet program. One question though, how long did this take to make?
  16. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    ^ Don't know exactly but it took a lot of time. There might been about 15000 lines of code I written, so if I would have written 1 line per minute it would have taken 250h. I would guess though I wasn't that slow so maybe 100-150 h might be close to truth.
  17. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    I just uploaded the new version (only the source, will add windows executable after more testing). Haven't tested it much so any help would be appreciated. Here's new features:

    1) Should have all english names for new moves, items, abilities and Pokemons. Also old japanese names are still there.

    2) Added gem items. They make 1.5 x boost in BasePower if anyone is intrested (not sure if it's tested more accurately)

    3) Much faster boot time. Cleaned some old (inefficient) code and program should now start much faster (about 4 times faster in my system).

    4) Given data is now transported between different functions. For example if you give some pokemon in offensive metagamecalculator and choose defensive metagamecalculator after that, it has already same info than previously. Comes handy when moving between functions. Also added swap button for damage calculator.

    5) Added 1vs.1 battle mode for finding bugs in weakness calculations. This simulates 1 vs.1 battle between two Pokemons and program shows what move each Pokemon uses each turn and so on. Counter and weakness calculations are directly based on these 1vs. 1 battle simulations, so this might be useful if some strange behaviour is observed or if you otherwise want to take a little deeper look in what's going on in this program actually.

    I also added online version of metagamecalculators and damage calculation in http://users.jyu.fi/~majukayh/KP/damage/. It lacks most of the desktop versions functionalities, but might be useful if you are not on your own computer and want to do some basic calculations. I might add the EV optimization tool on online version in near future. Probably will not add weakness finding in this because it's much slower than desktop version so it would probably be annoyingly slow.
  18. rav3n_zero

    rav3n_zero

    Joined:
    Nov 18, 2010
    Messages:
    153
    Pokemaniac, I don't seem to be able to open it. It says that "ImportError: No module named Teamlukija".
  19. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    ^ it should be fixed now.
  20. rav3n_zero

    rav3n_zero

    Joined:
    Nov 18, 2010
    Messages:
    153
    This happened when I tried to run a search for weaknesses in my team. It has Porygon2 with Trace.
  21. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    ^ Now it should work.
  22. rav3n_zero

    rav3n_zero

    Joined:
    Nov 18, 2010
    Messages:
    153
    Working fine now. Will keep testing. :) Thanks.
  23. Tomahawk

    Tomahawk M-I-C-K-E-Y M-O-U-S-E
    is a Team Rater Alumnus

    Joined:
    Oct 2, 2010
    Messages:
    2,277
    My computer says GUI_new.exe is not a valid Win-32 application.
  24. WillSO

    WillSO

    Joined:
    Oct 6, 2010
    Messages:
    100
    It seems the app doesn't work with Win7 32 bit :/
  25. Pokemonniac

    Pokemonniac

    Joined:
    May 23, 2007
    Messages:
    133
    Sorry for the late response. You have probably figured out itself already, but use the program from source code if it doesn't work on 32 bit system. And thanks for the info, I may look into it in future.

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