Future Sight AI

A Machine Learning Competitive Battler

What is Future Sight AI:

Future Sight AI is a computer program that chooses it's next move by looking at the possible outcomes several turns after choosing those moves and selecting the one that leads to the highest chance to win. Using the machine learning models made for the Pokemon Battle Predictor, the AI can determine how likely it is to win at the end of a given turn and use that information to rank the paths a move choice can take it down. This method, looking at turns in advance and choosing the ones most favorable to you, is the same one used by the best chess playing AIs, and now those same techniques can be applied to Pokemon. However, unlike chess, Pokemon is a game that involves random chance, information unavailable to both players, and a highly variable set "pieces" (aka Pokemon) and their potential moves. These additional factors makes creating an AI for this game in this way significantly more difficult to complete and interesting to solve. Despite those challenges, the result of the application in its current form is an AI that matches the play style of a human player, can take any team and understand how the members work together, and can beat the average player (more on that last part latter).

How Does It Work:

There are three main steps for getting an AI like this to work:

  1. Predicting an opponents move and understanding your chance to win

  2. Guess what you don't know about the battle

  3. Looking several turns beyond the current turn to see how the battle can play out

The first step was the hardest one, and also why making the battle predictor before this was crucial in this working. The predictions are used to generate a list of what your opponent will do next and the likelihoods of each. That list is important as it narrows down the different possibilities the AI must consider and gives weights to how much that action should be considered.

The second step is the easiest, and frankly the one with the least amount of thought put into it. This amounts to figuring out what moves, stats, abilities, items, etc. your opponent's Pokemon have so you can make your prediction accordingly. The way it works now is simply taking the moves, items, and abilities, you know they have and matching them to the most common set which matches those known attributes best.

The third step is the one where those aforementioned chess algorithms come into play. Since the AI has a list of its and its opponents next moves, it can run various turns to see what would happen after all the combinations of moves are ran. The way this is done is by using a slightly modified version of the code that runs Pokemon Showdown to make sure the results are identical to what would happen in the actual game. The reason the code is slight modified is to deal with the random chance as instead of choosing an outcome randomly, it will choose one outcome for that battle while creating a duplicate version of the battle that chooses the other outcome so all possibilities can be considered. Once it runs through one turn, it will find its new possible move options for that next turn, predict it's opponents move options, and run through that next turn. As you can imagine, this can quickly cascade into exploring tens of thousands of battle after only looking a few turns deep, so doing all of this quickly is key. That happens until the 15 second timer runs out, which at that point it collects the chance to win of all the different battles that stemmed from a move option and chooses the one with the collective highest chance to win.

How well does it work:

It's been tested on the ladder over a few weeks using random usernames to start at the lowest level each time and it reached up to the 1300s during its runs. Those results are with it running on a laptop using the CPU to run the machine learning models. It takes ~1 millisecond to run all the calculations for a turn where ~0.7 of those milliseconds are spent running the models, so those models are the speed bottleneck. This leads to it being able to look at most 3 turns deep in the 15 second time limit. That's probably as high as it can go given it's current setup, but, the current setup is very limiting. The program is multi-threaded and uses up all the resources on the computer easily, so just running it on a computer that has more cores and power than a laptop would do wonders. Also, running the models on a GPU rather than CPU can yield a ton of benefits speed wise. All of this is a long way of saying it may work fine now, but it has some serious potential to get better.

What comes next?

Making slight changes and implementing the aforementioned improvements which weren't made initially are the current goal. With an approach like this, there's really no upper limit to how well it can play outside of how you use the outputs of the highest chance to win models. Therefore, in the near future this project will look to run a proper machine capable of making the amount of calculations needed to reach those upper limits. Also, continued experimenting on ways to use models' outputs and adjusting the various shortcuts in play to make it run faster will happen along the way. I'd love to get people's feedback on what they think of it's play or try it with other teams, but for now what I really want is to see what this can do at its current full potential. Oh, and I guess getting it work with double battle too; just imagine what could happen if this could take on VGC...

watch the ai in action

Live View of Battle

See the Predictions and choice of the above battle

Live Predictions and Choices of the AI