Development, Games, Machine Learning

Logarithmic Tetris

I have a tendency to collect notebooks. Under a pile of pillows in my office-slash-guest room is a large box, filled with notebooks of varying stages of completeness. Every so often, I’ll pull one out and take a look, and if there are blank pages, it makes it into the rotation.

One notebook that I’ve been holding onto for a few years is a strange one. The Grids and Guides notebook has a lot of unusual page types, including charts, lists, and – my most perplexing – logarithmic graph paper.

If you’re someone who can understand how to manually graph something on a log scale graph, teach me! I have no idea. Naturally, I decided that I’d just doodle on those pages, and I found myself drawing distorted Tetris pieces. I showed my husband and told him that I wanted a version of Tetris that had a logarithmic board instead of a square grid, and he thought it was hilarious.

I couldn’t get the idea out of my head, so I turned to AI.

Please generate the code for a simple client-side web application that lets me play a basic version of the game Tetris, with one change to the game: instead of a 1:1 grid, the grid that the game is played on is a logarithmic grid. When the pieces move across the grid, they should visually change size to match their current placement within the grid. The app should be entirely self-contained in a single HTML file, and be written using standard javascript.

The prompt above got me a rough HTML file that outlined the canvas and made a simple board. It had gotten just about everything wrong. The pieces were complete nonsense, you couldn’t see the grid, and every time the piece hit the bottom of the screen, everything would reset. Sometimes three pieces would cycle through at the top of the screen before one would finally drop. It was a complete and utter mess.

After a few back and forth exchanges explaining the problems that I was seeing with the game, I was able to get a functioning, basic version working. At first, I had to be very explicit about what I was observing. ChatGPT would generate complete pages for each of the prompts, and I would have to dig into the console or read the code to figure out what was likely happening.

After about forty five minutes of conversing with AI and updating the HTML file on my local computer, I had an almost functional version of the game. Getting the code to match the size and shape of the piece to align with the grid was a bit of finnicky math, but not something I had to worry about. As it turns out, this is something that language models (at least the ones trained on GitHub’s open source corpus) are pretty good at when they have concrete instructions.

The first working iteration of the game was basic, but delightful. I marveled in the color choices that ChatGPT made about the project, thinking about how this machine had no way of appreciating what it was we were doing. When I had the first playable version of it running, I couldn’t help but type my enthusiasm into the chat. To my… embarrassment? delight? ChatGPT congratulated and complemented me on the accomplishment. I hadn’t written a single line of code!

I spent another hour on some lifestyle features, adding the ability to pause the game, creating an avatar and color palette from an image that I had generated a few weeks prior, and, at Zach’s request, adding the hard drop capability. Then, I put it all on GitHub. You can view the source code here.

Oh, and if you want to play it, you can do that too.

All in all, this took me about two and a half hours total.

I have a degree in Computer Science and familiarity with architecting software programs. While I have a strong sense of how to define what I want from a program, and the ability to read, modify, and run code, my ability to write net new code is slow1. I’m just not practiced in it anymore, and with generative AI, I don’t know if I ever will be. Would I have been able to write this without AI? Yes. It just would have taken me far longer to do, and it wouldn’t have turned out this nicely because I wouldn’t have been as patient in putting it together.

I feel a little bit weird about this. In general, I think that the ability to generate code will lead to a future of “disposable bits”, or single-use programs. There will be a large spectrum of software created, accelerated and augmented by these generative models that can “author” the algorithms and functions that power applications. Open source code was licensed freely, but it’s become economically disincentivized to produce, and, as evidenced by this project, the backbone of commercial enterprise offerings. It’s a moral gray area, and something that I’m continually thinking about.

But there is definitely something magical about a sub-24 hour turnaround from concept to reality. And that was on top of a full work day, while my eight month old continues to refuse to sleep through the night and had me up every 90 minutes all night.

/dev/ori

  1. Interestingly enough, this is the same challenge that I’ve had learning spoken languages. My ability to read, write, and comprehend far surpasses my skill in speaking a language. ↩︎