HOW Future Sight AI Works
Below is a modified version of the script for the video above to add content cut for time and make it more suitable for reading. Parts which are not found in the video are marked with this background
How an A.I. is Becoming the World's Best Pokemon Player
Competitive Pokemon’s Depth
Applying Machine Learning to Pokemon
Seeing a Battle’s Future
How Future Sight AI Did
Here's something even the most dedicated users of Showdown haven’t seen before. When you play against a random opponent, you're giving a rating based on how well you’ve done against other opponents. This is a graph of how many people have each of those ratings. Now this system does have its flaws, as people’s ratings tend to fluctuate quite a bit. I was able to mitigate that by not only making sure it plays plenty of games, but also play enough games until its rating became stable. As for how I got this information, because I had that system setup to download battles off Showdown daily, I found myself with a mini database of all of Showdown’s battles. This graph won't reflect every battle, but this does represent 50,000 battles in the past month, so this should be more than enough to make a good estimate.
For our analysis I added the yellow line to the graph which represents what percentage player you are when you're at that rating. I also shifted the graph over by 1 rating as to start at 1001 as the number for players at the base rating of 1000 is filled with far too much noise as there’s a high chance the other people who used the system once and left. I provided a picture of that graph if you want to see it, but that also means if used this graph to come to my conclusions, all of those points would be at a much higher percentage of the player-base. The extra points I have on that graph are there for you to see where other relevant battlers place in their ratings. Might notice that my reading, despite being the creator of the AI, is quite low. That's because despite playing competitive Pokemon for the better part of the past ten years and knowing way too much about how this game works, I’m just not good at the game. Obviously, I'm not going to compare myself to a computer that has perfect knowledge of every aspect of the game, but I think this still works as evidence that just because my AI will know exactly what the game can do, there is more to this game than just knowing how it works to play it well. As for the random moves, during my runs with the AI, I wanted to generate a baseline of what it would do if it wasn't working at all. They were to do that, I said it too randomly choose games where instead of using the AI, it would just pick random moves. I was considering having a separate bot start from the bottom of the ladder and see how high it can go, but doing so would have caused a lot of fluke wins and I wanted to get an idea of what random moves could do on the level of the I was playing at. At the end of the four runs that constitute the AI's current version, there were 60 battles in which it shows exclusively random moves. Of those 60 battles, it won zero. Now, I'll be the first to admit that winning zero of those battles is an anomaly as after that many either somebody should have forfeited or the game's random chance might have played in your favor. However, since winning zero out of 60 was even a possibility, that was more than enough proof to me that you must be far better than random moves to even have a chance.
Another point of context I gave is from Showdown itself as they do publish some of this information but only for the top 500 players in the world. And as I'm writing this, the rating of player 500 has moved slightly to 1706.
Now, the AI’s average rating is 1547 and its maximum rating is 1630. That average rating puts it in the top 10% of all players and that maximum rating puts it above the top 5% of all players. These numbers come from the aforementioned four runs I did of the current version where each run is the AI battling random opponent’s every 24 hours. Between each run, I intentionally lost enough games to drop the AI’s rating by 100 points to see if it could climb back to where it was without the benefit of the starting bonus a previous run might have given it. In retrospect, I should’ve had the AI start at the same rating each time, but it’s quite difficult and time consuming to move your rating to a particular spot as if you did too low, getting back up to the starting point might be a challenge in itself. And the thing about it getting to 1630 is that means it was remarkably close to being in the top 500 in the world. Also, the entry into the 1600s is not even an anomaly as that 1630 rating came three weeks ago but then when I ran this a few days ago it got back to the 1600s no problem!
Now I do want to clarify that just because it has that rating does not mean it's going play well every time because there are still some vital gaps in this logic and to fundamental parts of what it does which are still holding it back. The first is the two, and this is truly a topic onto itself that will have to save for later, is that the AI build its own teams. If you watched the video, you might have noticed I left a long pause after I said that because the importance this cannot be understated. It's very much so believed that team building is far harder than battling, so for the sake of completeness in making sure FSAI can handle everything that goes into playing this game, I'm potentially putting it at a great disadvantage for having it tackle the harder side. In short it does so by trying to create a well-rounded team that counters the Pokémon it thinks will see more often while also not being countered itself. For right now, I have it playing safe; FSAI can pick whatever Pokémon it wants for a team, but each Pokemon’s set doesn't deviate that far off what’s standard as I’d just have all its teams be fine rather than risk making bad ones.
Now the second part is a little more complicated. Since I knew the AI would be playing against people in a bunch of different skill levels while trying to raise its own rating, I programmed in a way to make it play differently against those of different rank. You can't simply approach different player levels the same way and expect to win as, for example, the worst players might go for that obvious move you wouldn't expect a better player to. This might be a byproduct of how I set up its runs, but it seems like this programming had unintended consequence.
One would expect that the AI would win more against worst players and lose more against better ones, but, when I looked at it wins and losses when they were grouped by player ranking, it seems like they're all close to 50%. That means it may have played to its opponent skill level which I guess is useful in its own right, but I would have preferred if it, you know, played better! I feel like with only a little adjustment I can get it out of the state, but for now, it has this weird limitation.
Inverse Damage Calculation
This pointed out that I wasn’t doing anything to determine what set of stats, moves, items, and just everything that your opponent can change about their team. Realizing I hadn’t addressed such an important part of playing this game, I started down the path of discovering just how much information you can gain about your opponent’s team that you’re not directly told, and the first stop was inverse damage calculations.
That’s a term I use to describe finding the stats of your opponent’s team based on the amount of damage that both sides do to each other. This is best explained through an example. Here’s a situation where our opponent does damage on us. When you click a damaging move in Pokemon, the amount of damage done is determined by this equation with the main components being the power of the move, its users’ attack and level, and its target’s defenses. We only run inverse damage calculation once the damage has already been done, so we can rearrange the equation to find the attack stat which caused this amount of damage. Since the game tells us our opponent’s level, we know our own defense stat, and the power of the move that hit us can be looked up, there’s only one more number we need correctly find their attack stat. However, that number is where things get complicated. It represents the general damage modifier which is the product of potentially dozens of known and unknown effects happening during a battle which change how much damage a move can do. The two effects that can have the greatest difference, yet we have the least likelihood of knowing, are from the item the attacker is holding or their special ability.
There are a ton of different items and some abilities which effect how much damage an attack can do, which could make sorting which ones they currently have a tedious process. But, if we combine the knowledge of how much each of them modify damage with what the opponent’s Pokemon most commonly has, then we can efficiently find their most likely combination of item and ability which makes this equation return the Pokémon’s possible stat.
Now I do understand I don’t need to get exact stats as an estimate’s probably good enough, but there’s just too many guesses this computer needs to make for me miss an opportunity to find something it can know for sure.
This is by no means an exact science and there's a lot more that can be done in this area, but this already goes an exceedingly long way in making its predictions more accurate.
Now I said there were three tasks that made this AI work, but there's actually a fourth. I’ll tell you what it does, but the how will have to come later since I only finished it recently and it’s gonna take some time for me to put it into words. Consider this; all three parts I’ve mentioned exist just to help the AI look through thousands of future turns, and although it’s a good strategy, I couldn’t help but think there must be a more efficient way. While writing the code to help the AI get more out of fewer turns, I realized that with a few changes, it could also be used to help guide the machine learning predictions. And after a bit of testing, it appeared this guiding code, on its own, outperformed the machine learning models not just in accuracy, but even more so in speed. It was such an improvement that the AI in its current form doesn't use machine learning at all. I still don’t know if that’s a good thing, but because of this 4th phase, the AI transitioned from doing well because I could think ahead, to doing great because it could think… sideways. It should be noted that this part of the video was filmed two months ago, so I have made a bit of a dent in being able to explain this. Basically, the machine learning models had its weight trained on certain on a battle format as a whole and then those weights were set in stone for every battle. That's fine as it gives you a general idea of how important things are, but with a game that varies as much is this one from battle to battle, those values being static could result in misguided decisions. So, I wrote code that could analyze the battle on its own which resulted to similar behavior to if the AI calculated those weights on the fly; it no longer understand the game on a format-by-format basis, but rather on a turn-by-turn basis. The code allows it to be far more dynamic in its analysis of the game and therefore improve all its predictions. And, because information no longer has to go through the machine learning, TensorFlow pipeline, it can skip a large part of its speed bottleneck and be way faster.
I could keep going forever on this cause for every five lines of code, I feel like I could probably add a page to this script. And considering there’s almost 20,000 lines in here there’s so much more I could dive into; I didn’t even talk about how physically plays the game! I’m definitely making this topic an on-going series on this channel, it won’t be every video, but expect this AI to stick around, so I recommend you do as well.
Battle the AI!
In the meantime, how would like to battle it yourself? For the week of this video being uploaded, Future Sight AI is open for challengers. All you have to do is go to Pokemon Showdown, type in its username, have a team ready in one it’s supported formats, and get ready to see what it’s made of firsthand. If you’re not the battling type, you’re already in the right place as if you switch to the main Future Sight AI page of the website, you can see it battle alongside its analysis of. Also, it should be noted it will be running at its absolute lowest performance setting, which still should be fine, but I get if that’s disappointing. that’s just how it has to be since if I had this thing running for a week at full strength on a server, the only thing this AI would be beating is my wallet! But if you’re really interested in challenging it at its peak, just hit me up and I’ll see if we can make something work.
I do have every intention in making it be able to play against others in the official games on Switch as it should be straight forward if the computer can read a screen, so that’s one thing I can guarantee is in this AI’s future.
Speaking about the future, yes, doubles is coming.
In case you don’t know, the format of tournaments hosted by Pokemon themselves is for battles where instead of having one Pokemon out per side, there’s two, and I am so ready to take on that side of this project. I tried to keep doubles in mind while coding and have most of the ideas how to implement it worked out, and really the only thing stopping me it will just take time. At the end of the day, I'm just one guy working on this, well, for now, but talking about stuff like that is what Friday’s for.
As for my other plans, I do have some fun things in mind like seeing how well it can play through the story of one of the games. And, of course, there’s no shortage Pokemon challenges I could apply this to and maybe see if we can find best solution to certain some of them or push the limits of what challenges we think are possible by throwing it at some tough ones.
But, I have my sights on a particular problem I’d like to solve once and for all. There is a popular quote amongst Pokémon fans, that frankly I believe applies life in general, that paraphrasing says if you’re truly skilled, you can win with your favorites.
And there have been several people that fit this truly skilled criteria who’ve tried being the proof. But their success or failures can never make this definitive. And that comes down to always not knowing who’s the weakest link; is it players on either side as even the best have bad days, is it your team as their sets were not the best they could be, is it both?
However, a computer which can not only keep its play consistent, but consistently good fixes both those problems as the AI won’t make a wrong calculation, or forget a mechanic, or just get tilted or anything. Also, through some more coding, the AI could be applied to find the best possible sets for a particular team. With all that in mind, I think this might be our best chance to see this through. As for what team to use, over the decade of playing this game, I’ve developed a pretty concreate idea who of the team of 6 I’d want to put up to this task. They aren't all my favorites, but collectively, they make up my favorite team. In its current state, Future Sight AI isn’t ready to do this question justice, but one day, when I’m ready, they'll get their time to shine.