Monday, May 23, 2011

Not the Chemistry I Remember (continued)

My previous attempts at the SpaceChem level Best Left Unanswered left me with an above average result compared to the rest of the SpaceChem players. But I was determined to do even better. The level was simple: nitrogen atoms input, output nitrogen molecules (N2 with a triple bond).

I saw that the best times (measured in cycles) were about twice as fast as mine. There must be something I was missing. And like much of SpaceChem, when I figured it out, it seemed so obvious. Clearly, to get a time that was twice as fast I needed to move two atoms at a time instead of one.

Like the previous attempt, to get the fastest time we'd use a straight line instead of a circuit. Each waldo would be responsible for assembling a nitrogen molecule and moving it across to the output. The two waldos would have to share the responsibility for bonding, inputting atoms and outputting molecules since we'd need to, for example, input a second nitrogen atom in the same cycle as bonding the first to it. To figure out the required placement of instructions we draw up a table and start filling in instructions.

We want red to drop its molecule last so that blue can output in the same cycle (red's instructions are carried out before blue's), so we have blue start building the first molecule on cycle 1.

CycleBlueRed
1Grab
2
3
4
5
6
7Drop
8
9
10
11
12

We then have to input the next atom and triple bond the molecule simultaneously, so constraining our options somewhat in cycles 2-4. Note that since red's instruction is run first, it has to run the in instruction before blue runs the bond+ instruction to ensure the atoms bond.

CycleBlueRed
1Grab
2Bond+In
3Bond+
4Bond+
5
6
7Drop
8
9
10
11
12

Red can't start building its molecule in cycles 3 or 4 because it leads to problems scheduling the in instructions. So the earliest we can start red's construction is in cycle 5.

Red's molecule also has to be assembled with an in instruction from red and three bond+ instructions, one of which must be run by red when blue is running its drop instruction.

CycleBlueRed
1Grab
2Bond+In
3Bond+
4Bond+
5Grab
6Bond+In
7DropBond+
8Bond+
9
10
11OutDrop
12

Now because our waldos are following a back and forth route on a straight line, each waldo's instructions will be mirrored around their grab and drop instructions. Here blue's bond+ instruction in cycle 2 is already mirrored in cycle 6, however the out instruction in cycle 11 must be repeated in cycle 3. This forces red to do a bond+ in that cycle which is already mirrored in cycle 7. Red's in instruction in cycle 6 must be repeated in cycle 4. This forces blue to do a bond+ in that cycle which must be mirrored in cycle 10.

CycleBlueRed
1Grab
2Bond+In
3OutBond+
4Bond+In
5Grab
6Bond+In
7DropBond+
8Bond+
9
10Bond+
11OutDrop
12

In addition, looking at cycle 2, blue's bond+ instruction must be repeated in cycle 12 and red's in instruction must be repeated in cycle 8. This forces blue to do a bond+ in cycle 8 which is already mirrored in cycle 6.

CycleBlueRed
1Grab
2Bond+In
3OutBond+
4Bond+In
5Grab
6Bond+In
7DropBond+
8Bond+In
9
10Bond+
11OutDrop
12Bond+

Only thing missing now is an out instruction for blue's molecule dropped in cycle 7. We have to do this in cycle 9 else there will be a clash of molecules. It doesn't matter who runs this instruction so we give it to red. This out is mirrored in cycle 1.

CycleBlueRed
1GrabOut
2Bond+In
3OutBond+
4Bond+In
5Grab
6Bond+In
7DropBond+
8Bond+In
9Out
10Bond+
11OutDrop
12Bond+

The two instruction lines are:
  • Blue: grab, bond+, out, bond+, -, bond+, drop
  • Red: grab, in, bond+, in, out, -, drop

There isn't space to position the waldo starts where we'd like on the paths, but we can position them off at an angle to run just the instructions we need to get started. The completed setup is below.


"Best Left Unanswered" - best attempt

This reactor outputs 10 nitrogen molecules in just 59 cycles, less than half our previous attempt and snagging a spot in the top bar on the histogram.

Thursday, May 19, 2011

Not the Chemistry I Remember

Despite the brilliance of Portal 2, I did feel let down by the lack of really difficult puzzles and challenge levels (quickest time/fewest portals). Scouring other thoughts on the matter led me to indie puzzle game SpaceChem. I was promised really difficult puzzles and competition for fastest time/fewest symbols used for each level.

Although the theme of the game is chemistry, reactors where you can manipulate atoms directly indicate that this isn't meant to be a realistic portrayal of the subject. The basic premise is that you need to take molecules (or atoms or radicals) coming into a reactor and convert them into the required molecules (or atoms or radicals). The example below shows a reactor I built to convert a methane molecule (CH4) into the required CH radical and hydrogen (H) atoms.


Disassembling methane

To accomplish this, you have two waldos, atom-sized "robots" that will follow the track laid down for them and process the instructions in the square they're currently in. The instructions include grab (to pick up an atom), drop (to put down an atom), in (to bring a new molecule into the input area) and out (to flush a molecule out of the output area).

In the example above you can see the red waldo has just dropped off a hydrogen atom and is about to flush it with the out instruction. Meanwhile the blue waldo is rotating a CH radical that it will drop in the upper output area in the next cycle (waldos move 1 square per cycle, the SpaceChem unit of time).

So far I've only played one difficult level and that was optional. I expect there are more challenging levels ahead, but in the meanwhile I'm having great fun trying to optimize my solutions to be among the best for each puzzle.


SpaceChem histograms

As an example of an early level and the optimization I did, I present my solutions for Sernimir IV's Best Left Unanswered. The level comes just as you've learned how to bond atoms together: running the bond+ instruction will cause all atoms on the special bonding tiles to add one bond to each neighbouring atom also on a bonding tile. In this level you have to make a triple bond between a pair of nitrogen (N) atoms to form a nitrogen molecule (N2). Looking at the histograms before the level shows me that players solutions typically take 200-250 cycles to output 10 nitrogen molecules and use about 22 instruction/direction symbols.


"Best Left Unanswered" - first attempt

My first attempt was fairly simple. The blue waldo grabs a nitrogren atom first (using the sync instruction, the red waldo waits for the blue waldo to have picked up its arom first) and then the red waldo grabs a nitrogen atom. The two waldos then drop off their atoms in the output area (blue's atom to the right to ensure there's no collision between atoms), Then the red waldo runs three bond+ instructions to form the triple bond followed by an out to flush the completed nitrogen molecule.

This first attempt takes 141 cycles and uses 20 symbols, outperforming the typical solution! (Perhaps it's too easy to over-engineer a solution for this one?)

The key step in optimizing here was realizing that the waldos' routes need not be a circuit. A straight line back-and-forth route was the shortest way between the input and output areas. This has the interesting side effect of each instruction (except those at each end) being run twice (once as the waldo moves left along the route and once as it moves right). This can be mitigated (e.g. running a drop instruction while not holding anything will do nothing) and exploited (e.g. we need to in two nitrogen atoms and can now do that with a single instruction symbol). By keeping the route lengths the same and choosing appropriate starting positions, we no longer need the sync instructions. A careful ordering of the instruction symbols gets us the nitrogen molecules we need.


"Best Left Unanswered" - improved attempt

To see how this solution works, we can go through the 12 cycle sequence that then repeats:

CycleBlueRed
0StartStart
1Inputs N
2Grabs N
3Inputs N
4Grabs N
5(out does nothing
6(bond+ does nothing
7(bond+ does nothing
8Drops N
91st bond N-NDrops N
102nd bond N-N3rd bond N-N
11Outputs N2(drop does nothing)

The solution takes 119 cycles (10 sequences) to reach 10 nitrogen molecules and uses 13 symbols. While a significant improvement over my first attempt, the histograms show a sub-100 cycle time is possible and can be solved with as few as 8 symbols (though probably not both in the same solution). Now that's got my brain straining for some inspiration...

An even better solution awaits in Not the Chemistry I Remember (continued).

Tuesday, May 10, 2011

Review: Portal 2 (PC)

Portal 2 is a first-person puzzle game, the sequel to the highly praised Portal. I thoroughly enjoyed the original and was greatly looking forward to Valve's big budget follow-up. I wasn't disappointed. Well, maybe a teeny little bit, but overall there's few opportunities to complain and many to praise this brilliant game.

The basic mechanic from Portal is unchanged: the player acquires a portal gun which can shoot blue portals and orange portals. The blue and orange portals are linked and anything passing through one portal will emerge from the other. There are a few conditions though: you can only have one blue and one orange portal up at a time, and they can only be fired onto certain surfaces, common in the game's test chambers but relatively rare in the many sections between the chambers.


Portals linking 2 disparate points

The original Portal proved that portals plus a few boxes and buttons can provide a suitably varied and challenging experience; so what could Portal 2 add to keep the sequel interesting?

Well, firstly they added a more compelling narrative. There are a few more twists and turns in the sequel's story which is told by way of some very humorous characters with the testing overlord AI GLaDOS returning from the first game, and a bumbling personality core, Wheately, accompanying you as you begin your adventure through Aperture Labs.

But the story is still just a background element to the puzzles, and here Portal 2 keeps it fresh with new environmental components introduced almost every chapter. The new components are:
  • Laser deflecting boxes
  • Light bridges - so many uses beyond just walking on them, especially since you can use portals to make the bridges vertical
  • Light funnels - act kind of like light bridges except they force anything caught in them to go along them in their direction, horizontally or vertically
  • Aerial faith plates - spring-loaded catapults to generate a great deal of momentum
  • Blue gel - you (or any object) will bounce off it and objects can be covered in it making them very bouncy
  • Orange gel - you can run really fast on it and so is another way of getting a lot of momentum
  • White gel - flat areas coated in this goo can have portals on them

If you're interested in seeing some of these components and how they're used in the context of a puzzle, you can have a look at my (spoiler-heavy) "Let's Play a Portal 2 Test Chamber" from later on in the Portal 2 single player campaign.


Blue and orange gel - two of the new Portal 2 components

For newcomers to the Portal series, Portal 2 starts off really easy but quickly ramps up as the new components are introduced. This difficulty comes from having to use the new components in clever ways rather than tricky portal shots like in the original.

Now Portal veterans (like myself) were hoping that later in the game, with all these new components, we'd get some really difficult puzzles to really challenge our puzzle-solving skills. Unfortunately that isn't the case: just when things are getting interesting with one of the new environmental components, the next test chamber will feature a different component and we'll be back to easy levels again. There are unfortunately no really difficult levels; even the final "boss level" uses just a couple of the new components and is only made somewhat challenging by a timer.

To be fair, the original Portal was just as easy and quite a bit shorter. But what really helped there were the advanced chambers (one of which kept me stumped for hours) and challenges (fewest portals or quickest time to solve a test chamber). However there's none of those options in Portal 2. According to news sources, free DLC will arrive eventually to fill in this gaping hole. Until then we have just about 12 hours of gaming: an 8 hour single player campaign and a 4 hour multiplayer campaign.


And talking of multiplayer ... the biggest innovation in Portal 2 is the co-op mode. If you can grab a like-minded friend to join you in this, it will be the most fun you've had since you discovered the joy of portal making in 2007. Since two heads are better than one, it's quite easy to blitz your way through the levels as one player figures out the solution if the other gets stuck. But with 4 portals at your team's command, the sheer creative joy of figuring out some of the solutions is great.


Portal 2 multiplayer: Co-operate for Science!

I loved Portal, and I love Portal 2 so much that I want more. As mentioned above, Valve has promised us more and I can't wait until then.

Final Score: 9 / 10 - Superbly polished puzzle game with an excellent single player story and a fun co-op campaign. It's only let down by a lack of really challenging puzzles and replayability options.

Notes on my personal rating scale: They are entirely based on my personal feelings about the game - I don't rate a game on its own merits but rather how much I've enjoyed and how much time it's sucking out of my life. Strategy games will do well and shooters poorly because those are my gaming preferences.

0-4 = Poor game that I won't be bothering to play any more
5-7 = Decent game - fun enough that I'll try play it some more if I have the time
8-10 = Good game that I'll be playing a lot more or have already finished and greatly enjoyed