Chinchow Battle Analyzer - A comprehensive replay analyzer and reverse stat calculator

Hey there! If you have seen me on the forums, you've probably seen my bug posts or related comments. All of those came from when I was working on this:

A comprehensive library that is able to parse, logically, analyze, and reverse stat calculate replay logs to allow for better battle analysis. ONLY designed to work for gens 7 & 8 standard metas

This has been bundled into an add-on here: https://github.com/gigalh128/Chinchow-Battle-Analyzer. However, I will note that I am not going to update this specific version of the battle analyzer because after creating it, I realize that there are so many structural improvements that I would like to make that I would be better off creating an entirely new version of this project instead. As a result, I decided not to make this into an npm package or something similar, since I don't see myself updating this specific project very often.

Capabilities
  • Parsing replays into easily usable json objects
  • Better handling of the illusion ability than any other parser that I know of
  • Figuring out impossible/guaranteed items and abilities based on what pokemon have done in battle, even if they are not explicitly shown (such as determining if something must have magic guard)
  • Reverse damage calculations to give a theoretically possible configuration of items/abilities/stats on each pokemon, even including ditto.
  • Calculations for defensive stats contain 2 possible ranges, the main one being the range that maximizes hp evs and the alternative one maximizing defensive evs.
  • These can also calculate whether or not something is guaranteed to have specs/band/life orb

Note that the analyzer only gives one theoretically possible combination (which assumes no items/boosting abilities if possible), which is one of the biggest reasons why I wanted to re-do the project entirely. With its current method, trying to show multiple combinations would be computationally too expensive, which is why I would like to integrate usage statistics into a different version.

Motivation/Challenges
I realized that all of the stat analysis add-ons that currently exist for pokemon showdown had only ever been for random battles, and that no one had ever tackled the issue of trying to calculate possible stat ranges for pokemon, given any type of standard battle (i.e. not custom metas). Additionally, none of the replay parsers around online seemed to give an output that contained comprehensive information on an entire replay. Usually they would just give summmaries, which is pretty limited. Just to make sure this project was actually original though, I asked if anyone had done this over a year ago on the discord, to which I got responses of no and that's probably impossible, which was pretty motivating. Although now, I do remember watching aed3's videos about making an AI and how he also encountered reverse damage calculation, so I'm curious to see if there are differences in the way that we approached this.

1634070962051.png

1634071068169.png

As a result, I spent about a month testing out how reverse damage calculation by itself might look like in my free time, and then went to actually code up the project. I can definitely see why no one had approached it to this scale before, since there are a ton of protocol messages to handle, and a lot of different edge cases that can pop up. They've gotten to the point where some of them cause problems for the client viewer itself, such as in https://replay.pokemonshowdown.com/gen8doublesubers-1286667398 (The battle analyzer will succeed and provide meaningful data for pokemon including Zoroark). The hardest part by far was definitely the reverse stat calculation though, which is not completely stable even now, as it requires you to guess both pokemons' items, abilities, and stats, which is a pretty difficult task. This is especially confusing for moves like stomping tantrum, which have a ton of different conditions that trigger base power changes.

One thing that definitely helped was the damage-calc code and I am very thankful it existed since it provided a jumping-off point for a lot of calculations with regards to special effects from abilities, items, and field conditions.

If you would like to talk about bugs or general problems surrounding the topic of replay parsing and reverse damage calculation, feel free to talk to me here or on discord (lighthouse64#5760).

Does this actually work though?
After all, the concerns surrounding an analyzer like this were not unfounded. A lot of hits end up not providing much information, simply due to the 0 - 252 ev range and variability possible in natures. However, some hits will still end up providing reverse calculations that provide a smaller range than 0 - 252, especially those that come from choiced pokemon or pokemon with special abilities. In addition, HP possibilities can often be narrowed down by looking at how pokemon showdown rounds percentages gained and lost from factors that change HP by proportions, such as leftovers and stealth rocks. From what I have seen, it will give at least some information on pokemon that play in battles of at least 20 turns. If you want to see whether or not this works for yourself though, just download the add-on from github and run it on a local instance of firefox.

Screenshots/examples

Analyzer working on a replay
1634069269440.png

Replay object behind the analyzer window
1634069582349.png

Analyzer working on an active battle
1634069112372.png

Example json from https://replay.pokemonshowdown.com/gen8ou-1257391400: https://drive.google.com/file/d/1ieZbLIgIZD2avxD6puFwjSS37xajkWM-/view?usp=sharing


Hope you found this interesting :)
 
Last edited:

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

Top