This is an AI Agent (using "AI" as in "video game AI" not "neural network" AI) that can play Pokémon Platinum's Singles Battle Tower . It controls Pokémon Platinum using py-desmume, and you'll have to supply your own ROM file (see Setup).
The goal is to see how far we can go in the Battle Tower. The longest streak I've done is 135 wins. The longest streak that my one of my Agents have done is 1227 wins. That would (unofficially) place it in 3rd on the Pokemon Pokémon Battle Tower Singles leaderboard But that's not enough. I want to shoot for the #1 spot, and it still has a ways to go.
After your environment is set up (see the Setup section below), the simplest way to get started is to run the following command: which will launch the A Agent and render it while the agent is running.
python run.py --strategy a --render--strategy a: This launches the Battle Tower Agent using the Only A strategy, which only ever hits the A button in the battle tower.. You can swap 'a' forsearch_v1orsearch_v2to try the other agents (see Agents for details).--render: By default, the agents are headless, i.e. there is no UI, but this renders the battles. NOTE: this slows down battling by about 50%, so if you are just going for a long streak, don't use it.
Each Battle Tower Agent keeps track of its current streak length and best streak, but when the agent stops, all progress is lost. The agent can save its progress to a database, which can be later queried for stats and plots. To run the database server, do:
python run.py --serveThis will start up a flask server for the DB. Now, in another terminal, run the agent with the --log-db flag like:
python run.py --strategy search_v2 --log-dbNow one could open up a SQL terminal or python script, write a bunch of queries yourself, and then code up some plots to visualize the results of the Battle Tower Agents, but that's a lot of work that I don't want to do. So I wrote a shell that uses Gemini to do it for you. You can run:
python run.py --visualizeAnd then enter your queries like: "give me the average # of battles in each streak".
Gemini will write and execute the code and print the results or display them using MatPlotLib.
It keeps track of the chat history, so you can reference previous commands like: "the agent has been running for a while, do that again."
You can exit the loop by typing quit or just q.
NOTE 1: You must supply a Gemini API key using the GEMINI_API_KEY environment variable to do this.
You can either set GEMINI_API_KEY directly in the environment
or create a .env file in the root directory (i.e. under BattleTowerAgent, same folder as run.py) or set `GE
NOTE 2: This works under the hood by Gemini generating code and then running that code using exec.
It is possible that Gemini can write harmful code (although I haven't seen anything like that in testing)
that gets automatically executed so just keep that in mind as you prompt it.
--log-level: The Battle Tower Agent has verbose logging (based onlogginglevels, including an extra one calledBUTTON_PRESSthat logs *every single button press by the agent). By default it isINFO, but set it toDEBUGif you want to see extra info about each state the agent reaches.--gemini-model-name: If you want to specify the Gemini model that you're using to run stats and visualize the DB.--db-path: If you want the server or agent to point to a different database, you can use this option (though I wouldn't recommend it unless you have a good reason).
NOTE: --strategy, --visualize, and --serve are all incompatible with each other, so you must run each of them on a seperate process/terminal.
git clone https://github.com/JVP15/BattleTowerAgent.git
cd BattleTowerAgent
pip install -e .I've tested this on a Windows 10 and 11 machine with Python 3.10 and 3.11, so if your setup looks like that, you're good to go. Linux support is coming (slowly). I've created the savestates for Linux but there are still some problems my multiprocessing code on Linux.
NOTE: you have to supply your own ROM, I won't include one (or a link to any) in this repo.
It needs to be a US copy of Pokémon Platinum to work with the savestates I've created.
Once you have the ROM, put it in the ROM folder and name it Pokemon - Platinum.nds (so should look like ROM/Pokemon - Platinum.nds).
Right now, this repo has 3 strategies/agents.
| Strategy | Win Streak | Usage | Notes |
|---|---|---|---|
| A | 115 | '--strategy a' | Throughout the entire Battle Tower, this agent only hits the 'A' button. There is no decision making and yet it still handily beats Palmer |
| Search v1 | 383 | '--strategy search_v1' | This is a 'basic' search that chooses each possible move, plays the game until the end, and then chooses the move that won, or at least ended the game the quickest |
| Search v2 | 12271 | '--strategy search_v2' | This uses an improved search algorithm that tracts damage dealt, searches over which Pokémon to swap to, and has a number of efficiency improvements. |
| Max Damage | 147 | '--strategy max_damage' | This is the classic "pick the strongest move" strategy |
I use a Garchomp, Suicune, and Scizor team for my agents. There is definitely room for improvement but this team has led me well both in my personal games and for these agents. You can check out the exact team builds here:
Footnotes
-
When the v2 Search agent got the 1227 winstreak, searching over the next Pokémon to swap to wasn't available. ↩
