Hacker News new | past | comments | ask | show | jobs | submit login

> Crowther had written his Adventure program in FORTRAN

I got my first insight into object oriented programming with ADVENT. Buried in the source was the line "A TROLL IS A MODIFIED DWARF". I was gobsmacked.






After some experimentation, I hypothesized that there was a troll flag in Zork, and once I finally discovered the source code decades later, I found out there actually was, called "TROLL-FLAG!-FLAG"!

https://github.com/itafroma/zork-mdl

https://news.ycombinator.com/item?id=31846457

DonHopkins on June 23, 2022 | parent | context | favorite | on: Random Ultima Online anecdote #2 – Horses inside p...

My favorite object containment related ZORK bug (which I discovered in the origin ZORK on MIT-DM, but which persisted in the InfoCom version), involves the troll holding an axe, blocking the door to the depths of the dungeon, who eats anything you give to him:

    >GIVE AXE TO TROLL

    The troll, who is not overly proud, graciously accepts the gift 
    and not having the most discriminating tastes, gleefully eats it.

    The troll, disarmed, cowers in terror, pleading for 
    his life in the guttural tongue of the trolls.
To have killed him in cold blood then would have been cruel, so I tried something else:

    >GIVE TROLL TO TROLL

    The troll, who is not overly proud, graciously accepts the gift 
    and not having the most discriminating tastes, gleefully eats it.
POOF! No more troll!

(I've actually been able to successfully apply this technique of giving HN trolls their own weapons (quoting their own words back to them), then giving them to themselves (pointing them back to their previous posts), to make them disappear from HN!)

But giving the troll to itself triggered another bug, because apparently it forgot to clear the TROLL flag, so you could still not leave the room, because when you tried to go through the exit the troll previously blocked, it said that "The troll fends you off with a menacing gesture." even though there was no troll in the room.

Decades later I finally found the Zork source code, and it turns out there was actually a troll flag called "TROLL-FLAG!-FLAG" that it forgot to clear, which the exit depended on.

I wrote up the bug in more details, with links to the source code:

https://news.ycombinator.com/item?id=19672436

DonHopkins on April 16, 2019 | prev | next [–]

I wrote some comments on the Wikipedia Zork talk page:

https://en.wikipedia.org/wiki/Talk:Zork/Archive_1#h-Link_to_...

Link to the original Zork source code in MDL

I suggest linking to the original Zork source code in MDL which is available here:

http://retro.co.za/adventure/zork-mdl/

Is it OK to link to that source code from Wikipedia? I don't know who officially owns it, though. It was never a commercial product, and was developed at MIT. As the Zork article mentions, the Zork source code was leaked way back in 1977, so the cat's been out of the bag for a long time. A link to the actual source code would be a nice thing to cite in that section.

It is fascinating to read, and really beautiful code, quite understandable even if you don't know MDL, and practically a form of literature.

I played the original Zork on MIT-DM and also the Infocom versions of course. Reading the source code is like seeing the behind-the-scenes underground rooms and passages at Disneyland!

While I was playing Zork, I found a bug. First some context: when you're battling the troll, you can give things to him, and he eats them! Sometimes he drops his axe, and you can pick it up and kill him with it. He blocks the exits until you kill him.

So I tried "give axe to troll," and he ate his own axe, then cowered in terror: "The troll, disarmed, cowers in terror, pleading for his life in the guttural tongue of the trolls."

Not satisfied with that, I tried "give troll to troll", and he devoured himself: "The troll, who is remarkably coordinated, catches the troll and not having the most discriminating tastes, gleefully eats it."

...Except that I still could not get out of the exit, because every time I tried, it said "The troll fends you off with a menacing gesture."

I figured there must be a troll flag that wasn't getting cleared when the troll devoured itself. And sure enough, I found it in the code, and it's called "TROLL-FLAG!-FLAG"!

Here is an excerpt of the MDL troll code, where you can see the bug, where it should clear the troll flag when the troll devours itself, but doesn't (well that's how I would fix it!):

               <COND (<VERB? "THROW" "GIVE">
                      <COND (<VERB? "THROW">
                             <TELL
    "The troll, who is remarkably coordinated, catches the " 1 <ODESC2 <PRSO>>>)
                            (<TELL
    "The troll, who is not overly proud, graciously accepts the gift">)>
                      <COND (<==? <PRSO> <SFIND-OBJ "KNIFE">>
                             <TELL
    "and being for the moment sated, throws it back.  Fortunately, the
    troll has poor control, and the knife falls to the floor.  He does
    not look pleased." ,LONG-TELL1>
                             <TRO .T ,FIGHTBIT>)
                            (<TELL
    "and not having the most discriminating tastes, gleefully eats it.">
                      <REMOVE-OBJECT <PRSO>>)>)
                     (<VERB? "TAKE" "MOVE">
                      <TELL
    "The troll spits in your face, saying \"Better luck next time.\"">)
                     (<VERB? "MUNG">
                      <TELL
    "The troll laughs at your puny gesture.">)>)
              (<AND ,TROLL-FLAG!-FLAG
                    <VERB? "HELLO">>
               <TELL "Unfortunately, the troll can't hear you.">)>>

Thanks for the nice story!

Another thing I liked about the ADVENT FORTRAN code is it would detect if its static tables were initialized or not. If not, it would initialize the statics, and then write the executable out overwriting the executable. Then, the next time it ran, it was already initialized!

I used this trick in my editor in 80s. It didn't have a configuration file, one just set ones configuration in the editor, then hit a command to rewrite the executable. It worked like a champ! This greatly speeded up load times for the editor as doing a file lookup for the configuration file on a floppy disk was very slow.

Sadly, this all ended when the operating system would shut down an executable that attempted to modify itself as "malware".


Gosling Emacs used "unexec.c" by Spencer W Thomas (1982):

https://github.com/bobbae/gosling-emacs/blob/master/unexec.c

There was a FORTRAN version of ZORK (aka DUNGEON) by Bob Supnik at DEC, which was limited in some ways compared to the MDL version, but also had a "GDT" debug mode where you could inspect and control things like the thief and the troll and the cyclops and the robot.

I think you could tell them to perform commands, even become one of them, or have them pick you up and carry you around. I have a vague memory of being carried around by a robot in Zork, but I can't remember which version, or if that was part of the game or GDT. Something like "ROBOT, TAKE ME". Then it could carry you places you couldn't walk to yourself.

Bob Supnik started translating ZORK to FORTRAN in 1977, and published it on the DECUS tape library in 1978.

You could type "GDT" at any time and it would go:

  A booming voice calls out, "Who summons the right hand of the translator?
  State your name, cat, and serial number!"

  SUPNIK,BARNEY,70524

  At your service!

  GDT>
“Barney” was Supnik’s cat; 70524 his DEC badge number.

Zork Fortran Sources:

https://github.com/historicalsource/zork-fortran

GDT Sources:

https://github.com/historicalsource/zork-fortran/blob/master...

It had commands like:

  900        FORMAT(' Valid commands are:'/' AA- Alter ADVS'/
          &' AC- Alter CEVENT'/' AF- Alter FINDEX'/' AH- Alter HERE'/
          &' AN- Alter switches'/' AO- Alter OBJCTS'/' AR- Alter ROOMS'/
          &' AV- Alter VILLS'/' AX- Alter EXITS'/
          &' AZ- Alter PUZZLE'/' DA- Display ADVS'/
          &' DC- Display CEVENT'/' DF- Display FINDEX'/' DH- Display HACKS'/
          &' DL- Display lengths'/' DM- Display RTEXT'/
          &' DN- Display switches'/
          &' DO- Display OBJCTS'/' DP- Display parser'/
          &' DR- Display ROOMS'/' DS- Display state'/' DT- Display text'/
          &' DV- Display VILLS'/' DX- Display EXITS'/' DZ- Display PUZZLE'/
          &' D2- Display ROOM2'/' EX- Exit'/' HE- Type this message'/
          &' NC- No cyclops'/' ND- No deaths'/' NR- No robber'/
          &' NT- No troll'/' PD- Program detail'/
          &' RC- Restore cyclops'/' RD- Restore deaths'/
          &' RR- Restore robber'/' RT- Restore troll'/' TK- Take.')
Gunkies Zork info:

https://gunkies.org/wiki/Zork

GDT Command:

https://gunkies.org/wiki/Zork#The_GDT_command

>GDT dates from a very early version of the game, in fact, before the game was actually finished. I realized early on that debugging an interactive program with the traditional PRINT statements was going to be very cumbersome, and that the interactive debug tools of the day (1978) had no semantic understanding of the program. GDT was the answer. It enabled me to track when things went wrong, and to simulate parts of the game that hadn't been implemented yet.

>Originally, GDT was just a command like any other. Once the game was released, players quickly realized that it offered a simple way to short circuit the game and to undo mistakes. Lost something to the thief? Take it back. Getting killed too often? Turn on immortality mode. So I implemented a variety of challenges to prevent players from entering GDT without making the mechanism too difficult for me to remember. I think the INCANT mechanism might have been the final PDP-11 challenge.

>When I did the VAX version, I abandoned all that and went back to GDT as universally enabled, under control of a run time flag, GDTFLG. I think I intended to turn GDTFLG off before releasing the VAX version, so that it would be impossible to get into GDT without patching the binaries; but in fact the final VAX sources have GDTFLG=1.

>/Bob


I wish I knew which version of ADVENT was the one I looked at. All I recall is it was in FORTRAN circa late 70s, and it ran on the univeristy PDP-10 (which meant it was FORTRAN-10).

Thanks for the fun information you posted!




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: