Colossal Cave Adventure in batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Colossal Cave Adventure in batch

#1 Post by dbenham » 25 Aug 2013 16:49

Well, since I've already demonstrated how pure batch can be used to develop a classic arcade style game: SNAKE.BAT, I thought it was time to show how batch could be used to develop a text based interactive fiction game.

Developing my own game would take a ridiculous amount of time, so I opted to port an existing game to batch.

What better game than the grand-daddy of them all: Colossal Cave Adventure - the 350 point version by Crowther and Woods. It is the forebear of all interactive fiction games that followed.

The batch implementation is too large (~150kb) to embed the code directly, so I've attached a zip file.

Here is the adventure.zip file:
adventure.zip
(42.51 KiB) Downloaded 860 times

You can also downloaded the game from my DropBox: http://goo.gl/2ohAxB Current version = 1.6 2015/03/27. Download the file, adventure.bat.txt, and then rename it to adventure.bat. EDIT - I've used the Google URL shortener in my link so that I can crudely track how many people have downloaded the game.

The FORTRAN source code I used as a basis for my implementation is available at http://rickadams.org/adventure/e_downloads.html

There are only a few technical hurdles to overcome to make an effective batch IF game. The biggest issue stems from the fact that batch is an interpreted language. All of the code and data is in plain sight within the script. We don't want a player to cheat by looking at the script to figure out how to beat the game.

The solution I used is to selectively encrypt all text messages, variable names, and labels using a simple rotation cipher. The game is first written without encryption. Text that is to be encrypted is enclosed within curly braces {}. Encrypted text can span multiple lines. Sometimes I need to be able to enable or disable encryption in a way that is invisible to the batch parser. That is easily accomplished using undefined variables %{% and %}%.

I then include a command in the game that makes a copy of the script, with selective encryption. The command is symetric - if the running version is encrypted, then it creates the un-encrypted version, and vice-versa.

The encrypted version of the game is ADVENTURE.BAT. The decoded "source" is called ADVENTURE_SRC.BAT. During game play, the encrypted version dynamically encodes all user input so that commands may be properly parsed, and decodes all screen messages so the player can read them.

Both versions play identically. The encrypted version is simply a little slower because it must decode any text that is displayed.

The other hurdle I faced was how to deal with exclamation points in the database of text messages. They cause problems when delayed expansion is enabled and a FOR loop is used. I could have modified the data, but I wanted to use the original game database with minimal changes. I opted to include a routine that performs search and replace on text input, dynamically replacing each ! with an escaped form: ^!

The rest was simply brute force design and programming (and learning how to read FORTRAN) It took about 2.5 weeks of development during nights and weekends.

My version of this classic is intended to be a mostly faithful replica of the original. Here are a list of known differences from the Plotkin version that I used as my source:

- Command words have been restored to the first 5 characters of the word, instead of 4. This is in keeping with the original Crowther version.

- Command parsing and error messages have been reworked, especially the message for a verb with a missing object. But it should not impact game play.

- Bridges may be crossed using compass points. The restriction on using a special crossing verb seemed silly.

- The "BACK" command is implemented in a simpler way. Its behavior is very similar to, but not exactly the same as the original.

- A few choice synonyms have been added.

- The "GRATE" serves only as a noun, never a movement word.

- A hint for the elusive last point has been incorporated into the game.

- Completing the game required a random event. Sometimes the random event never occurred in the original, making it impossible for the player to complete the game, even though the player made all the right moves. I made a slight change to the end game mechanics to nearly guarantee that a well played game can always be completed.

- There is one aspect of the end game code that I did not understand. I had to comment out one instruction to get the game to work. I think I got it correct, but I'm not sure. This issue was fixed in version 1.4

I've done a fair amount of play testing, but certainly not exhaustive testing. Please let me know if you find any bugs, or incorrect behavior.

The link near the top is to the encrypted version of the game. Instructions for getting the un-encrypted version are below. But I suggest you avoid looking at the un-encrypted code if you have never played the game before.

I fully expect there to be bug fixes over time. I will post changes to my Google site, and post notifiation to this thread.

---------------------------------------------------------------------------------------

Below are the instructions on how to decode the script, in case you want to see how the program works. I've embedded the key word below in a way that you won't accidentally see it.

One by one, you get the letters. Be sure you do this correctly. Follow the instructions carefully. Use the first uppercase letter of each sentence in this paragraph. Since the source and walkthrus are readily available on the web, it's not a big deal to publish the un-encrypted form. Caution: don't do this if you don't want to see any spoilers. After you collect all the letters, put them together to get the command word. The command to decode/encode the script takes about 15 minutes to run. Enter the command immediately after answering the instructions question - it will not work at any other point in the game.

Enjoy

Dave Benham
Last edited by dbenham on 27 Mar 2015 19:04, edited 7 times in total.

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: Colossal Cave Adventure in batch

#2 Post by brinda » 25 Aug 2013 22:27

dave thanks. still playing...

:) great flute music as well on your google site. listening to flute as background music while playing the game.

thanks.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#3 Post by dbenham » 25 Aug 2013 22:36

Cool 8)

Totally off topic, but if you like the music, I have about 2 hours worth posted at SoundCloud - https://soundcloud.com/dave-benham


Dave Benham

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Colossal Cave Adventure in batch

#4 Post by foxidrive » 25 Aug 2013 23:28

A brief play here - amazing to think that you've done all this work Dave. Good fun!

I did notice two things - you have a typo in 'infromation'

and when I quit, the console printed my score and something else and then exited without letting me read it.

Cheers

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#5 Post by dbenham » 26 Aug 2013 10:39

Thanks foxidrive

I fixed the spelling, and added a PAUSE to the end of the game.


Dave Benham

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: Colossal Cave Adventure in batch

#6 Post by brinda » 26 Aug 2013 19:36

dave,

the game is saved. on loading back there is an error

Code: Select all

>load

Game restored.

Load failed - Incorrect save version


it loads back where i was. just wondering if the error is a wrong thing on my part

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#7 Post by dbenham » 26 Aug 2013 22:52

That isn't right :(

Either message is valid, but not both :?

I've tried every way I can think of, but I can't reproduce that behavior.

What version of Windows are you using? Are you running adventure.bat? or adventure_src.bat?


Dave Benham

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: Colossal Cave Adventure in batch

#8 Post by brinda » 27 Aug 2013 06:15

sorry dave,
was not descriptive :( .

This will be long

1. have download the new version from google site. Using WINXP SP3(not virtual) + win2000 SP4

it took around 30mins to get adventure_src.bat. :D No error on this [winxp SP3]

Code: Select all

>down

You don't fit through a two-inch slit!

You're at slit in streambed.

>save

Game saved.

>load

Game restored.

>



Below is from winxp sp3 using adventure.bat

Below is saved on adventure.bat, quit and reload on open

Code: Select all

Welcome to Adventure!!

Instructions are available at a cost of five points deducted from your
final score. If you decline the instructions, then I will assume you are
experienced and you will have less time to complete your adventure.

Would you like instructions?

>no

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.

>load

Game restored.

Load failed - Incorrect save version

>



Below is the full walkthrough - reloading within after save [winxp sp3 using adventure.bat]

Code: Select all

Welcome to Adventure!!

Instructions are available at a cost of five points deducted from your
final score. If you decline the instructions, then I will assume you are
experienced and you will have less time to complete your adventure.

Would you like instructions?

>yes

Somewhere nearby is Colossal Cave, where others have found fortunes in
treasure and gold, though it is rumored that some who enter are never
seen again.  Magic is said to work in the cave.  I will be your eyes
and hands.  Direct me with commands of 1 or 2 words.  I should warn
you that I look at only the first five letters of each word, so you'll
have to enter "NORTHEAST" as "NE" to distinguish it from "NORTH".

Should you get stuck, type "HELP" for some general hints.  For infor-
mation on how to end your adventure, etc., type "INFO".  For information
about this version of the game, as well as its history, type "VERSION".
                      - - -

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.

>n

You are in open forest, with a deep valley to one side.

>n

You're in forest.

>down

You are in a valley in the forest beside a stream tumbling along a
rocky bed.

>down

At your feet all the water of the stream splashes into a 2-inch slit
in the rock.  Downstream the streambed is bare rock.

>save

Game saved.

>load

Game restored.

Load failed - Incorrect save version

>


below is from adventure.sav

Code: Select all

#{abgSbhaqPag}=15
#{arjybp}=7
#{bowCebc}.1=0
#{bowCebc}.10=0
#{bowCebc}.11=0
#{bowCebc}.12=0
#{bowCebc}.13=0
#{bowCebc}.14=0
#{bowCebc}.15=0
#{bowCebc}.16=0
#{bowCebc}.19=0
#{bowCebc}.2=0
#{bowCebc}.20=0
#{bowCebc}.21=0
#{bowCebc}.22=0
#{bowCebc}.23=0
#{bowCebc}.24=0
#{bowCebc}.25=0
#{bowCebc}.26=0
#{bowCebc}.27=0
#{bowCebc}.28=0
#{bowCebc}.29=0
#{bowCebc}.3=0
#{bowCebc}.30=0
#{bowCebc}.31=0
#{bowCebc}.32=0
#{bowCebc}.33=0
#{bowCebc}.34=0
#{bowCebc}.35=0
#{bowCebc}.36=0
#{bowCebc}.37=0
#{bowCebc}.38=0
#{bowCebc}.39=0
#{bowCebc}.4=0
#{bowCebc}.40=0
#{bowCebc}.5=0
#{bowCebc}.50=-1
#{bowCebc}.51=-1
#{bowCebc}.52=-1
#{bowCebc}.53=-1
#{bowCebc}.54=-1
#{bowCebc}.55=-1
#{bowCebc}.56=-1
#{bowCebc}.57=-1
#{bowCebc}.58=-1
#{bowCebc}.59=-1
#{bowCebc}.6=0
#{bowCebc}.60=-1
#{bowCebc}.61=-1
#{bowCebc}.62=-1
#{bowCebc}.63=-1
#{bowCebc}.64=-1
#{bowCebc}.7=0
#{bowCebc}.8=0
#{bowCebc}.9=0
#{bowCynpr}.1=3
#{bowCynpr}.10=96
#{bowCynpr}.11=19
#{bowCynpr}.12=17
#{bowCynpr}.13=101
#{bowCynpr}.14=103
#{bowCynpr}.15=0
#{bowCynpr}.16=106
#{bowCynpr}.17=0
#{bowCynpr}.18=0
#{bowCynpr}.19=3
#{bowCynpr}.2=3
#{bowCynpr}.20=3
#{bowCynpr}.21=0
#{bowCynpr}.22=0
#{bowCynpr}.23=109
#{bowCynpr}.24=25
#{bowCynpr}.25=23
#{bowCynpr}.26=111
#{bowCynpr}.27=35
#{bowCynpr}.28=0
#{bowCynpr}.29=97
#{bowCynpr}.3=8
#{bowCynpr}.30=0
#{bowCynpr}.31=119
#{bowCynpr}.32=117
#{bowCynpr}.33=117
#{bowCynpr}.34=0
#{bowCynpr}.35=130
#{bowCynpr}.36=0
#{bowCynpr}.37=126
#{bowCynpr}.38=140
#{bowCynpr}.39=0
#{bowCynpr}.4=10
#{bowCynpr}.40=96
#{bowCynpr}.5=11
#{bowCynpr}.50=18
#{bowCynpr}.51=27
#{bowCynpr}.52=28
#{bowCynpr}.53=29
#{bowCynpr}.54=30
#{bowCynpr}.55=0
#{bowCynpr}.56=92
#{bowCynpr}.57=95
#{bowCynpr}.58=97
#{bowCynpr}.59=100
#{bowCynpr}.6=0
#{bowCynpr}.60=101
#{bowCynpr}.61=0
#{bowCynpr}.62=119
#{bowCynpr}.63=127
#{bowCynpr}.64=130
#{bowCynpr}.7=14
#{bowCynpr}.8=13
#{bowCynpr}.9=94
#{bowSvkrq}.1=0
#{bowSvkrq}.10=0
#{bowSvkrq}.11=-1
#{bowSvkrq}.12=27
#{bowSvkrq}.13=-1
#{bowSvkrq}.14=0
#{bowSvkrq}.15=0
#{bowSvkrq}.16=0
#{bowSvkrq}.17=-1
#{bowSvkrq}.18=0
#{bowSvkrq}.19=0
#{bowSvkrq}.2=0
#{bowSvkrq}.20=0
#{bowSvkrq}.21=0
#{bowSvkrq}.22=0
#{bowSvkrq}.23=-1
#{bowSvkrq}.24=-1
#{bowSvkrq}.25=67
#{bowSvkrq}.26=-1
#{bowSvkrq}.27=110
#{bowSvkrq}.28=0
#{bowSvkrq}.29=-1
#{bowSvkrq}.3=9
#{bowSvkrq}.30=-1
#{bowSvkrq}.31=121
#{bowSvkrq}.32=122
#{bowSvkrq}.33=122
#{bowSvkrq}.34=0
#{bowSvkrq}.35=-1
#{bowSvkrq}.36=-1
#{bowSvkrq}.37=-1
#{bowSvkrq}.38=-1
#{bowSvkrq}.39=0
#{bowSvkrq}.4=0
#{bowSvkrq}.40=-1
#{bowSvkrq}.5=0
#{bowSvkrq}.50=0
#{bowSvkrq}.51=0
#{bowSvkrq}.52=0
#{bowSvkrq}.53=0
#{bowSvkrq}.54=0
#{bowSvkrq}.55=0
#{bowSvkrq}.56=0
#{bowSvkrq}.57=0
#{bowSvkrq}.58=0
#{bowSvkrq}.59=0
#{bowSvkrq}.6=0
#{bowSvkrq}.60=0
#{bowSvkrq}.61=0
#{bowSvkrq}.62=121
#{bowSvkrq}.63=0
#{bowSvkrq}.64=-1
#{bowSvkrq}.7=15
#{bowSvkrq}.8=0
#{bowSvkrq}.9=-1
#{byqYbp2}=5
#{byqYbp}=4
#{cnavp}=0
#{cynprBowf}.-1=
#{cynprBowf}.0= 6 15 18 21 22 28 34 39 55 61 17 30 36
#{cynprBowf}.1=
#{cynprBowf}.10= 4
#{cynprBowf}.100= 59
#{cynprBowf}.101= 60 13
#{cynprBowf}.102=
#{cynprBowf}.103= 14
#{cynprBowf}.104=
#{cynprBowf}.105=
#{cynprBowf}.106= 16
#{cynprBowf}.107=
#{cynprBowf}.108=
#{cynprBowf}.109= 23
#{cynprBowf}.11= 5
#{cynprBowf}.110= 127
#{cynprBowf}.111= 26
#{cynprBowf}.112=
#{cynprBowf}.113=
#{cynprBowf}.114=
#{cynprBowf}.115=
#{cynprBowf}.116=
#{cynprBowf}.117= 32 33
#{cynprBowf}.118=
#{cynprBowf}.119= 31 62
#{cynprBowf}.12=
#{cynprBowf}.120=
#{cynprBowf}.121= 131 162
#{cynprBowf}.122= 132 133
#{cynprBowf}.123=
#{cynprBowf}.124=
#{cynprBowf}.125=
#{cynprBowf}.126= 37
#{cynprBowf}.127= 63
#{cynprBowf}.128=
#{cynprBowf}.129=
#{cynprBowf}.13= 8
#{cynprBowf}.130= 35 64
#{cynprBowf}.131=
#{cynprBowf}.132=
#{cynprBowf}.133=
#{cynprBowf}.134=
#{cynprBowf}.135=
#{cynprBowf}.136=
#{cynprBowf}.137=
#{cynprBowf}.138=
#{cynprBowf}.139=
#{cynprBowf}.14= 7
#{cynprBowf}.140= 38
#{cynprBowf}.15= 107
#{cynprBowf}.16=
#{cynprBowf}.17= 12
#{cynprBowf}.18= 50
#{cynprBowf}.19= 11
#{cynprBowf}.2=
#{cynprBowf}.20=
#{cynprBowf}.21=
#{cynprBowf}.22=
#{cynprBowf}.23= 25
#{cynprBowf}.24=
#{cynprBowf}.25= 24
#{cynprBowf}.26=
#{cynprBowf}.27= 51 112
#{cynprBowf}.28= 52
#{cynprBowf}.29= 53
#{cynprBowf}.3= 1 2 19 20
#{cynprBowf}.30= 54
#{cynprBowf}.31=
#{cynprBowf}.32=
#{cynprBowf}.33=
#{cynprBowf}.34=
#{cynprBowf}.35= 27
#{cynprBowf}.36=
#{cynprBowf}.37=
#{cynprBowf}.38=
#{cynprBowf}.39=
#{cynprBowf}.4=
#{cynprBowf}.40=
#{cynprBowf}.41=
#{cynprBowf}.42=
#{cynprBowf}.43=
#{cynprBowf}.44=
#{cynprBowf}.45=
#{cynprBowf}.46=
#{cynprBowf}.47=
#{cynprBowf}.48=
#{cynprBowf}.49=
#{cynprBowf}.5=
#{cynprBowf}.50=
#{cynprBowf}.51=
#{cynprBowf}.52=
#{cynprBowf}.53=
#{cynprBowf}.54=
#{cynprBowf}.55=
#{cynprBowf}.56=
#{cynprBowf}.57=
#{cynprBowf}.58=
#{cynprBowf}.59=
#{cynprBowf}.6=
#{cynprBowf}.60=
#{cynprBowf}.61=
#{cynprBowf}.62=
#{cynprBowf}.63=
#{cynprBowf}.64=
#{cynprBowf}.65=
#{cynprBowf}.66=
#{cynprBowf}.67= 125
#{cynprBowf}.68=
#{cynprBowf}.69=
#{cynprBowf}.7=
#{cynprBowf}.70=
#{cynprBowf}.71=
#{cynprBowf}.72=
#{cynprBowf}.73=
#{cynprBowf}.74=
#{cynprBowf}.75=
#{cynprBowf}.76=
#{cynprBowf}.77=
#{cynprBowf}.78=
#{cynprBowf}.79=
#{cynprBowf}.8= 3
#{cynprBowf}.80=
#{cynprBowf}.81=
#{cynprBowf}.82=
#{cynprBowf}.83=
#{cynprBowf}.84=
#{cynprBowf}.85=
#{cynprBowf}.86=
#{cynprBowf}.87=
#{cynprBowf}.88=
#{cynprBowf}.89=
#{cynprBowf}.9= 103
#{cynprBowf}.90=
#{cynprBowf}.91=
#{cynprBowf}.92= 56
#{cynprBowf}.93=
#{cynprBowf}.94= 9
#{cynprBowf}.95= 57
#{cynprBowf}.96= 10 40
#{cynprBowf}.97= 58 29
#{cynprBowf}.98=
#{cynprBowf}.99=
#{cynprNooe}.1=1
#{cynprNooe}.10=0
#{cynprNooe}.100=0
#{cynprNooe}.101=0
#{cynprNooe}.102=0
#{cynprNooe}.103=0
#{cynprNooe}.104=0
#{cynprNooe}.105=0
#{cynprNooe}.106=0
#{cynprNooe}.107=0
#{cynprNooe}.108=0
#{cynprNooe}.109=0
#{cynprNooe}.11=0
#{cynprNooe}.110=0
#{cynprNooe}.111=0
#{cynprNooe}.112=0
#{cynprNooe}.113=0
#{cynprNooe}.114=0
#{cynprNooe}.115=0
#{cynprNooe}.116=0
#{cynprNooe}.117=0
#{cynprNooe}.118=0
#{cynprNooe}.119=0
#{cynprNooe}.12=0
#{cynprNooe}.120=0
#{cynprNooe}.121=0
#{cynprNooe}.122=0
#{cynprNooe}.123=0
#{cynprNooe}.124=0
#{cynprNooe}.125=0
#{cynprNooe}.126=0
#{cynprNooe}.127=0
#{cynprNooe}.128=0
#{cynprNooe}.129=0
#{cynprNooe}.13=0
#{cynprNooe}.130=0
#{cynprNooe}.131=0
#{cynprNooe}.132=0
#{cynprNooe}.133=0
#{cynprNooe}.134=0
#{cynprNooe}.135=0
#{cynprNooe}.136=0
#{cynprNooe}.137=0
#{cynprNooe}.138=0
#{cynprNooe}.139=0
#{cynprNooe}.14=0
#{cynprNooe}.140=0
#{cynprNooe}.15=0
#{cynprNooe}.16=0
#{cynprNooe}.17=0
#{cynprNooe}.18=0
#{cynprNooe}.19=0
#{cynprNooe}.2=0
#{cynprNooe}.20=0
#{cynprNooe}.21=0
#{cynprNooe}.22=0
#{cynprNooe}.23=0
#{cynprNooe}.24=0
#{cynprNooe}.25=0
#{cynprNooe}.26=0
#{cynprNooe}.27=0
#{cynprNooe}.28=0
#{cynprNooe}.29=0
#{cynprNooe}.3=0
#{cynprNooe}.30=0
#{cynprNooe}.31=0
#{cynprNooe}.32=0
#{cynprNooe}.33=0
#{cynprNooe}.34=0
#{cynprNooe}.35=0
#{cynprNooe}.36=0
#{cynprNooe}.37=0
#{cynprNooe}.38=0
#{cynprNooe}.39=0
#{cynprNooe}.4=1
#{cynprNooe}.40=0
#{cynprNooe}.41=0
#{cynprNooe}.42=0
#{cynprNooe}.43=0
#{cynprNooe}.44=0
#{cynprNooe}.45=0
#{cynprNooe}.46=0
#{cynprNooe}.47=0
#{cynprNooe}.48=0
#{cynprNooe}.49=0
#{cynprNooe}.5=2
#{cynprNooe}.50=0
#{cynprNooe}.51=0
#{cynprNooe}.52=0
#{cynprNooe}.53=0
#{cynprNooe}.54=0
#{cynprNooe}.55=0
#{cynprNooe}.56=0
#{cynprNooe}.57=0
#{cynprNooe}.58=0
#{cynprNooe}.59=0
#{cynprNooe}.6=0
#{cynprNooe}.60=0
#{cynprNooe}.61=0
#{cynprNooe}.62=0
#{cynprNooe}.63=0
#{cynprNooe}.64=0
#{cynprNooe}.65=0
#{cynprNooe}.66=0
#{cynprNooe}.67=0
#{cynprNooe}.68=0
#{cynprNooe}.69=0
#{cynprNooe}.7=1
#{cynprNooe}.70=0
#{cynprNooe}.71=0
#{cynprNooe}.72=0
#{cynprNooe}.73=0
#{cynprNooe}.74=0
#{cynprNooe}.75=0
#{cynprNooe}.76=0
#{cynprNooe}.77=0
#{cynprNooe}.78=0
#{cynprNooe}.79=0
#{cynprNooe}.8=0
#{cynprNooe}.80=0
#{cynprNooe}.81=0
#{cynprNooe}.82=0
#{cynprNooe}.83=0
#{cynprNooe}.84=0
#{cynprNooe}.85=0
#{cynprNooe}.86=0
#{cynprNooe}.87=0
#{cynprNooe}.88=0
#{cynprNooe}.89=0
#{cynprNooe}.9=0
#{cynprNooe}.90=0
#{cynprNooe}.91=0
#{cynprNooe}.92=0
#{cynprNooe}.93=0
#{cynprNooe}.94=0
#{cynprNooe}.95=0
#{cynprNooe}.96=0
#{cynprNooe}.97=0
#{cynprNooe}.98=0
#{cynprNooe}.99=0
#{fnirIrefvba}=1
#{fpbevat}=0
#{gheaf}=5
#{jnfQnex}=0
#{nooAhz}=5
#{obahf}=0
#{pybfrq}=0
#{pybfvat}=0
#{pybpx1}=30
#{pybpx2}=50
#{qjnesByqYbp}.1=19
#{qjnesByqYbp}.2=27
#{qjnesByqYbp}.3=33
#{qjnesByqYbp}.4=44
#{qjnesByqYbp}.5=64
#{qjnesByqYbp}.6=114
#{qjnesFgngr}=0
#{qjnesFrra}.1=0
#{qjnesFrra}.2=0
#{qjnesFrra}.3=0
#{qjnesFrra}.4=0
#{qjnesFrra}.5=0
#{qjnesFrra}.6=0
#{qjnesYbp}.1=19
#{qjnesYbp}.2=27
#{qjnesYbp}.3=33
#{qjnesYbp}.4=44
#{qjnesYbp}.5=64
#{qjnesYbp}.6=114
#{qrgnvyPag}=0
#{qrnqQjnesPag}=0
#{qvrPag}=0
#{sbbPag}=0
#{tnirhc}=0
#{ubyqPag}=0
#{uvagGheaf}.2=0
#{uvagGheaf}.3=0
#{uvagGheaf}.4=0
#{uvagGheaf}.5=0
#{uvagGheaf}.6=0
#{uvagGheaf}.7=0
#{uvagGheaf}.8=0
#{uvagGheaf}.9=0
#{uvagrq}.2=0
#{uvagrq}.3=1
#{uvagrq}.4=0
#{uvagrq}.5=0
#{uvagrq}.6=0
#{uvagrq}.7=0
#{uvagrq}.8=0
#{uvagrq}.9=0
#{xavsrYbp}=0
#{ybfgPag}=0
#{ybp}=7
#{ynzcJnea}=0
#{ynzcYbj}=0
#{ynzcYvsr}=1000

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#9 Post by dbenham » 27 Aug 2013 07:22

Great description of the problem brinda, thanks.

I'll see if I can reproduce the behavior on my XP virtual machine, and (hopefully) fix the problem. It may take a while though, because I have a lot of other things going on right now.


Dave Benham

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#10 Post by dbenham » 27 Aug 2013 22:23

OK - I diagnosed the problem :D

The problem was from a seemingly innocuous statement like: SET "VAR="

It turns out that XP silently sets ERRORLEVEL to 1 when undefining a variable that does not exist (thanks penpen for the clarification). But more modern Windows systems do not set the ERRORLEVEL to 1. The unexpected error was causing a problem with my conditional logic in the LOAD routine.

I had tested the LOAD function on XP before, but since then I restructured some unrelated logic that inadvertently brought the error into play.

I've fixed the immediate problem, and uploaded version 1.2 to my Google site. I think it is good to go, but there is the potential for more unintended side effects on XP.

When I get some more time I will do some play throughs on XP to make sure everything is working as it should.


Dave Benham
Last edited by dbenham on 28 Aug 2013 09:53, edited 1 time in total.

carlos
Expert
Posts: 503
Joined: 20 Aug 2010 13:57
Location: Chile
Contact:

Re: Colossal Cave Adventure in batch

#11 Post by carlos » 28 Aug 2013 09:18

Dave, I read that using the .bat extension in filename errorlevel change only on failure, and using .cmd errorlevel change on error and success.

test.bat

Code: Select all

@echo off
cmd /c exit /b 20
set "var=foo"
echo(%errorlevel%
pause

prints 20.

test.cmd

Code: Select all

@echo off
cmd /c exit /b 20
set "var=foo"
echo(%errorlevel%
pause

prints 0.

maybe this info should be useful for your implentation.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#12 Post by dbenham » 28 Aug 2013 09:49

Thanks carlos. Funny you should say that. I just wrote the same thing in a private message to penpen, and then realized I could have probably solved the ADVENTURE XP problem by switching to the .CMD extension.

But I have already solved the problem by explicitly exiting routines with EXIT /B 0 instead of just EXIT /B. (Except a few where I intentionally want to return the current ERRORLEVEL).

I don't think I ever test %ERRORLEVEL% in my code. That is susceptible to detecting errors from commands executed long ago.

My code exclusively uses && and ||, which only look at the return status of the most recently executed command. Where I ran into a problem is that in the LOAD routine, the last command prior to || was a CALL to a subroutine. The routine was setting ERRORLEVEL to 1 early in the routine, and nothing cleared it. So the routine's EXIT /B was passing back an error to CALL, which then in turn fired the || logic. Simply exiting with EXIT /B 0 solved the problem.

Here is the logic that was causing the problem:

Code: Select all

comand1 && (
  successCommand1
  successCommand2
  call  :subroutine
) || (
  failureCommand
)

The :subroutine was returning error status 1 because of SET "VAR=" early in the routine, even though the routine was executing perfectly.


Dave Benham

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#13 Post by dbenham » 28 Aug 2013 20:46

I've posted version 1.3 to my Google site. The only difference is it disables some debugging commands that were accidentally left in place in the prior versions.

Dave Benham

brinda
Posts: 78
Joined: 25 Apr 2012 23:51

Re: Colossal Cave Adventure in batch

#14 Post by brinda » 29 Aug 2013 04:46

dave,
thanks all good :D

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Colossal Cave Adventure in batch

#15 Post by dbenham » 27 Oct 2013 10:02

I've posted version 1.4 to my Google site. It has significant bug fixes to the end game.

I had posted info about my batch port to Rick Adams' Colossal Cave Adventure Forum, and forum user Quuxplusone sent me a private message with invaluable info on how to fix some end game problems. The prior version worked somewhat, but the new version is much better.


Dave Benham

Post Reply