I wanna be the very best: A second Pokemon automation attempt

I wanna be the very best: A second Pokemon automation attempt

After a bit of time off blog posting and watching a never-ending YouTube stream of personalised content, I still had this thought bugging me. This ... obsession. Surely, there must be a tool out there (i.e GitHub) that I can use to programmatically complete a play through of Pokemon. I couldn't let this go. And so, I decided to give this challenge another crack. Enter "SkyEmu".

SkyEmu is a GBA emulator that allows a local server to receive input commands sent by code. Using this method, I can send a sequence of commands to perform button presses. For this attempt, I'll be using python.

As always I like to complete my work in checkpoints. This allows me to

  • complete a goal in a reasonable time-frame
  • have functional code upon completion
  • use my last git push as a checkpoint to commence again in future

Using SkyEmu, I can form a sequence of button presses to be executed in python to simulate a user playing the game. Initial results are positive. Press A, go here, move player there. What can go wrong.

I decide to begin this second attempt by starting the game in the players room, right after the new game prompts have been completed. The first thing as a player you do here is leave the upstairs room to head downstairs. Simple enough.

Being a 2D tile-driven game, the player moves around in tiles. Each tile is an individual square. In this very first room sequence, there are 11 button presses that need to be performed. These presses are used to traverse the 11 tiles pictured above. Below is the output of that function.

def navigate_roomStart_to_downstairs():
    print(navigate_roomStart_to_downstairs.__name__)
    pressButton("Right")
    pressButton("Right")
    pressButton("Right")
    pressButton("Right")
    pressButton("Right")
    pressButton("Up")
    pressButton("Up")
    pressButton("Up")
    pressButton("Up")
    pressButton("Left")
    pressButton("Left")
    time.sleep(delayBetweenStairs)

I also include a short delay at the end, to wait for animations that play when transitioning between locations. At this point, you could see an issue building. My script is going to need to contain a massive amount of actions to navigate across all the tiles in the Pokemon world. One can only imagine the number of python lines needed to traverse Safari Zone, Silph Co and Victory Road. I mean, check out what's needed to navigate through Viridian Forest!

Credit to psypokes for the map references.

At this point I figured I might need to rethink my options. No matter how many levels of abstraction I include in my python scripts, at least 1 of them will contain this +100 line sequence, not to mention the many other areas in the Kanto region.

SkyEmu is a great option for providing a defined set of steps that can execute without fail. I see games like Sonic or Crash Bandicoot as potential automation candidates here too. However, I don't have any means to read game RAM data to look into the game states. I have no idea if I'm in a battle or I'm walking into grass, meaning all the button presses for steps are useless if I'm stuck fighting wild Pidgeys without me knowing.

There are plenty of other challenges to be frightened about to:

  • how to deal with wild encounters
  • how to progress through battle scenes
  • how to successfully catch a Pokemon to use HMs
  • the list goes on!

Yeah it's not looking too positive at this point for Pokemon 😓. One way to progress a little further would be to use cheats to disable random encounters and have infinite items. This removes some of my blockers, but I would still need a way to fight trainers and choose moves. And, it just wouldn't feel right to use cheats in this challenge. As they say, "it ain't a challenge if there's no hard work." i.e no pain, no gain.

Well I have gained something with this challenge. It's a gif recording of the player existing the starting house. All the print logs on the right are individual buttons presses. What a win!

oh yeah, a codified Pokemon challenge

Outside of the gif, I managed to get to the point of selecting a starter Pokemon. Of course I was thinking Bulbasaur to speed-run through the first 3 gyms. I have the full code available here for those interested in seeing a 140 line file for <5 minutes of actual gameplay.

Sadly, SkyEmu will be joining Maestro in the fail column however I will continue searching for the tool that can do it all.

Next up in this Pokemon related series is a look at disassembled Pokemon game data. I'll be exploring the data available, such as trainer teams, AI choices and other game logic. Stay tuned!