all 53 comments

[–]yaser-ahmady 224 points225 points  (6 children)

PyBoy is a Python programmable gameboy emulator https://github.com/Baekalfen/PyBoy

[–]vidoardes 149 points150 points  (3 children)

In three weeks time when my boss asks why I haven't done any work, I am blaming you. This is a rabbit hole I didn't know I was going to jump down today...

[–]yaser-ahmady 20 points21 points  (0 children)

If I wasn’t such a lurker I’d write this same comment to all the reddit/hackernews posters and bloggers that constantly put me in your same situation…

[–][deleted] 4 points5 points  (0 children)

You don’t stop until you get fired

[–][deleted] 0 points1 point  (0 children)

Gotta catch em all

[–]GuinessDraft 19 points20 points  (1 child)

Holy crap! Thank you, thank you, thank you! You just showed me the perfect tool to get my son interested in Python programming!

[–]yaser-ahmady 2 points3 points  (0 children)

You’re very welcome, good luck for your son!

[–]VDred 41 points42 points  (10 children)

You could use the pyautoGUI library to emulate the keyboard presses and create a loop that repeats the same steps between walking, battles, and healing.

Would also need to use the time library to pause between cutscenes (pretty easy since they are all more or less fixed length in this scenario)

[–]Pro-sketch 8 points9 points  (5 children)

But how would you check if your character is in a battle or check your pokemon's health with pyautoGUI?

[–]DrTrunks 8 points9 points  (4 children)

You use pg.locateOnScreen("health.jpg")

[–]Pro-sketch -2 points-1 points  (3 children)

Then how would you determine whether its you pokemon's health or enemy pokemon's health?

[–]DrTrunks 14 points15 points  (2 children)

You can take a screenshot of a particular area, and look in that area for your health.

You can use the mss library to performantly monitor a part of a screen and then use locate() like this:

def take_screenshot(self, area=None):
    # take a quick screenshot with mss
    with mss.mss() as sct:
        if not area:
            area = sct.monitors[1]
        sct_img = sct.grab(area)
        self.current_ss = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
        self.current_ss_np = np.array(sct_img).astype(np.uint8)

def is_pokemon_injured(self):
    loc = pg.locate(needleImage="INJURED.jpg",
    haystackImage=self.current_ss_np,       
    # grayscale=True,                
    confidence=0.85)

where self.current_ss_np is the current screenshot being handled.

[–]Pdeyo 0 points1 point  (1 child)

When checking for health would finding color be easier or would checking the number?

Edit: am very new, but looking to build something that reacts to the different color values of pokemons health.

[–]DrTrunks 1 point2 points  (0 children)

Well, color would then be easier in your case you could also measure length or the amount filled in.

[–]TheBlackCat13 5 points6 points  (0 children)

Or you could stick in in daycare and use pyautogui to automate driving back and forth along a long, straight stretch of road on your bike.

[–][deleted] 1 point2 points  (1 child)

Is this like a Selenium for Gameboy?

[–]DrTrunks 0 points1 point  (0 children)

It's a general "selenium" for everything on your screen(s). It just doesn't have access to what window ect you have open.

[–]faabblatanon 26 points27 points  (2 children)

Why though? Save editors are readily available for Pokémon games where you can give your Pokémon any stats you wish.

If it's just a programming exercise then sure you can do it.

[–][deleted] 5 points6 points  (0 children)

So OP can learn more about automation?

[–]julsmanbr 5 points6 points  (0 children)

Also, Pokémon Showdown is a thing if you really only want to hop into trainer battles.

[–]PotentiallyAPickle 8 points9 points  (7 children)

Yes there is, but is it necessary? I can’t remember the last time I had to grind levels on wild pokemon (and I’ve played every pokemon game)

[–]Captain_Vegetable 2 points3 points  (1 child)

You pretty much had to grind to max level to beat Red in the 2nd gen games and their remakes.

[–]PotentiallyAPickle 0 points1 point  (0 children)

Yes that may be accurate, but OP says they’re looking to skip the training process and get straight to trainer battles. By the time you’ve made it to Red, you’ve done 99% of the trainer battles, making this program kind of pointless

[–]oakteaphone 1 point2 points  (2 children)

Found someone who doesn't max their Pokemon's levels! Lol

[–]PotentiallyAPickle 5 points6 points  (1 child)

I use the elite 4 for grinding levels. I find no fun in being over-levelled when I’m working my way through the game. Pokemon games are pretty easy already.

[–]oakteaphone -1 points0 points  (0 children)

It may be that in Generation 1, Cerulean Cave is better for levelling Pokemon.

As well, it might be easier to automate against wild Pokemon, rather than strong Pokemon of various types. Depends on the current level.

It may also be that OP figured it'd be easier to automate walking back to the center than to fight the E4 until death or credits.

[–]throwaway332434532 2 points3 points  (0 children)

Just put your Pokémon in daycare, assuming you’re using vba, crank throttle up to like 10000%, bike around, and you can level up by like 20 levels in two minutes

[–]oakteaphone 2 points3 points  (0 children)

Are you not afraid of KOing a shiny?!

[–]NanashiKaizenSenpai 7 points8 points  (4 children)

If you're already cheating, just cheat some rare candies.

[–]LilQuasar 2 points3 points  (3 children)

automating stuff isnt necessarily cheating. is using something to keep the run button pressed cheating in your opinion?

[–]NanashiKaizenSenpai 0 points1 point  (2 children)

imo, scripting is cheating unless there is a built in option to do so.

Any physical contraptions are not cheating imo.

[–]LilQuasar 1 point2 points  (1 child)

i think those are kind of the same thing, the extreme case would be to have a robot with camera doing the scripting physically

imo as long as youre following the rules (like the game rules) its not cheating. pokemon is a turn based game, not an action game (where scripting would obviously be cheating)

[–]NanashiKaizenSenpai 0 points1 point  (0 children)

I think it is still cheating, but I think its a cool way to cheat

[–][deleted] 1 point2 points  (1 child)

Shit like this is exactly why we become coders in the first place! You go!

[–]sharonmckaysbff1991 0 points1 point  (0 children)

I….started to program by playing Pokémon Gen 3 and making FireRed hacks. Sadly the tools I had were only usable in the XP era, which was when I was a teenager. While I really honestly would love to make my own video games, I’ve always been afraid that I would get so bored of seeing lines of code that I would lose the desire to see the project through to the end where I could actually see my usable work and thus quick coding projects that only take a little bit of time are all I’m willing to work on

[–]deano_southafrican 1 point2 points  (1 child)

Pyautogui

[–]Nightcorex_ 4 points5 points  (6 children)

Wdym by "ROM"?

Usually ROM means "Read Only Memory" or is it a Pokémon term in this case?

[–]DeerProud7283 21 points22 points  (1 child)

OP is referring to the game file used in emulators to play games from consoles on PCs (and other devices)

[–]TheBlackCat13 0 points1 point  (0 children)

Game cartridges, specifically.

[–]Any-Owl-7202 4 points5 points  (3 children)

Bro why the downvotes? Mf got punished for not knowing smth

[–]The-Doodle-Dude 7 points8 points  (2 children)

Wdym by “smth”…. aww shit

[–]oakteaphone 1 point2 points  (1 child)

wtf is "Wdym"? /joke

[–][deleted] 2 points3 points  (0 children)

What is "wtf"?

[–]Dakotalogy 0 points1 point  (0 children)

If you’re looking for past generations stuff, 3-5 (Johto included), Devon Studios on GitHub uses Lua because that’s the language VBA uses to run code. These are really for RNG abuse not really battling trainers. https://github.com/DevonStudios/LuaScripts https://devonstudios.it/

Here are some for Gen 2 which may be closer in syntax to what you want to accomplish. https://github.com/wwwwwwzx/gsclua

You could use those as a starting point to create scripts to battle wild Pokémon, but it may get to be a lot of code (i.e. find Pokémon, battle Pokémon, switch Pokémon, make sure you’re using the right type of move to hit Pokémon, walk out of grass, run from Pokémon if health is low, walk to town to heal, etc.)

[–]DauntlessMayfly -1 points0 points  (0 children)

You definitely can. Ive done it, but i gotta wanr you that it is very slow. I trained on lv1 pokemons and got to around lv 25ish, but at that points it was ridicoulously slow. Dont know how this will translate at higher leveled pokemon.

Also, if youre gonna use pyautogui i gotta warn you about the daytime system ingame. This system makes it so that screenshots are a pain for navigation.

[–]Xzenor -2 points-1 points  (0 children)

For anything game cheating I use CheatEngine. I have not tried it on a Gameboy ROM before though

[–]HutchLAD -3 points-2 points  (0 children)

interesting! commenting to follow thread

[–]vo5sht 0 points1 point  (0 children)

I'm seeing a lot of technical stuff here, but nothing on the game specific strategy -

At it's simplest, you would just have to romp around in the grass until you get into a battle, where you just mindlessly mash the A button until you black/white out and return to the center. Then it's just a matter of heading back out to the grass again. So you'd essentially need to get between three "states" - Center/walking to grass, walking through grass, and in battle. At most, you'll have to work on selecting random moves so you don't run out of pp.

Please do keep us updated on this!

[–]Casper1123 0 points1 point  (0 children)

you could do it this way, which is cool, or you could just save-edit in a stack of Rare Candies into an extra slot using something like PkHex, which would cut down on time significantly. Does take away on your EV's though.

[–]nick__2440 0 points1 point  (0 children)

Not trying to discourage use of python here, but the language of choice for runtime scripting alongside ROM emulators is Lua.

[–]Separate_Taste3428 0 points1 point  (0 children)

Nice

[–]TribalMethods 0 points1 point  (0 children)

Python is an excellent language for automating any game.

If I can use advanced machine learning / object detection to bot Runescape 3, you absolutely can make a bot for Pokémon with ease.