All projects

project Published

Wish Upon a Block.

A low-latency online Tetris game that uses machine learning to pick pieces for the current board.

Play Wish Upon a Block
Project date
February 2026
Tools
OpenAI Codex, Cloudflare
Original article language
English

I was out of the job and I made peace with it for the time. I still had energy to create stuff, so I decided to realize something that has been in the back of my mind for years now.

Do you know what “Tetris effect” is? Apart from a visually (and audially) impressive videogame, it’s a… psychological phenomenon of sorts where, after a long period of playing Tetris, people have reported uncontrollably seeing Tetris shapes when they close their eyes. Well, I have experienced it in droves.

I usually play Tetris whenever I have just a little vacant attention budget. Watching (or rather listening to) YouTube videos, attending boring conference calls, etc. Then at night when it’s time to go to sleep and I close my eyes, I start playing Tetris in my head whether I want it or not.

The thing is, with a little effort of will, I can wish for any shape to appear in my mind, so these imaginary Tetris games always go smooth and clean. I wanted to recreate that feeling. I will build a custom piece generator that looks at the current board and serves you the piece that is more likely to be the one you want in the situation.

So I started with a playable guideline Tetris. The classic scene is built around the 1989 NES game. Pieces fall faster as you go, there’s a limit to how fast you can shift them sideways or down, and the next piece is harder to predict.

Guideline games like TETR.IO and Jstris allow instant sideways shifts and hard drops. They use a more predictable 7-bag generator. I only played the guideline one, usually chilling in the practice mode with constant fall speed, playing at my own pace. And that’s going to be the main mode I’m developing around.

Feb 2–3 · 0.1.0

I started with a simple browser Tetris using TypeScript, Vite, and PixiJS. Codex did virtually all the work. I gave it direction and feedback, and it made the revisions. That back-and-forth took a day. By the third of February, I had a playable local version.

Feb 3–6 · 0.2.0

I started taking snapshots of the board. It’s a 20-by-10 matrix with occupied cells as ones and unoccupied cells as zeros. After each piece, I append the resulting board state to a JSON, and the dataset grows.

Once I had a few thousand of these snapshots, I had to label them manually. It’s a supervised problem after all. So I built a labelling tool into the app itself. It currently lives under Tools → Wish Upon a Block. It serves you a random board state and asks you to select a piece that I would be most pleased to see next.

This approach evolved during the following days, and finally I settled on a weighted multi-label approach. You can select all the pieces that are fine in this situation, and their weight harmonically decays: the first one you choose is the “best” one. The next is slightly worse, etc. This quirk isn’t exposed to the user. It’s just too much information. The weight decay is supposed to correlate with how people choose the pieces anyway.

After that, I trained a small convolutional neural network. It is in native TypeScript on the CPU and vastly inefficient, but the training happens offline and the inference is so simple it hardly matters. On inference, it samples from the distribution over pieces, with a temperature parameter I’ve tuned to my liking.

After training on 1,000 or so samples, it started serving reasonable pieces, and I had an MVP. I bought a domain name and served the game on Cloudflare.

Feb 6–11 · 0.2.1–0.2.3

I continued polishing the app with quality-of-life stuff like options which are exposed to the user instead of being buried in a JSON file.

Options menu with key bindings, gameplay speed, audio, graphics, and snapshot sharing settings.
The game’s options menu

I added sound effects. The piece lock sound is me clicking my tongue. The line clear sound is a guitar note I recorded. I lifted from Jstris, and when you combo clears together, it results in a C major scale.

Feb 12–13 · 0.2.4

I shared the progress on joyreactor.com, which I don’t have the time to go into. The reception was mixed.

One useful thing is people wanted an option to see the worst possible piece instead of the best served. It resulted in the “Curse Upon a Block” generator, which just samples the complementary distribution. It is truly awful and, I suspect, unwinnable.

Feb 19–21

I have been continuing to label board states and retrain the generator. By now, I labelled 6,000 samples, and the returns started to be very much diminishing.

I shared the results on Reddit and published on itch.io. The reception was lukewarm, to say the least. And despite the 0.2.4 label of the project, it was virtually finished.

I was nonetheless pleased with the result and continued to play it myself for many more months.

There was also a huge rabbit hole with me trying to make a good RL bot for labelling and PvP purposes. I was at it the whole of March, but it never got good enough, and it is a whole other story.