How to Get Good at Pac Man – a Coding Journey
If the ability to write code is a super power, my origin story is rooted in an obsession with classic coin-op video games that started when I was 10 years old. The DevNet team always finds creative ways to inject fun into a conference experience, when friend and fellow retro gaming enthusiast Hank Preston tweeted about the Pac Man contest that would be held at Cisco IMPACT, I went into turbo mode and spent an unreasonable amount of time practicing. Winning the DevNet IMPACT Pac Man contest means more to me than it probably should. To understand why and learn how to get good at Pac Man yourself, read on.
Introduction to Pac Man at The Pink Onion
While I had a neighborhood mom I had to check in with periodically throughout the day, I had an ’80s latch key kid childhood like you might see depicted on Stranger Things (sans the inter-dimensional monster battles). Every weekday during the summer of 1980, my dad would leave $1 for me to go spend on video games. My friends and I would bike the half mile up to the most unusual store Chino, CA had to offer at the time: The Pink Onion. It sold the strange combination of unpainted plaster statues and bicycle parts, but it also had two video games: Star Castle and Pac Man.
As anyone who has played Pac Man knows, each level has a fruit associated with it and with no Internet back then, the only way to discover what possible fruits were available was to observe someone getting to a level you hadn’t seen before. The same was true for the “cartoons” that appear in between certain levels, what modern video games now call cut scenes. You’d hear rumors about patterns that could outsmart the four ghosts, but it wasn’t until I witnessed a teenager get past my personal best of the apple level – past the grapes level (some say it’s a grenade and others a melon, but we called them grapes), past the Galaxian boss level, past the bell level, and all the way to the key levels where eventually the power pellets stop working – did I really understand how much there was to this game.
From Games to Coding
The first day of 6th grade in September of 1981 changed my life forever as my teacher brought in his personal TRS-80 into our classroom. As was common at the time given the lack of copyright law around gaming, it had several clones of popular arcade games, the best of which was a Galaxian clone. In order to use the computer, you had to complete at least the first lesson in a seven lesson self-paced course my teacher created. It started with introducing basic components (monitor, CPU, keyboard, etc) and ended with writing a program in BASIC that took in user console input and stored data in arrays. The more lessons you completed, the more time you could reserve after you finished your lessons for the day. I finished the entire course by Thanksgiving and spent the rest of the 6th grade playing that Galaxian clone daily.
It had 16k of memory, a cassette player for storage, and Microsoft Color Basic. They also got me a subscription to a hobbyist magazine called The Rainbow, which printed program listings you had to type yourself. From those listings, I learned basic coding structure, debugging techniques, and how to iterate over things I wanted to improve. Really, my 26+ year career as a software engineer started with that computer and that magazine and it was all because I so desperately wanted to play those games. In fact, if you look closely at that photo, you can see a copy of The Rainbow in the foreground of the desk and you can barely make out the game on the screen is a Pac Man clone I bought from an advertiser in the magazine with my birthday money in 1982.
How to Get Good at Pac Man
With a contest placed in front of me by DevNet and a deeply rooted motivation to do well, I researched and I practiced the week prior to IMPACT. Because of its very early AI, the ghosts in Pac Man can be manipulated by patterns, but due to their speed increasing as you advance through different levels, there are four separate patterns to learn and a few caveats.
First, there’s the Cherry Pattern, which as you might expect, is good only for the first level of the game.
Next there’s the Midfruit Pattern, which is good for the strawberry level and both orange levels.
Then there’s the Apple Pattern, which is good from the first apple level through the 8th key level.
Finally, there’s the 9th Key Pattern, which is good through the end of the 256 levels of the game, or so I’ve read but not experienced personally because through 50+ practice games, I never got that far.
When you dig into this, though, it turns out that there are different Pac Man chip sets, each containing slightly different ghost AI, and while these patterns work perfectly on the original chip set, on later chip sets they either work in a different order or not at all. Then there’s the matter of having a way to practice the patterns and the impracticality of finding a local machine given their age. For that, Hank and I both use Retropie to build retro systems out of Raspberry Pi’s although you can also use MAME on pretty much any computer you can get your hands on.
My Contest Entry at IMPACT
When I arrived in Las Vegas, my score for the DevNet Pac Man contest was going to be at the mercy of the chip set on the machine being used and whether or not there was someone among the 20,000+ attendees who knew the 9th Key Pattern. Fortunately for me, it was a refurbished original chip set machine and as the third contestant, I posted my best ever score of 174,710 dying multiple deaths on the dreaded 9th key level. A (now under control) family emergency sent me home from IMPACT early, but friends kept me apprised of how my score was holding up and after being notified that I won, I was so excited that I vowed to put this accomplishment that meant so much to me given my personal history in my email signature:
That’s my programming origin story, but it’s never too late for anybody to begin their own. Wherever you are on your coding journey DevNet has learning resources and sandboxes that can help you get started.