JustPaste.it
User avatar
@anonymous · Apr 6, 2024 · edited: Apr 12, 2024

Tiny Python Adventure

sketch1712415579097.png

 

From: Chuck Darling

Re: Colossal Cave

 

Colossal Cave is a

Real Place.

 

The Original Colossal Cave

Simulation was written by

Willie Crowther based

on ACTUAL CAVE DESCRIPTIONS.

 

Willie and his wife Pat

explored Colossal Cave,

Pat found the link

between Colossal Cave

and the Mammoth Cave System.

 

Over 600 miles of CAVE !

 

Very dangerous to explore.

 

You could be 10 miles into

a twisty cave, and it could

start raining up above,

and your cave could FLOOD!

 

Then you'd DROWN.

 

Don't try it.

 

Pat and Willie plotted Digital

Maps of her explorations.

 

Willie was a programmer,

working for BBN, 

programming the early

ARPANET...

sketch1712682021316.png

gif_20240411_173533_627.gif

 

(which has been

rewritten and hardware

expanded into today's

"Internet".)

 

Willie & Pat Divorced...

 

Willie made his cave

simulation into a game

for his 2 kids.

 

Like I did, when I wrote SimulaWPD for my kids ...

 

Don Woods added fantasy

elements to Willie's code, to

make it a game.

 

The earliest ADVENT CODE

was written on a PDP-10,

in a version of late-60's

FORTRAN that was extended

with a package called MDL.

 

The early code used 5-character

commands, because that Fortran would pack words together into 18 bit words

to save memory space.

 

The game played on a

Teletype Terminal...

No Video Monitors !

gif_20240408_074359_125.gif

******************************

* I first played ADVENTURE

* around 1977 

* on Bob Hanzlian's work

* computer after midnight.

* The QM-1 was running a

* PDP-10 Emulation, and the

* game played on a Teletype...

* I also played Star Trek..!

* Click the gif to see a

* Teletype Adventure Session...

****************************

 

 

A $10,000 dollar PDP-10

only had 56 kilobytes of RAM

Memory.

 

Know how much that is ?

 

23 typed pages.

 

Imagine trying to fit

EVERYTHING into 56K !

 

The Operating System...

The bootstrap loader

The Paper-Tape reader

The Teletype-Terminal program

The programming language...

and finally,

Your Program.

 

Very clever programming

methods were used.

 

They HAD to be.

 

That source code is available,

but you can't run it without

a PDP-10 running MDL.

 

Others have "ported" the

ADVENT code to C, etc,

but the code is still basically

impossible to follow.

 

When early 8-bit Personal Computers appeared in the

LATE 70's and '80's,

 

They all used BASIC

as their programming language.

 

You can't really write ADVENTURE in BASIC,

though many tried...

 

I did...

 

I extended TS-1000 Wumpus

into a Star Trek game...

 

I wrote 00Cedar and

JPICedar in Turbo Pascal...

Few of you can program in Pascal now ..

 

Turbo Pascal was the

FIRST compilable language

for the IBM PC.

 

I learned Pascal at

The University of Buffalo

in 1982-83...

on Punched Cards.

 

Ever write a Streaming

Text-Editor, that can

right justify,

center justify,

left justify,

replace or delete words...

from a file of text,

 

by writing command cards

that would tell the

program what to do?

 

In Pascal...

On PUNCHED CARDS ???

 

I did. CS113.

 

The card deck was

about 3" thick.

 

It worked.

 

I got a "b" in the course.

 

I only got a "d" in CS114...

 

BECAUSE THEY HAD GONE

TO ONLINE TERMINALS

AND THE DORM STUDENTS

WOULD SLEEP AT THEM...!

 

I got maybe 45 minutes

of online time, for the entire

semester...

 

Projects were worth 40% of

the GRADE ...

 

I turned in NO PROJECTS !

 

So, starting at 60%... I got a "d".

 

In the current 2024

Computer Environment,

the common language

isn't BASIC.

 

I've only worked with PYTHON

for One Day...and yes, I got it

to work...

 

You try it !

 

#

# Copy text below:

#

# A tiny Python Advent Starter

# Paste into Interpreter and RUN

# Try to make it work !

 

directions = ['north','south','east','west','up','down','xyzzy','plugh']

 

# Data structure to store details of each location in the game

class Location:

    # Constructor - set up

    

    def __init__(self, name, description):

        self.name = name

        self.description = description

        self.linkedLocations = {}   

        

# Empty dictionary - will store which locations are linked to which other locations

 

    def addLink(self, direction, destination):

        # Add link to linkedLocations dictionary 

        #(if the specified direction and destination are valid)

        if direction not in directions:

            raise ValueError('Invalid direction')

        elif destination not in locations:

            raise ValueError('Invalid destination')

        else:

            self.linkedLocations[direction] = destination

 

# Dictionary with location ID strings as keys 

# and Location objects as the values

 

locations =

              'forest':Location('The forest', 'You wander aimlessly in a dark woods, dov''e la diretta via era smarrita... .'),

              'stream':Location('The stream', 'You are by the stream. The stream flows southward.') , 

              'valley':Location('The valley', 'You are in a valley in a forest, beside a rocky stream.'), 

              'hill':Location('The Hill', 'You have climbed up a hill in the forest. There is a building in the distance.'),

              'debris':Location('The Forest', 'You are in a room filled with debris washed from the surface last time it FLOODED ..!'),

              'pit':Location('The Pit', 'You are in a pit deep within the cave.'),

              'Y2':Location('Y2', 'You are deep within the cave. A large boulder is inscribed "Y2".'),

              'building':Location('The Building', 'You are inside a small brick building, a wellhouse for a spring.').}

 

# Join the locations together

locations['forest'].addLink('down','stream')

locations['stream'].addLink('south','slit')

locations['hill'].addLink('east','forest')

locations['building'].addLink('east','forest')

locations['debris'].addLink('east','forest')

locations['Y2'].addLink('east','forest')

locations['pit'].addLink('east','forest')

locations['valley'].addLink('east','forest')

 

# Player will start in the forest

currentLocation = locations['forest']

 

# Main game loop

print('Tiny Python Adventure ')

print(' ')

print('Try to make it work! ')

print(' ')

print(' ')

 

while True:

    # Display description of current location

    print(currentLocation.description)

 

    # Display neighbouring locations

    for linkDirection,linkedLocation in currentLocation.linkedLocations.items():

        print(linkDirection + ': ' + locations[linkedLocation].name)

 

    # Read player input

    command = input('>').lower()

    if command in directions:

        if command not in currentLocation.linkedLocations:

            print('You cannot go that way')

        else:

         # move, if possible

            newLocationID = currentLocation.linkedLocations[command]

            currentLocation = locations[newLocationID]

    else:

     # hints

        print('Try o

ne of: ' + ', '.join(directions)) 

# Show list of directions, separated by commas

 

# copy above text

#

#

 

I program on a Ten Dollar Smartphone.

sketch1712422995446.png

 

Try to make that Python script

into something functional,

and you'll appreciate

my 00Cedar efforts.

 

Chuck

 

# Copy text below:

#

# A tiny Python Advent Starter

# Paste into Interpreter and RUN

# Try to make it work !

directions = ['north','south','east','west','up','down','xyzzy','plugh','open grate','enter','unlock']

#

# Data structure to store details of each location in the game

class Location:

#

    # Constructor - set up

#

    def __init__(self, name, description):

#

        self.name = name

        self.description = description

        self.linkedLocations = {}   

#

# Empty dictionary - will store which locations are linked to which other locations

#

    def addLink(self, direction, destination):

#

        # Add link to linkedLocations dictionary 

        #(if the specified direction and destination are valid)

#

        if direction not in directions:

            raise ValueError('Invalid direction')

        elif destination not in locations:

            raise ValueError('Invalid destination')

        else:

            self.linkedLocations[direction] = destination

#

# Dictionary with location ID strings as keys 

# and Location objects as the values

#

locations ={ 'forest':Location('The forest', 'You wander aimlessly in a dark woods, dovei la diretta via era smarrita... .'),

              'stream':Location('The stream', 'You are by the stream. The stream flows southward.') , 

              'woods':Location('The Woods', 'So harsh and bitter this woods that a little more would be death .'),

              'slit':Location('The Slit', 'All the water in the stream disappears into a tiny slit in the rocks.') , 

              'grate':Location('The Grate', 'A Strong Steel Grate is mounted in Concrete on the Ground.') , 

              'gratlock':Location('GratLock', 'The Grate is LOCKED! You have no KEYS !') , 

              'valley':Location('The valley', 'You are in a valley in a forest, beside a rocky stream.'), 

              'road':Location('The Road', 'You are at the end of the road.'), 

              'hill':Location('The Hill', 'You have climbed up a hill in the forest. There is a building in the distance.'),

              'debris':Location('The Forest', 'You are in a room filled with debris washed from the surface last time it FLOODED ..!'),

              'pit':Location('The Pit', 'You are in a pit deep within the cave.'),

              'dedend46':Location('Dead End', 'The Stream bed dead-ends against a rocky cliff.'),

              'Y2':Location('Y2', 'You are deep within the cave. A large boulder is inscribed "Y2".'),

              'building':Location('The Building', 'You are inside a small brick building, a wellhouse for a spring.') }

#

# Join the locations together

#

locations['forest'].addLink('down','stream')

locations['forest'].addLink('south','woods')

locations['woods'].addLink('south','forest')

locations['stream'].addLink('south','slit')

locations['stream'].addLink('north','valley')

locations['slit'].addLink('south','grate')

locations['slit'].addLink('north','stream')

locations['grate'].addLink('south','dedend46')

locations['grate'].addLink('north','slit')

locations['grate'].addLink('east','forest')

locations['grate'].addLink('west','forest')

locations['gratlock'].addLink('east','forest')

locations['gratlock'].addLink('south','dedend46')

locations['gratlock'].addLink('north','slit')

locations['grate'].addLink('open grate','gratlock')

locations['dedend46'].addLink('north','grate')

locations['grate'].addLink('north','slit')

locations['grate'].addLink('open grate','gratlock')

locations['hill'].addLink('east','forest')

locations['road'].addLink('east','forest')

locations['road'].addLink('west','forest')

locations['road'].addLink('north','hill')

locations['road'].addLink('south','valley')

locations['road'].addLink('enter','building')

locations['building'].addLink('east','forest')

locations['debris'].addLink('east','forest')

locations['Y2'].addLink('east','forest')

locations['pit'].addLink('east','forest')

locations['valley'].addLink('east','forest')

locations['valley'].addLink('west','forest')

locations['valley'].addLink('south','slit')

locations['valley'].addLink('north','road')

#

# Player will start in the forest

#

currentLocation = locations['forest']

#

# Main game loop

while True:

# Display description of current location

    print(currentLocation.description)

# Display neighbouring locations

    for linkDirection,linkedLocation in currentLocation.linkedLocations.items():

        print(linkDirection + ': ' + locations[linkedLocation].name)

#

# Read player input

#

    command = input('>').lower()

    if command in directions:

         if command not in currentLocation.linkedLocations:

             print('You cannot go that way')

#

# move, if possible

         else:

            newLocationID = currentLocation.linkedLocations[command]

            currentLocation = locations[newLocationID]

    else:

        print('Try one of: ' + ', '.join(directions))

        

 

 

 

[ This page built with you https://justpaste.it/drevsJPICedar v. j022924a Sat, 4-6-2024 Time : 1:06p]