Getting Distracted by Side Projects

It all started sometime last week; I had just awoken from my nightly slumber, and after staring at the ceiling for a couple of mins to give my brain time to boot up my bodily systems and function for the day, I rolled over to grab my phone. I opened the PokĂ©mon TCGP app and BOOM!! There it was, the Mythical Island Booster Pack! With no less than my absolute favourite PokĂ©mon, Mew, gorgeously gracing the cover đŸ„č

Mew on the cover of the Mythical Island Booster Pack

So, I obviously and excitedly ripped open the new pack as soon as I could
 and no Mew. I opened about 6 packs in the subsequent days, but no Mew. I returned to Threads to find my feed awash with other players who were swimming in elation after opening “Gods Packs” containing multiple iterations of my beloved Mew. It pissed me off! So much so I yeeted all the gold and Pack Hour Glasses I had been accumulating for months to force open a 10-pack, and still, NO MEW 😔!

The 10-pack dud was the last straw! I deduced that such a statistical anomaly could only mean one thing: the game devs had purposely singled out my account and banned me from acquiring Mew
 and I was not about to take that laying down. And so, I decided to build my own version of the game that simulates opening a Booster Pack—giving myself Mew every, single, time 😠!

Thanos I'll do it myself meme

The Language

I actually started building this thing in C, and that’s only because it’s the language I’m most comfortable with. So when I start picturing things in code, I do so in C. And it was going great to be honest, up until I got to the point where I had to build my own function to parse the JSON data. And I mean, I was salty, but not saltine enough to deal with all that jazz—Python was always the only option for me 🙄

C memory leak meme

Python programmers laud the language for its speed of development. For me, I find that sentiment to be both true and untrue at the same damn time. True in the sense that you can write a “Hello, World!” program faster in Python than you can even think about it in ANY other language. And false in that if your program is any bigger than 4 lines of code, the simplicity of Python’s syntax gets more and more complex with each additional line.

What in the Indentation is Python All About?

In my poke_play program, there’s a method called [load_booster_pck] in the [PokedexAPI] class (built to receive & process the API Data) which returns a list of 5 random selected PokĂ©mon. It is the literal crux of the whole application. If it was unable to return that list, none of the logic in my main function would work after asking for user input. And for hours, I COULD NOT GET IT TO WORK!

Python code

No matter how long I stared at my source code; I could not figure out why main wasn’t getting access to a list being returned by a method in a class that was clearly instantiated in main’s very first line!! If you’re a non-technical person, that probably sounds like utter gibberish. But take my word for it. As far as I could see, I did everything correctly, but my code still wasn’t running as expected


Python code meme

Of course, the truth was I hadn’t in fact done everything correctly, or at least not in the Pythonian way. The reason main couldn’t access the list even though there was an instance of it on the very first line; the reason half the variables I declared in the PokedexAPI class seemed scooped to themselves, the reason my code wouldn’t run as expected after 4 straight-hyper-focused hours of writing it, was all because of some gosh darn indentation errors. It’s not even funny, it’s actually ridiculous. The human eye was not built for readily identifying indents 😭!

Take this meme below as an example. It’s meant to be funny because the two blocks of code are exactly the same, but the fact that Python made me stare at this image for 15 fucking minutes to deduce that is objectively insane!! Also, the really funny part about that is both blocks of code would fail because the person who made it forgot a fucking colon on line 5. Sigh; excuse my French, I shall begin to digress 😞

Python indentation meme

I mean, as an old web dev, I used to find the JavaScript “missing semicolon joke” to be extremely hilarious. Mostly because JS was getting dragged for something it correctly inherited from C. But Python’s indentation syntax is the absolute worst solution to anything I’ve ever had the horror of seeing in my life—especially for something that was never a problem in the first place. Opting for indentation over curly braces was a mistake, and I hope Guido van Rossum knows that.

The Main Logic of My Code

They say the Python Programming language is so close to natural language that you don’t even need a main function. But if you actually want to write a program bigger than 10 lines with it and also keep your sanity, you will absolutely need a main function!! Anyway, as mentioned previously, my main starts with an instance of the fabled PokedexAPI. Next, I use Python’s input function to ask the user for their name and strip it of any trailing space.

The simple control flow that follows is where all the magic happens. If the user name entered is specifically mine, then the [load_booster_pck]method will instantaneously return Mew followed by 4 random cards to make 5. ELSE IF it’s any other username, the method simply returns 5 random cards. An absolute genius, aren’t I?

Python code

Getting All Up in that API

After about 2 days of reading the PokeAPI doc as much and as often as I could, I now feel I know more about PokĂ©mon than I ever have before. Which does actually feel incredible. I learned things like the fact that they’ve issued exactly 898 PokĂ©mon IDs to new creatures as of Generation 8. And the reason Mewtwo’s ID is 150 while Mew’s is 151, although Mewtwo is Mew’s clone, is all because the original game devs planned for Mewtwo to be obtainable in-game as the last all-powerful PokĂ©mon, and thus was given number 150. But Mew was created very shortly after as a buff that could only be had through special events.

However, since the source code for the original game had already been written and shipped. The devs had no choice but to give Mew 151. In a nutshell, the devs finished writing their code before the storytellers finished writing their lore—typical behaviour from both fields.

Writer's block meme

Throughout this return to coding journey of mine, someone dear to me commented how they weren’t surprised by my love for coding once they found out that it involves more reading of docs than writing of code. And my love of stories is something I never connected to my love of code until she pointed it out to me.

Which leads me to my personal favourite block of code in the whole base. It’s the [get_pokes] method! A simple function in the API class which does a try-catch API call. For as much gripe as I’ve given Python in the first half of this article, it has to be said was a joy writing this was!! I think too much abstraction in programming is just as wrong as too little abstraction, and I also believe what is too much or too little is totally down to personal preference. And Python having a built-in library specifically for handling API calls and parsing JSON data, is exactly the amount of abstraction you need to build a CLI game real quick in a fit of anger.

Oh, and I set the timeout on the response to 69 seconds, because I’m the type of guy to sit and stare at a cursor blinking on a blank screen for a minute and 9 seconds just to have a little chuckle once that code ran đŸ€·đŸœâ€â™‚ïž

Python code

That’s All I Wrote

That's all folks! The actual game itself is nothing more than a terminal application that simulates opening a PokĂ©mon TCGP Booster Pack in plain text. It’s fun for about 10 mins and then you’ll get tired of it, but the fun I had writing it will stay with me for a long time.

I guess anyone is welcome to try it out for themselves, it’s half the reason I put it on Github. But honestly, I really wouldn’t recommend doing that unless you’re a technical person. Running code from a random box on the internet directly on your personal machine is always a bad idea if you don’t know what that code does.

But, if you DO happen to be a follow programming. Please, clone the repo, run the Python executable, and tell me what you think. Full source code on Github: poke_play_app