Nathan Wailes - Blog - GitHub - LinkedIn - Patreon - Reddit - Stack Overflow - Twitter - YouTube
Games related to programming
Table of contents
Child pages
Related pages
Background
When I was studying for the LSAT, I found it helpful to do other kinds of logic puzzles as a way of getting better at the LSAT's logic games. I learned certain lessons / best-practices from those other puzzles that I was able to then apply to the LSAT's games.
I suspect that the same thing may be possible with programming; by playing these games, in which a lot of the variables/frustrations/distractions of normal programming have been removed (like spending hours looking on Google to figure out what to do next, or not being able to understand the documentation), I suspect (hope) it will be easier to learn certain lessons about the 'best' way to do programming.
Developers
Articles
2016.10.03 - RPS - Can videogames teach you programming?
Human Resource Machine
Hack ‘n’ Slash
"you have an incredible amount of freedom in approaching every puzzle, but at the same time, it can be terribly intimidating if you don’t understand why your solution simply didn’t work. To be fair, though, that’s pretty much programming in a nutshell."
difficulty spike makes Hack ‘n Slash a rough game to play, but if you can get past that, there’s a lot of good stuff to learn.
As a game, Hack ‘n’ Slash has a lot of problems. As a programming tutorial, it’s markedly better. (...) So long as you’re prepared to learn the hard way just how much trial, error, and frustration goes into coding, you can come away with a firm grip on the systems and processes that underpin all languages of the modern era.
TIS-100
Summary: So, can you learn to program by playing games? I’d say yes, with a couple of caveats. First, the challenges of programming are rarely as clearly defined as the puzzles in the aforementioned games; project requirements often change multiple times during development, and sometimes you won’t even know whether what you’re trying to do is possible until you do it – or give up. (...) Second, games alone won’t turn you into John Carmack; they can teach you the basics and help hone a programming mindset, but you’ll still need to hit the virtual books before you’re ready to make the next DOOM.
Lessons learned
Keep track of the patterns you're being taught.
Many of these games are cumulative in their puzzle design: they will have a puzzle that will require a certain technique to solve it, and then a later puzzle will require that same technique to solve a component of the later puzzle.
This makes it really hard for people who play the game intermittently, as you'll have forgotten the pattern by the time you revisit the game.
The solution (IMO) is to keep track of the patterns and think of them as "new moves" in the same way that those 30 rules of chess can be thought of meta-moves.
This kind of writing-down-what-you've-learned is exactly how I got good at the LSAT logic games.
Limit yourself to solving at most one puzzle per day.
Don't aim for your first solution to be an optimized solution. First focus solely on having a working solution. Be content with an unoptimized working solution.
It is much easier to get to an optimized working solution by first getting an unoptimized working solution and then looking for ways to optimize it. Going straight for an optimized working solution can make it extremely difficult to finish a puzzle.
Step through your code when you're feeling stuck.
Look for ways to break a puzzle down into smaller sub-puzzles or simpler versions of the same puzzle, and solve those smaller / simpler puzzles first.
Games I haven't played yet
Online collections of programming games
programminggames.org ← Wow, that was a true labor of love.
Beginner-level
LightBot - This one looks really well-done.
CodeMonkey - Less well-done
COLOBOT - Haven't checked this out yet, graphics aren't great
Hacking-related games
Misc
rec'd by Oliver Steele here, who made this very-insightful comment about sleep (not related to the game or programming)
Inspired by Zachtronics' Flash games.
Was infinifactory based on this?
Rec'd by a guy in a review of Human Resource Machine on Steam.
This seems to do a good job of showing how commands can be combined to create new commands.
rec'd by Samy Kamkar in a tweet
This one looks cool...
...it apparently has some kind of subscription model.
Games I have played
7 Billion Humans
The sequel to Human Resource Machine
Lessons Learned
...
Levels and the patterns / processes used to solve them
You're Hired (cutscene)
Robots have been able to take over all useful work, but people are complaining that they want work, so they're going to be given busywork. You see an alien hand reach from out-of-frame twice, making me think aliens are behind both the robots and this new jobs plan. Your job is to write the instructions for the humans to follow.
Welcome, New Employees
Introduces the step, pickUp, and drop commands.
Transport Squad
Introduces you to the idea of repeating commands (in this case, you put two step commands in a row to have the workers step two times).
Long Distance Delivery
Introduces you to the jump command, which lets you loop your commands (in this case, looping the step command).
An Important Decision
Introduces you to the if/else commands.
Little Exterminator 1
Introduces you to the concept of a bug: there's a problem in a pre-existing program and your task is to find it and fix it.
Collation Station
This one seems to be the first puzzle where you need a nested if/else statement.
Introduces you to the comment command.
Intro to Morale Officers (cutscene)
Doesn't seem to advance the plot. It's just two robots congratulating you on your progress and explaining how to congratulate a worker (with a kind word and a pat on the butt).
Dynamic Angles
Introduces optional size and speed challenges, which you can ask the boss about.
Emergency Escapades
Has a four-level-deep nested if/else statement.
Has you control a person based on the number on a data cube at their location.
Injection Sites 1
Introduces you to the fact that an 'if' statement can have more than one condition.
Unzip
Injection Sites 2
Intro to Shredding
Shred Lines
Little Exterminator 2
Content Creators
Uniquely Disposed
Content Creators Bug Fix
Reverse Line
Big Data
Number Royale
Sorting Hall
Budget Brigade 1
My First Shredding Memory
Budget Brigade 2
Fitness Program (cutscene)
Neural Pathways
Biometric Access
Fill the Floor
Checkerboard Organization
Creative Writhing
Data Backup Day
Seek and Destroy 1
Intro to Calc for Art Majors
Seek and Destroy 2
Dangerous Spreadsheeting
Seek and Destroy 3
Printing Etiquette 1
Printing Etiquette 2
Image Decrypter
Important Email Organization
Task: A 6x10 area of randomly-numbered data cubes ("emails") numbered 0 through 99 needs to be sorted into shredders numbered 0 through 9, depending on the tens-place of the email.
You have to deal with how to get the human to know which shredder to drop the cube in. I used a Memory slot to store their number divided by 10 and then just compared the label below them to that result.
You have to deal with the "pick up nearest data cube" command leading the humans to pick up the labels above the shredders. I dealt with this by having them walk up to the top of the room before looking for their next data cube.
You have to deal with the humans trying to pick up the label data cubes after they've exhausted all the 'normal' data cubes. I did this by having each human deal with 12 data cubes and then stop (because there are 60 total cubes that need to be shredded).
Multiplication Table
Factorio
Human Resource Machine
General thoughts
I beat this game! I haven't beaten all the time/space challenges, though.
I suspect this game may not be getting enough credit by reviewers for its main reason for existing, which is to show explicitly how a computer works in a very real-world "a person is doing these actions" way. I think that's just brilliant.
Lessons learned
Use comments to label portions (stubs) of your code so you can work on them one-at-a-time.
I was working on a task that required some branching logic and I didn't have any comments to separate the different parts, and I ended up getting confused. Adding comments to divide up the different branches made it much easier to work on one part at a time.
The key for me to enjoy this game has been to 1) limit myself to attempting a single puzzle a day at most, and 2) not trying to have my first solution be an optimized solution, but instead being content with an unoptimized initial solution.
Before doing those two things I was finding myself feeling stressed out while playing the game.
Just as in TIS-100, this game is reminding me of the value of stepping through your code when you're feeling stuck.
Just as in TIS-100, the trick to solving scary-looking / big puzzles is to figure out how to break it down into smaller sub-puzzles.
One unfortunate thing about the game is that people totally new to programming are probably not going to be able to complete it, although they may get far.
2016.02.21 - I did the totally wrong task for a Fibonacci question. I thought it was asking me to calculate Fibonacci of N, when in actual fact it was just asking me to output the Fibonacci sequence up to N. So I guess the lesson there is, double-check that you understand what you're being asked to do.
Infinifactory
General advice
Turn the music off. It's really annoying and was probably part of why I would feel gross after playing the game for a while.
Turn the ambient sounds all the way up (sounds of wind since you're up in the clouds).
Write down the patterns you discover when solving the puzzles, because otherwise if you step away from the game for a week or more (and thus forget the patterns you've seen) you may really struggle with any later puzzle which requires one or more patterns that were previously introduced in a simpler setting.
Levels and the patterns used to solve them
Proving grounds
Training routine 1
Objective
There are three single-box inputs facing three single-box outputs, but the left and right input-output pairs are not matched up correctly, so that the left input location is facing the right input's output location.
Thoughts
I had a fair amount of trouble with this one.
Insights / patterns taught
The big pattern / insight was "pay close attention to any irregularities among the inputs". In this case I noticed that one of the inputs would drop one square ahead of the others, and that made me go "now why would they do that?", which led me to think that I could run conveyers behind the input drop locations.
Training routine 2
Training routine 3
Training routine 4
Training routine 5
Skydock 19
Munitions refill Type 2
Munitions refill Type 6
Objective
Split a single input of boxes into three single-box outputs.
Insights / patterns taught
If you want to split off every Nth box from a conveyer belt, put a sensor 2N blocks ahead of a pusher to the side of the conveyer.
The simpler versions of the puzzle
First focus on splitting the input into two different outputs. Only then think about the third output.
Shuttle Propulsion Units
Objective
There's a single input, and you need to create a 3-block output and also a 2-block output.
Patterns required
Use the splitting trick from the previous puzzle and the use-grey-blocks-to-delay trick.
Learn Git Branching
I found out about this from Andy. I remember he said at his job before Infer he and his colleagues would use it to understand what would happen in various situations.
Levels
Main
Introduction sequence
Introduction to git commits
Summary of text:
A commit is a snapshot of the repo.
The commits are expressed as the set of changes from one version of the repo to another.
To win:
Just run "git commit" twice.
Branching in git
Summary of text:
A branch is just a pointer to a specific commit.
There is no storage / memory overhead with making many branches.
Many git enthusiasts say "branch early, branch often".
Use "git branch <branchname>" to create a branch.
In this web app, an asterisk denotes which branch you're on.
Use "git checkout <branchname>" to get onto a branch.
Use "git checkout -b <branchname>" to both create and check out a new branch.
To win:
Just run "git checkout -b bugFix".
Merging in git
Rebase introduction
Ramping up
Detach yo' HEAD
Relative refs (^)
Relative refs #2 (~)
Reversing changes in git
Moving work around
Cherry-pick intro
Interactive rebase intro
A mixed bag
Grabbing just 1 commit
Juggling commits
Juggling commits #2
Git tags
Git describe
Advanced topics
Rebasing over 9000 times
Multiple parents
Branch spaghetti
Remote
Push and pull – git remotes!
Clone intro
Remote branches
Git fetchin'
Git pullin'
Faking teamwork
Git pushin'
Diverged history
To origin and beyond – advanced git remotes!
Push Master!
Merging with remotes
Remote tracking
Git push arguments
Git push arguments – Expanded!
Fetch arguments
Source of nothing
Pull arguments
Robot Odyssey
This is the sequel to Rocky's Boots. It's apparently harder than Rocky's Boots.
Rocky's Boots
This game was followed by a more-difficult sequel, Robot Odyssey.
You can play the game online here: Virtual Apple 2 - Rocky's Boots
Shenzhen I/O
This is a beautiful game. The artwork and sound effects are fantastic.
It's basically a high-production-value version of TIS-100.
It's more complicated than TIS-100.
General advice
Turn the music off.
Changes to designs are autosaved (just like in TIS-100), so if you want to experiment, make a copy first.
Hold tab to see the register names when you've got two modules close together.
Ctrl + Click to toggle breakpoints on the input/output graph.
Look for patterns in the desired output, because you may be able to use them to simplify your code.
For the pulse generator I took advantage of the fact that every time unit with the ouput at 100 should be followed by a time unit with the output at 0.
Consider taking something that's coded as a loop and looking for ways to partially hard-code it as a loop of multiple iterations of the same command.
I've done this in TIS-100 several times.
I did it for the pulse generator. Originally the code calculated every time unit individually, but then I saw that I could hard-code a two time-unit length of output.
Vocabulary
"Simple input" and "simple out" in the instructions for various assignments refer to the p0 / p1 "Simpe I/O"-type pins.
Differences from TIS-100
No commas between the register names ("MOV 5, RIGHT" → "mov 50 p1").
The concept of "time units" is totally new. There's nothing analogous in TIS-100.
The actual duration of a "time unit" is never specified, but it seems to be seconds or tenths of a second.
The only thing that consumes time units is the slp command.
When you click the 'step' command, it does two different kinds of things, depending on the current command to be executed:
If there is a non-slp command to be executed, that command will be executed, and the current time unit will remain the same.
If there are no non-slp commands to be executed, the time unit will be incremented by one.
When you mov a value to an XBus pin (p0 / p1), it isn't a single event (like in TIS-100), but rather happens over a period of time determined by the slp command.
Rather than tracking cycles (steps) to rank your solution, they track "power usage".
Each microcontroller has a "power" indicator on it that shows how much power it has consumed up to that point.
Power usage is incremented by one when any command runs.
The slp command increments the power usage for each time unit slept.
You can name your designs.
the code is auto-indented
you can have conditional execution of lines following a teq statement. "+" means "run if the teq above is true", and "-" means "run if the teq above is false".
There's no JGZ / JLZ / JEZ / JNZ
There's no SAV or SWP. You can write directly to "dat" (the equivalent of BAK).
Summary of the manual
Reference card
Basic instructions
nop
mov R/I R
jmp L
slp R/I
slx P - Sleep until data is available on the specified XBus pin (P).
Arithmetic instructions
add R/I
sub R/I
mul R/I
not - If the value in acc is 0, store 100. Otherwise store 0.
dgt R/I - Isolate the specified digit of the value of the acc register and store it in the ACC register.
dst R/I R/I - Set the digit of the value in acc specified by the first operand to the value of the second operand.
Test instructions
teq R/I R/I
tgt R/I R/I
tlt R/I R/I
tcp R/I R/I - This is a weird one. It's like a combination of the greater-than and less-than, or the opposite of the 'is equal' check. The "+" commands will execute if and only if the first operand is greater than the second operand. The "-" commands will execute if and only if the first operand is less than the second operand.
Registers
acc
dat
p0, p1
x0, x1, x2, x3
Notation
R - Register
I - Integer
R/I - Register or integer
P - Pin register (p0, p1, etc.)
L - Label
Application notes
The two types of interfaces
Simple I/O - Continuous signal levels from 0 to 100, inclusive. Unmarked(?).
This is used for getting input and sending output.
XBus - Discrete data packets from -999 to 999, inclusive. XBus pins are marked with a yellow dot.
This is used mainly for communicating between microcontrollers.
Simple I/O can be read or written at any time with no regard to the state of the connected devices.
XBus is a synchronized protocol. Data over XBus pins is only transferred when there is both a reader attempting to read and a writer attempting to write.
Sleeping
Touch-activated light controller
Language reference
Introduction
Program structure
Comments
Labels
Conditional execution
Registers
Instruction operands
Basic instructions
Arithmetic Instructions
Test instructions