Got my Twitters in pairs and they’re playing Gorillas

Gorillas is a classic computer game in which two King Kong-sized gorillas standing at a distance on top of skyscrapers attempt to destroy each other with explosive bananas. I spent many many hours as a kid playing this game and its companion, Nibbles, which shipped bundled with the QBasic programming language. I was too young at the time to care that their source code was available to me, but I’ve found a tribute written in Python a useful demonstration of that much more useful language.

A few months ago, Derek Arnold unveiled @GorillaCities, a Twitter bot which uses a stripped-down edition of Python Gorillas to generate and share empty cities. I was immediately taken by this idea and wanted to play along; incredibly, my first stab at a joke was rewarded with two perfect and unclaimed Twitter names. I immediately snatched them and started following the cities but my joke ended there, half-complete.

Finally, a few months later, I’ve ported a similarly stripped-down edition of Python Gorillas to CoffeeScript and now @LeftGorilla and @RightGorilla are endlessly interacting with @GorillaCities, hopping on each skyline in sequence and messing everything up.

This was a fun excuse to play with game programming and Twitter—the pair together comprise only my second Twitter bot, after @EverywordCup. And having borne them out of a browser, they also double as a captivating attract mode!

It took a few failed attempts before I ended up with a finished product. I started by hacking away at Gorillas.py, refactoring the code and removing interaction as necessary. I found myself disinterested in Python and decided to port my new code to Ruby, my language of choice in most endeavors, but couldn’t find any graphics libraries as easy to use as PyGame. After a few hours getting nowhere in a web of dependencies, I threw my hands up and started writing some HTML. This was also a good excuse to finally start playing with PhantomJS, which captures the frames of each turn as a PNG and saves them to disk. I then use gifme to turn those sequences into GIFs and a simple Ruby script on Heroku to post to Twitter and keep track of Tweet IDs (the first turn is a response to the corresponding @GorillaCities tweet; every turn thereafter responds to the previous one).

The code is on GitHub; I encourage you to follow @GorillaCities, @LeftGorilla, @RightGorilla, and me—I’m @JohnHoldun. Enjoy!