Monday, September 26, 2016

Space Chem: A brilliant game about Chemistry and Parallel computing

If you like programming, you might want to play SpaceChem, a delightful game.


The world doesn't need another platformer, another action RPG, or another First Person Shooter.  These genres have been explored beyond the point of creativity.  I played a game recently that blew my mind: it was a puzzle game that allowed you to write code to create molecules.  If you are left scratching your head, it is because the game truly is a mind-bender.


Spacechem bills itself as a puzzle game about chemical synthesis, but it is really about programming.  You build reactors using blocks which follow simple programming rules.  You can control two devices called Waldos (one Red, one Blue) that run the commands, and allow you to combine or uncombine molecules into elements.  Elements follow their true chemical properties: Oxygen can make two bonds, Hydrogen can only make a single bond.

The game board is limited, and the input and output areas are clearly delineated.  This constrains your programs, as objects cannot overlap on the game board.  And only one instruction can be placed for a single waldo: you cannot have two red instructions in a square.

Since there are two Waldos, sometimes you need to synchronize them to accomplish a task.  This forces you to reckon with parallel programming concepts.  Accomplishing the task is sufficient to advance to the next level, though you are given a graph of time and complexity (reactors used, and symbols used).  These correspond to time spent and space complexity of parallel programs.  To accomplish the goal quickly or with a small complexity, you quickly learn to keep your waldos busy as much as possible, and synchronize little.  This corresponds to high CPU utilization and reduced global barriers in parallel computing.

All put together, this is one of the most innovative games I have played.  There is a story-line which, while innovative,  pales compared to the beauty and elegance of the game.  The combination of Chemistry and Computing and puzzle solving is truly unmatched.

SpaceChem stands out as a wonderful example of gaming both as a creative art form, and a splendid way to motivate and teach programming.

Here is a program I made which creates Titanium Dioxide and Zinc Oxide from Oxygen, Zinc and Titanium.