April 26, 2024

Learn Computing Through Games

How much could you learn about computing and programming through playing games? How much, specifically, could you learn by playing games available through steam that will run on a 3-year old laptop running ubuntu? This is the question I have set out to discover the answer to.

I will note here at the top that I’ve not played all of these games in great depth, so I might be missing aspects of the later stages of the games. Also, I often play with the sound off, so I won’t be commenting on the sound effects or music at all.

You might consider this something of a sequel to my earlier post about more straightforwardly pedagogical resources for learning to code.

Games that teach you about circuits

Let’s start at the very basic level: computers are built out of wires and logic gates. There are a number of games on steam that let you play around with computers at this deep level.

There’s Turing Complete which turns learning about computer architecture into a puzzle game. I learned a lot from playing this game, it’s great. The story is that you have been kidnapped by aliens and they are forcing you to build computers for them. A recurring theme of this post will be that story is not a big part of these games appeal, and little effort has gone into that aspect. The game looks a little plain, but it’s really a puzzle game about blocks and wires, so it’s mostly blocks and wires. I do like the way the wiring does sort of end up looking like wiring on a circuit board. The editing of your contraptions feels nice, and you can copy sections easily.

You also have The Signal State which focuses more on signal processing, but you also end up doing quite a bit of logic. This is maybe a little bit removed from how an actual computer works, but lots of devices that turn analogue signals into digital or vice versa probably use the sorts of techniques that are useful in this game. As far as stories goes, this one is a little more interesting in that you’re in some sort of post-collapse world (post apocalypse? unclear) where you’re entrusted with rebuilding the electronic systems of an old farm. The early story hints at mysteries that might be revealed later. I haven’t got too far into this game yet, so I don’t know how satisfying a conclusion the story will have. The gameplay ultimately involves dragging wires across from inputs to outputs of the components set up in your rack of gear. It looks pretty good, but it’s not easy to see what’s doing what. I had some weird screen flickering on the level select screen, but other than that it’s been great.

You’ve also got something like Virtual Circuit Board or Logic World which offer a nice sandbox for building circuits in. These are just a sandboxes, so there’s no story to speak of. I haven’t tried Logic World, but VCB looks pretty nice. I haven’t really played with it enough to get to grips with its editing tools to know if they’re any good, but it seems alright so far. I have to say that without the motivation of solving specific puzzles, I was kind of at a loss as to what to do in VCB. I guess I could try making a 7-component display or something like that.

Another game that kind of fits into this category is MHRD a game where you design hardware. You do this, not by dragging around components in a graphical interface, but by writing out a spec for the new hardware. So you say “wire the first input up to the in for a NOT gate, and wire that output into the first input for a OR gate” in a kind of hardware specification language. I didn’t get very far with this one because I felt like I could get the same thing out of the early levels of Turing Complete, and found the graphical aspect helped me think things through. This game has no story to speak of: the story is you’re supposed to be designing hardware. It looks pretty basic: just two colours, all text. You can change what the two colours are to match various old school displays, though.

Silicon Zeroes takes a slightly different approach. On some level it’s similar to Turing Complete – you’ve got some components and you are wiring them up in order to satisfy some goal – but the starting components are things like adders and latches (things you build out of logic gates in Turing Complete). On the other hand, Silicon Zeroes has a more careful, more obvious timing mechanic so you can see you how long different operations take, and you have to accommodate components which take different amounts of time to complete their operations. The story of Silicon Zeroes, at least the first chapter that I have played so far, is that you’re an employee at a company designing widgets of some sort. The art style is fine. The visuals aren’t as striking or as easy to read as Turing Complete, but it’s still pretty easy to figure out what is connecting to what.

Games that teach you about assembly language

Before getting into the new games, I’ll note that both Virtual Circuit Board and Turing Complete involve assembly language. In the case of Turing Complete, you actually build the circuits that read the instruction bytes and turn on the correct circuits to perform the operation. It’s immensely satisfying to see how the circuit you’ve built up out of logic gates is actually a chip you can progam in assembly on. I should also say that when I say “assembly language” here, what I normally mean by that is “language for programming a register machine”. One way or another, all these games are about programming simple machines that consist of several memory locations (registers) and several operations to act on those registers (add, subtract, multiply, compare, etc).

The first of several games from Zachtronics that I am going to mention is Shenzhen I/O. The basic idea of this game is that you are designing devices that take inputs and produce outputs. You have control over what components make them up, and also what code is run on each component. The game comes with a PDF that provides the specifications for the assembly language you can use to program these devices. It’s a pretty unforgiving game that does not hold your hand at all. But it’s satisfying to solve a puzzle. It looks pretty good too. Controls-wise, you are basically writing assembly into small windows on the components that make up your devices. It’s not particularly ergonomic.

Human Resource Machine is a game that effectively teaches you a simple assembly language by stealth. You are an office worker tasked with performing various manipulations on some numbers that enter on the left side of the screen and (conditionally) outputting some numbers on the right hand side. You perform a list of instructions in sequence. You can pick up numbers from the input, place them down on a number of storage squares, add, subtract, compare, jump to a different instruction, conditionally jump and then place possibly new numbers on the output conveyor belt. You are, in effect, acting out the role of the accumulator register in a simple register machine. The storage squares are your internal registers, there’s input and output registers too. It’s a pretty satisfying game and it’s probably a more gentle introduction to assembly programming than any of the other games in this section or the next. On the other hand, as the levels get more complicated, the cartoony UI and drag-and-drop editing of the instruction list starts getting in the way of actually building a solution. I want procedures, functions, named blocks and better control flow! This game probably has the most distinctive art style of any of the games discussed in this post. Personally, I don’t like the style, but it is at least something different. The game also has some cut-scenes and other touches that poke fun at office culture and corporate structures in general.

Games that teach you about parallel computing

The sequel to Human Resource Machine is called 7 Billion Humans and takes basically the same idea as HRM, but now instead of creating instructions that you follow, you write instructions that several other workers will perform in parallel. So if you say “Pick up the block in front of you” each worker will pick up their block. It is immediately much more mind-bending to have to figure out how to write instructions that several workers can perform at the same time. The same comments about the cartoony UI and art style apply here too.

Returning to Zachtronics games, Exapunks is similar to 7 Billion Humans in some ways. It’s about writing programs for several independent units to work together to achieve your goal. The difference is that you’re writing a different program for each agent. You still have to get the cooperation to work right though: send a signal from one robot to another, and have that other robot ready to recieve the signal at the same time. The story is a little more involved than many we’ve seen above. You’re living in some sort of cyberpunk metropolis and you need some sort of medicine to stay alive. To get the medicine you hack into various places at the behest of some sort of AI. Hacking involves moving your little programmable robots from room to room, picking up, reading and writing datafiles. Also there are levels where you hack your own nervous system. Again, the spec for the assembly language you are writing in is provided in a PDF. I enjoyed this (I haven’t played much of it, but I am planning on going back to it once I’ve finished Turing Complete). As with many Zachtronics games, there’s actually quite a lot of clever story-telling in the instructions PDFs and in the details of the UI as well as the more straightforward cutscenes and textboxes. It’s got a nice kind of retro pixel art style, but the actual experience of writing your code into the smallish code window component of the UI is not the best.

Finally, another, older Zachtronics game: TIS-100. This is a much more barebones experience. The core game screen consists of a number of boxes into which you can write code. You have a specification you are trying to meet. Each box is actually a register machine which has four special registers (up, down, left, right) which correspond to a way to communicate with the other machines that are in those directions. So if you want to pass a value from one machine’s accumulator to the one on its right, you write MOV ACC RIGHT, and then, on that machine to its right, you put MOV LEFT ACC to move the value from the LEFT register into the accumulator. It’s a simple concept but the puzzles quickly become pretty tricky as you’ve got to get the timings right: moving values to the special directional registers are blocking: if you write a value into one of these registers, and don’t read it on the other side, or read when you haven’t written, the machine blocks up until it can pass its message. Aesthetically, this game is just a collection of black and white textboxes. As with many games on this list, the core gameplay of writing assembly into a small window is not the most ergonomic, but it’s fine. It is, nevertheless, a very satisfying puzzle experience.

Games that teach you about computers by accident

Sometimes, there are features of a game that, it turns out, are sophisticated enough in the right way that they can be used to simulate logic gates. For example, Dwarf Fortress contains a number of mechanics that can be use to perform computation. (Disclaimer, I don’t know if the steam version supports all of these ways. If you want to try these out, you might want to consider the original non-steam version.)

Breaking my own rule about only mentioning steam games, it also needs to be mentioned that Minecraft contains “redstone” that people have used to create some truly incredible feats of computer engineering.

A number of other games are also accidentally turing complete, such as the collectible card game Magic: The Gathering.

I don’t think these examples are really all that helpful in terms of learning about computers, since in order to build or understand these computations, you really already need to know what’s going on.

Games that teach you about process and control flow

The above games have really all relied on puzzles built around low-level computing concepts: wires, logic gates, register machines. There is a genre of game that, more broadly, is useful to train you in thinking about process and control flow. These games are typically less directly about computing concepts, but are nevertheless quite useful pedagogical tools.

There are a bunch of puzzle games where the basic gameplay idea is that you’re building a device made up of transport pieces and pieces that do something and you have to produce some sort of output. Back in the day there was a flash game I played a bunch called Manufactoria. You were building robots: you had conveyor belts and various devices that detected colours and sorted the robots by colour. Given that it was a flash game, I haven’t found an easy way to play it any more, but there is a recent 3D remake called Manufactoria 2022 which looks like it captures at least some of the original’s gameplay. More minimalist versions of pretty much the same idea can be found in Shapez and Word Factori where you are creating shapes and letters respectively. Of these, I think the best balance of simplicity and complexity is found in Shapez. Aesthetically it is quite minimal, deliberately so, and the whole idea is you’re building simple shapes from basic building blocks. So you can generate circles and colours, you can chop the circles in half, and paint them, say, red to produce the output of red semi-circles. The editing features aren’t as polished as in some games, and some simple tools (copy and paste of sections of machinery for example) are locked behind progress milestones which is a bit annoying.

A slightly different take on the process and control flow puzzle game is present in several Zachtronics games such as Space Chem, Molek Syntez and Opus Magnum. Of these, Opus Magnum is the most polished and easiest to look at, but they are all broadly along similar lines. Various basic materials are places at points in some sort of grid and you have rotating and extending arms for moving them to other spots on the grid that contains items that modify them in some way to produce desired output. In Opus Magnum, these items are all given a kind of alchemical flavour, and the world has a sort of steampunk vibe which suits the gameplay quite well. Again the important thing to get right here is getting the right components into the right spots with the correct timing. Neon Noodles is another game that seems to be taking a similar approach to some of the above games, but with a cyberpunk food shop theme.

Beyond these, there are games built around constructing vast factories. These again force you to think about what needs to be where and when. To name just two exemplars of this genre, Factorio is a sort of top-down survival crafter and Satisfactory is a full 3D factory builder.

Games that use a (high-level) programming language

Some games give you a method to interact with game world through writing (high-level) programming language code. (The “high-level” caveat is just to differentiate these games from all of the above games that give you something like assembly).

For example, Bitburner is a game where you are a hacker. And what do hackers use to do their hacking? That’s right, a subset of javascript! The game basically consists of writing programs in javascript, and then running them on computers that you have hacked. You then spend your resources getting better computers, and various other items that will help in a number of ways. The idea is that many activities in the game can be automated by writing appropriate scripts that perform game actions through calling functions in the game’s API. My impression was that the level of programming required was relatively little, and the main challenge was figuring out what API calls you needed to make to automate this or that feature. This is an incremental game, so you write your automation scripts and come back in a few hours to see if you’ve got enough resources for the next step or whatever. You can also play bitburner in your browser.

Screeps World is another game that uses “interacting with the world through a javascript API” as the core mechanic. Here you write progams that run on your little minions that direct them to get resources, defend the base, and so on. The steam version, last time I checked, had no way to control the font size of the code editing window, and it came out incredibly small on my screen. Again, there’s a browser-based version, and this at least lets you use your browsers scaling features to increase the text size. I didn’t get very far into this one, because I simply wasn’t in the mood to learn yet another API to get anywhere in the game.

Closing remarks

As I said at the top, I haven’t spent much time with all of these games. Some – like Turing Complete, Factorio – I have played a lot of. Others I bought specifcally for this post and played for an hour or so to get a feel.

So the question remains, if you wanted to learn computing through the medium of steam games, which games would do the best job of teaching you that? I think the game I learned the most from was, hands down, Turing Complete. It’s an excellent puzzle game, where each level is just a little more difficult than the last (with some notable exceptions like the stupid space invaders level). The documentation isn’t perfect and there’s some rough edges in the UI, but overall it’s a very very good puzzle game that also happens to teach you how to build a whole computer (CPU, Memory, ALU…) out of logic gates.

Human Resource Machine is probably the most accessible game that is sort of about assembly language, but I would suspect you’d get into deeper harder problems playing one of the Zachtronics games such as Exapunks or Shenzhen I/O. On the other hand, those other games are more just about programming in a toy language wrapped in a story and a quirky UI, whereas HRM somehow feels more like a game that people who aren’t programmers might get a kick out of playing.

Just as a puzzle game, I think Opus Magnum is my favourite (or second favourite behind Turing Complete), but I’m not convinced how much you’d learn about process and control flow that you wouldn’t learn by playing the above games.

As for learning a high-level language through games like Bitburners or Screeps, I think what they provide is little more than a wrapper around some coding challenges that involve interacting with a bespoke API. I would, at this stage, probably graduate from steam to just doing coding challenges on exercism or similar.

© Seamus Bradley 2021–3

Powered by Hugo & Kiss.