adventure in python
Ported from Fortran IV, Crowther and Woods, 1977
YOU ARE STANDING AT THE END OF A ROAD BEFORE A SMALL BRICK BUILDING. AROUND YOU IS A FOREST. A SMALL STREAM FLOWS OUT OF THE BUILDING AND DOWN A GULLY.
Picture from VR Colossal Cave game.
Adventure Is Everywhere
In the classic text game adventure, words and imagination hold their own against graphics.
Nearly everyone who used a computer before 2000 has been exposed to adventure and is almost certainly why you're here. The Pulitzer Prize winning 1980 "Soul of a New Machine" by Tracy Kidder even opens a chapter with a brief experience in the cave:
MIDNIGHT PROGRAMMERIT WAS THE HOUR of insomniacs. In the basement of Westborough, the corridors and cubicles stood empty and in shadows. Carl Alsing's cluttered little area made a small rectangle of light. Strewn before me across the surface of his desk, like the relics of a party, lay dozens of roughly drawn maps. They consisted of circles, inside of which were scrawled names such as Dirty Passage, Hall of Mists, Hall of the Mountain King, Complex Junction, Splendid Chamber, Bedquilt, and Witts End. Webs of lines connected the circles, and each line was labeled, some with points of the compass, some with the words up and down. Here and there on the maps were notations—"water here," "oil here," and "damn that pirate!" In the midst of all this paper sat Alsing’s computer terminal. On the screen of the tube in white letters, like the little voice that whispers in a wild gambler's ear, this message stood:
ARE YOU SURE YOU WANT TO QUIT NOW?
The game is widely known and has equally wide appeal.
What's Unique Here?
There are a hundred and one adventure pages out there, so why another? Here are things you won't find elsewhere:
- A micropython version for the HP Prime calculator. There are a small number of Prime-specific subroutines, so porting to other micropython platforms should be straightforward.
- Command line arg to choose the earlier or later 1977 version of adventure. The oldest is a bit less polished showing the game earlier in its evolution.
- Maps are programmatically created from the 1977 set up file showing all transition verbs and conditions, quite different from players' best efforts at hand drawn maps.
- Vocabulary and synonyms pulled from the set up file.
- List of objects with initial locations.
- Discovery of a long overlooked bug in the 1977 set up file.
Screenshot of adventure on the HP Prime calculator
Background
Extensive information on the real cave and life events that inspired adventure is available at Somewhere Nearby is Colossal Cave.
New information from 2024 on Crowther's participation in Dungeons and Dragons just prior to enhancing adventure is at Crowther's Adventure and Mirkwood Tales.
Conversion Effort
I ported adventure from the original FORTRAN IV to python. It was harder than expected because the program is fairly complex, a massive block of code with few subroutines. It has the look of code that grew organically. The code assumes 36-bit words (cramming five 7-bit ascii chars into one word, yielding the 5-letter commands in the game), characters and integers are treated interchangeably, and then the maze of twisty little GOTOs... :-o These are all things that can't be done in python, resulting in opportunities to introduce bugs in the port. Let's hope I have not taken full advantage of those opportunities!
The original text case is maintained and I'm not at all certain, but it might be a unique port keeping the prime time hours check, message of the day and holiday announcement. They are fun to use. Similarly, the original random number generator, ran(), that Crowther & Woods, unsure which, used from Knuth Vol 2 is in use. Sure, python's random() is fine but it's just not the same. :-)
Two versions of adventure source code have been found from 1977, one more polished and presumably the more recent. This is the version you get when running adventure without command line arguments. To experience the older one and its slightly different set up file, run
adventure -o
The 1977 code is at: Crowther, W. and Woods, D. “Adventure”. [Aka “ADVENT” and “Colossal Cave”] FORTRAN source code. 1977. Accessed 18 Apr 2025. https://unbox.ifarchive.org/?url=/if-archive/games/source/adv350-pdp10
I successfully played to the end, as seen below, so have some confidence that all is well. In addition, I've visited every room in the cave and attempted various silly things to expose bugs. But I do worry that undiscovered bugs or changes from original behavior exist. Wear your caving helmet and please email any issues. Many thanks!
Download
Here are three python versions of the game.
- PC version.
- 1. adventure (latest 27 Oct 2026)
an object oriented version. There are internal comments, of interest
mainly to programmers, at the top of the file describing the structure.
- Option -o to choose the oldest version of adventure.
- The original random number generator and wizard challenge for maintenance mode have been revived.
- Many thanks to Raz Alazar for discovering the previous and rather large round of bugs.
- 2. advent.py (latest 1 Sep 2026, fixed QUIT command), direct conversion. Fortran COMMON blocks to dictionaries, etc., as nearly a line by line conversion as possible given language differences. This is an intermediate version leading up to the better one above.
- text Required to be in the same directory as the program, this is the adventure set up data with command RESUM added.
- advent.dat This is used only when running adventure -o. It's also required to be in the same directory as the program, this is the original adventure set up data with command RESUM added.
- 1. adventure (latest 27 Oct 2026)
an object oriented version. There are internal comments, of interest
mainly to programmers, at the top of the file describing the structure.
- HP Prime calculator (latest 18 Jun 2026).
Drag and drop the zip file into your calculator's Applications folder via
the HP Connectivity Kit:
- 3. Adventure.hpappdir.zip (File text included in the zip file.)
- The calculator version recognizes the HP command which toggles alpha shift. It is convenient having on so that text can be directly typed. However, it disables screen scrolling. If you want to scroll back to prior text, use HP to turn off shift-lock, scroll as you like, and then HP to turn shift-lock on again.
- G1 bug: Apparently, the input area is not cleared properly on the older G1 Primes. The fix would be in hpinput() and involve the RECT_P calls that draw white rectangles, and I hope someone with a G1 will be able to debug this small but annoying glitch.
- The code can certainly be ported to run on other devices that run micropython. I hope to do so for the TI Nspire at some point.
Setting Cave Hours
If the file hours exists, the game will allow play during those hours. By default, adventure can only be played during non-work hours. You can modify hours the same as back in the 70s by starting game and answering as follows:
- NO to "Do you want instructions?"
- MAGIC MODE must be first command.
- YES to "Are you a wizard?"
- DWARF, same default password as original,
- NO to "Do you know what I thought it was?"
The original wizard challenge comes after the above sequence. (But only in adventure, not advent.py or the HP Prime version.) It's part of the fun of fully reliving the original game, but can be bypassed if you like. Simply start the game with -c to turn off the challenge. Yes, the challenge is unnecessary in this day of single user machines and there is similarly no need for tracking prime time hours, but you have to accommodate nostalgia, after all. :-) After modifying hours the game exits. The new hours are used when run next. A file hours is created and must remain in the same directory where you run adventure to be found and used.
When actions require a wizard and you haven't turned off the challenge, you will be prompted with a 5 letter challenge string to prove you are a wizard. Use that string as input to answer.py. A sample run whose first line is the message of the day might look like:
$ adventure
NO CAVING 6PM TO 7PM TODAY. SYSTEM OFFLINE FOR MAINDEC AND FILTER CLEANING.
WELCOME TO ADVENTURE!! WOULD YOU LIKE INSTRUCTIONS?
N
YOU ARE STANDING AT THE END OF A ROAD BEFORE A SMALL BRICK BUILDING. AROUND YOU IS A FOREST. A SMALL STREAM FLOWS OUT OF THE BUILDING AND DOWN A GULLY.
MAGIC MODE
ARE YOU A WIZARD?
YES
PROVE IT! SAY THE MAGIC WORD!
DWARF
THAT IS NOT WHAT I THOUGHT IT WAS. DO YOU KNOW WHAT I THOUGHT IT WAS?
NO
BJEMV
IKPJU
OH DEAR, YOU REALLY *ARE* A WIZARD! SORRY TO HAVE BOTHERED YOU . . .
DO YOU WISH TO SEE THE HOURS?
Y
MON - FRI: 0:00 TO 8:00
18:00 TO 24:00
SAT - SUN: OPEN ALL DAY
HOLIDAYS: OPEN ALL DAY
THE NEXT HOLIDAY WILL BE IN 33 DAYS, NAMELY THANKSGIVING
DO YOU WISH TO CHANGE THE HOURS?
$ answer.py BJEMV
IKPJU now
IFQJU after 08:00
The challenge algorithm uses a 24 hour clock and the result changes every 10 minutes. The last line is there in case you happen to run it immediately prior to entering a new 10 minute block on the clock. Blocks start at :00, :10 and so on, minutes after the hour.
Finally, I added a new command RESUMe so that you can resume after a SUSPEnd. Originally, after an hours change or suspend, the game remained memory resident in the now obsolete magnetic core memory image. But if you didn't expect to return for awhile, you better dump memory to a file. Even though the program now saves game state to a file, I left the CORE IMAGE message in for old times' sake and a smile.
Music
Don't start playing the game yet. Set the time machine to 1977 and listen to some hits of the day while exploring Colossal Cave:
Music is rarely mentioned in retro-gaming circles, yet was a huge part of the times for me. Whether at home or in the university lab, I always had the stereo on and tuned to one of the local rock or college stations. As a matter of fact, I continue to do so daily in my lab at work. Computers become outdated, software quaint, but music forever sparkles like new.
The first link above is by Peter Grantham (thank you!) and the best of the links. It's a sampling of rock from the 60s through late 70s, just like you'd hear on the radio in the late 70s. The 2nd and 3rd links include only 1977 music, not quite the same experience but at least you rewind to right year. :-) Please share playlists if you make or find them!
Vocabulary
Little spoiler alert: Part of the charm of adventure is discovering the vocabulary that the game responds to. The challenge is fitting what you want to do into the 1 or 2 word constraint! If you don't mind giving up the enjoyment of discovering recognized words yourself, look at the vocabulary list and you will likely find words you never tried.
Maps
Big spoiler alert: To debug my port of adventure I need detailed maps. I wrote subroutines that parse the adventure setup file to do various things.
- It lists where initial items of interest are placed.
- Generates complete lists of all verbs causing movement from one location to another.
- Outputs graphviz dot commands so that maps can be generated.
If you would like to experience virtual caving, do not look at these maps. They take the challenge out of making your own maps and experiencing late 1970s gaming. If you have already spent weeks or months of your life living in Colossal Cave, use the maps to see what you might have missed. With that warning, here are the maps.
Setup File Bug
The adventure program creates Colossal Cave by reading in a separate setup file that fully describes the cave. The file is made up of 12 sections including vocabulary, cave design, object placement, the messages printed during game play, and various other details.
The 1977 set up file has a bug that is not apparent in the execution of the code. However, when writing a parser to make maps and write out various information, the parser discovered (that is, broke!) when encountering the mistake. This will mean little to any unfamiliar with the code, but there is a transition in Section 3:
113 109 46 11 109which says that to go from room 113 to room 109 the player must enter verb 46, 11, or 109. 46 is SOUTH, 11 is OUT, but there is no verb 109. It has no effect on game play, but is a fun mistake to find 48 years after the fact!
Colossal Cave in VR
THERE IS A LOUD EXPLOSION, AND A TWENTY-FOOT HOLE APPEARS IN THE FAR WALL, BURYING THE DWARVES IN THE RUBBLE. YOU MARCH THROUGH THE HOLE AND FIND YOURSELF IN THE MAIN OFFICE, WHERE A CHEERING BAND OF FRIENDLY ELVES CARRY THE CONQUERING ADVENTURER OFF INTO THE SUNSET.
YOU SCORED 350 OUT OF A POSSIBLE 350 USING 344 TURNS.
ALL OF ADVENTUREDOM GIVES TRIBUTE TO YOU, ADVENTURER GRANDMASTER!
TO ACHIEVE THE NEXT HIGHER RATING WOULD BE A NEAT TRICK!
CONGRATULATIONS!!
A DEC PDP-10 in the Main Office
I've also enjoyed working through the cave in VR, great fun. A nice touch is that upon entering the Main Office, a PDP-10 is seen in all its glory! This is the machine that adventure was written on and reference to its architecture is seen throughout the source code. I wish the VR game allowed the player to walk around and see the machine up close.
I took these snapshots while playing the game. The 3d effect is a lot of fun and more impressive than flat 2d snapshots convey.
Here is the trailer on YouTube.