Dr James Wootton

@decodoku

Game Jamming on a Quantum Computer

There are many things you’ll be able to do with a quantum computer. Messing around and doing something fun is one of them.

Over the past few years, I have been one of the main misusers of quantum computers. Among my projects are simple games and quantum superpositions of smileys. Others have also done similar things, including quantum music. Together they demonstrate many ways to use this new technology for something creative.

So I had an idea. I’d take the quantum heart of each of these projects, and abstract it out to a simple class or function in Python. This set of tools would then allow even more people to make even more creative quantum projects, without needing to worry about the technicalities of programming the devices themselves. It could provide an easy way for quantum novices to do quantum things for hackathons and game jams.

I liked this idea, and thought about it quite a lot. It was a nice idea to think about. I didn’t actually do anything about it, though. I needed something to spur me on. I needed a deadline. So I committed myself to making the first ever quantum game for the Ludum Dare 42 game jam.

On the day before the game jam, I quickly hacked together some basic tools from my first few quantum games. The project had finally started! The github repo had been made, and had more things in than just a README.

Then I just needed to wait for the theme of the jam to be revealed. At the stroke of midnight, as Friday became Saturday, it came.

There was no way I could think of to make a ‘Running out of space’ game with any of my existing quantum tools, so I needed something new.

When thinking about the word ‘space’, my mind quickly lept to ‘Hilbert space’. This is the space of possible states for the qubits in a quantum computer. Usually we start out with all our qubits set to 0. So if we had 5 qubits, we'd start with the state 000000. This is just a single point in the Hilbert space.

A short quantum program can then start to explore nearby states, like the ones that differ on only a single bit: 0001, 0010, 00100, etc. These states, as well as all the quantum superpositions of them that we can also create, form a small region within the Hilbert space. Then, as we make our program ever longer, we create more possible states and slowly explore more and more of the Hilbert space.

That’s basically the exact opposite of the theme for Ludum Dare 42. We are supposed to be running out of space, not expanding! So let’s run our programs in reverse. Start with something that can create crazy complicated quantum states, and then delete a few lines of quantum code from the end of it. Keep on doing this, and the output for our program will describe a slowly shrinking region of the Hilbert space.

That’s the basic quantum idea. Now how to make it into a game. To me, it lends itself quite natural to something like Hunt the Wumpus. This is an early precursor to games like the Legend of Zelda, where the player explores a labyrinth, trying to find a monster while avoiding dangers. With Hunt the Wumpus, it is all text based on the command line. That also suits me quite well, as I didn’t have enough time to do much in the way of graphics.

Now for the narrative. Quantum mechanics is famous for being a bit odd, and there are many interpretations of what is going on. A popular one is the many worlds interpretation, which basically states that quantum superpositions should be thought of as parallel universes.

I’m not convinced by this interpretation myself, but sci-fi has shown is time and time again that it makes for good storylines. So we’ll say that the large and complex quantum state we begin with represents a multiverse. As the program used to create it gets undone, this multiverse slowly collapses in on itself. If left to continue, only one universe would remain.

The player’s job is to save the multiverse! They must hop between neigbouring universes, avoiding ones that have collapsed, and trying to find the cause of the problem: the Quantpus. Once they find it, everything can be saved.

With this basic idea, I created the game (Actually I came up with the idea while making the game, resulting in dead-ends and spaghetti code. But reality doesn’t always make a good narrative.) The quantum program required was written as a new tool in my creative package. Like all the rest, it was written using the QISKit quantum SDK (which has its own publication here on Medium)

I then ran many different instances of the quantum program on one of IBM’s real prototype quantum devices. The data from these runs was saved so that it could be used in the game, giving players the genuine experience of playing on a real quantum computer without them needing to bother setting up the connection. The rest of the program was then just normal Python for normal computers, handling all the inputs and outputs, victories and losses.

The final product is still quite raw and buggy, but there is a game in there somewhere. And it’s a game that actually runs on a quantum computer. I’m pretty confident in saying that Ludum Dare has never had one of them before. If you want to play it, check it out here.

More by Dr James Wootton

Topics of interest

More Related Stories