
After clam chowder and debatably, the telephone, the best thing ever to come out of the Boston area is the text adventure. More broadly known now as interactive fiction, it's a rich tradition that continues to today. Colossal Cave, the true original, is some fifty years old now, and its descendant, Zork, is not far behind.
I've had some ideas around digging back into the original world of Zork since Microsoft open-sourced the three original microcomputer games last year. Combined with various snapshots of the mainframe (PDP-10) code that have been released, I started to compare all of the versions out of historical curiosity.
Of course, the biggest difference is that the mainframe game was simply too large for the personal computers of the day, and so it had to be sliced up into multiple segments to fit. The technical achievements required to do this are true mothers of invention. Many writeups of the details exist and I encourage you to read them.
As I excavated the process the original programmers — Implementors — used to break up the game, I had the idea "simply" to stitch the games back together to make a single Zork Trilogy allowing someone to play all three games in order.
This turned out to be more difficult than I expected.
Miscellanea
Z-machine v3, which Zork I ran on, is too small to contain all three games together. This meant upgrading Zork I and II to v5 (at minimum) and running them in the newer engine.
The end of each game and the beginning of the next are slightly different, describe different rooms, or don't have completely consistent geography. I took the beginnings as the canonical version rather than the endings.
There are a few architecture-specific bits hanging around, and engine versions accept different truncation lengths for commands. Minor, but all potential incompatibility points.
Some items have shared names between the games. This meant thinking carefully as to whether those items were actually the same item between games or just a different instance of a similar thing. Easy for things like doors; harder for keys; and then there was the sword and the lamp.
Mainframe Zork only had score, and so did the first two Zork games. Zork III used a different approach, called "potential", on a 0/7 scale assessing your potential to become the new Dungeon Master. I converted this into a 0/350 points scale with 50 points awarded per potential point, summed the scores, and came up with a final tally out of 1100 points.
The sword and the lamp

These two things are the signature objects in Zork (and the "GET LAMP" documentary makes it clear this is true of most early text adventures.) It seemed important to me to preserve the "same" sword and lamp throughout all three games, which presented challenges for both.
First of all, you don't actually need the lamp to beat Zork I. Once you get the torch, you can technically leave the lamp behind and complete the game. But then, you either 1) need the lamp at the start of Zork II, or 2) you could keep the torch through the start of that game, which is an unfair advantage. So I added a block to the endgame of I to require you to be carrying the lamp.
The second thing is that managing lamp power is a significant aspect of the first game, and it's equally unfair to start Zork II with a depleted lamp. So I confirmed my memory that the lamp is in fact battery-powered, and added a spare battery supply at the starting rooms of Zork II and III. You can replenish the batteries, good as new, same lamp.
Then I realized it's possible to smash the lamp, rendering it useless, and making it impossible to beat the later games. So I made the batteries magically restore the lamp too, if you were so inconsiderate as to have destroyed it. There are so many parallels between algorithms to ensure a narrative proceeds properly and algorithms to ensure a program proceeds properly!
The sword presented other issues. At the beginning of Zork III, you find the sword in a stone and can't take it. Occasionally the game will reproach you for trying to take it ("Who do you think you are? Arthur?") Eventually, it is retrieved from the rock and appears in your hand. However, having it earlier makes some things easier. So now the sword will fly out of your hand at the appropriate time, into the rock, and order is restored. Except — there's another way to get it now, thanks to the merged game!
Item continuity
Merging the games created some other interesting opportunities. For example, what if you carry an item from Zork I into II, and it might solve a puzzle in a new way?

I decided that it was within the spirit of the original game to allow these solutions to work, if you could get the item through to the next game. That meant doing an exhaustive audit of all objects you might have with you, and what effects they might have in the later games. In most cases, nothing at all happened, but it was often because the game just didn't recognize a foreign item as a puzzle solution. I wasn't satisfied with that. The opposite wasn't great either: obtaining a key might be really difficult in a game, but you could simply bring a key from the previous game. In all cases, it would be deeply unsatisfying to have the game difficulty change dramatically in either direction as a response to player creativity. (Then, I thought, why stop there? Why not allow the engine to evaluate any clever solution with any combination of items? Hm. I parked the idea for the moment.)
Shared locations
There are moments in Zork III where you revisit rooms from earlier games. It wasn't clear to me if these were meant to be exactly the same places as the earlier games or a recreation, so I checked the source to see if it had anything to say.
;"Here's some ZORK I"
<OBJECT TIMBERS ;"was OTIMB"
(IN TIMBER-ROOM)
(SYNONYM TIMBERS PILE)
(ADJECTIVE WOODEN BROKEN)
(DESC "broken timber")
(FLAGS TAKEBIT)
(SIZE 50)>...;"Stuff from ZORK II"
<ROOM ROOM-8
(IN ROOMS)
(LDESC
"This is a small chamber carved out of the rock at the end of a short crawl.
On the wall is crudely chiseled the number \"8\". The only apparent exit,
to the east, seems to be a blur and a loud, whirring sound resounds through
the rock.")
(DESC "Room 8")
(FLAGS RLANDBIT)
(EAST "You are repelled from the exit by a fierce wind.")>...Confirmed, so I additionally had to merge the rooms to become the same places. This created an additional problem. What if a player dropped an item in one of these rooms in the earlier game, and then came back to the room in Zork III? Should it still be there? (Of course it should still be there.)
But what if one of those items was an item needed to solve a different puzzle in each game? It's a fun bit to remember what you found in the room in the previous game, but if it's the same room and you're playing the same game, what's the best way to handle this? I ended up simply doubling the item. Experienced players will probably realize the implications when they see that. And yes, there are other things you could do with this connection.
More item continuity
I continued looking, not just into which items could have which effects, but also which things plausibly would have new effects in the later games. This got extremely complicated when I realized the wand itself from Zork II could be carried through to Zork III. Some of the effects are novelty or cosmetic, but others have significant results that could break the game.
The mainframe version doesn't even have the wand, and that version (as I'd learned) removes all items when you enter the crypt that would become the opening to Zork III. I'd already decided that difficulty should remain consistent, and that creativity was still in keeping with the spirit of the games.
Handling classes of items and understanding which puzzles they might solve early or strangely was another full run across the whole merged game. I think I standardized everything, but there are probably some items I missed...
Walkthrough and RNG

Once I had merged the games and their items, fixed puzzle solutions, managed large immersion issues with continuity, and dealt with problems arising from behavior within a single game, like the thief only wandering around Zork I rooms, I was ready to test.
My plan was to run the original walkthrough on each game individually to make sure that the original sequence of commands still worked, then run I + II, II + III, and then finally the entire trilogy end-to-end from a single command sequence.
This turned out also to be very difficult, because I had forgotten about RNG. That's a weird thing to forget about, and the walkthroughs I had were seed-independent, but once I stitched those together my walkthrough tests started killing the player or simply getting stuck.
RNG gets used in many places in all versions of Zork. I'd realized I'd probably just repressed the memory of having the thief steal all my treasure or the wizard randomly destroying my progress on a puzzle. At scale, across many test runs, it became multiply irritating.
There are plenty of other examples, notably the earthquake that occurs in Zork III (between 70-140 turns), combat, and how likely it is you are eaten by a grue when wandering around in the dark.
Final testing
I added a series of debug commands to the engine, which allowed things like setting the seed, generating a random number directly, waiting a number of clock ticks without advancing the turn counter, and so forth. This allowed me to consistently run walkthrough steps without worrying about the effect on the game (a sort of NOOP slide.)
Intra-game continuity also presented some unique challenges here, due to encumbrance rules and the wizard. In Zork II the wizard occasionally appears and casts FUMBLE, causing you to drop the first item in your inventory. Your inventory count is also limited, in general. If you have more than 7 things, you have only a 64% chance of being able to pick up the eighth item. Under the FUMBLE condition, you can't pick up more than 3 things.
This is a fun (or annoying hard-mode) side effect of the original game, but in a deterministic playthrough it's disastrous because it desyncs the run entirely. The debug commands allow for correcting a run so that you can fix problems in any given seed.
Once I had those running properly, I was able to complete a run end-to-end of each game and the entirety of Zork I-III, in a single playthrough:

I never played all three games in order in any number of sessions. On period hardware, I don't think 80ms is even enough time to print the response to a single command.
Up next
This work gave me several other ideas for what to do next. I'll write more about these ideas in future posts, as things begin to get wild.
What if I built my own Z-machine interpreter and used it to lift some of the limits of the original game?
What if I added an AI layer on top of the existing game to allow the engine to interpret commands the original game never could?

Download The Zork Trilogy (Plus) and play it yourself.

