Hunt the Wumpus

From More BASIC Computer Games, 1979 by David H. Ahl Wumpus 1.

BASIC09 edition

PROCEDURE wumpus
     REM *** HUNT THE WUMPUS ***
     DIM legal:BOOLEAN
     DIM lt,j,k:INTEGER
     DIM path(5):INTEGER
     DIM feature(6),origsetup(6):INTEGER
     DIM cave(20,3):INTEGER

     INPUT "INSTRUCTIONS (Y-N)? ", i$
     IF i$="Y" OR i$="y" THEN
         GOSUB 375
     ENDIF

80   REM *** SET UP CAVE (DODECAHEDRAL NODE LIST) ***
     FOR j=1 TO 20
         FOR k=1 TO 3
             READ cave(j,k)
         NEXT k
     NEXT j
     DATA 2,5,8,1,3,10,2,4,12,3,5,14,1,4,6
     DATA 5,7,15,6,8,17,1,7,9,8,10,18,2,9,11
     DATA 10,12,19,3,11,13,12,14,20,4,13,15,6,14,16
     DATA 15,17,20,7,16,18,9,17,19,11,18,20,13,16,19

     GOSUB 320
230  LOOP
       REM *** SET NO. OF ARROWS ***
       LET a=5
       LET lt=feature(1)
       REM *** RUN THE GAME ***
       PRINT "HUNT THE WUMPUS"
       REM *** HAZARD WARNING AND LOCATION ***
255    GOSUB 585
       REM *** MOVE OR SHOOT ***
       GOSUB 670
       ON o GOTO 280,300
       REM *** SHOOT ***
280    GOSUB 715
       IF duel=0 THEN 255
       GOTO 310
       REM *** MOVE ***
300    GOSUB 975
       IF duel=0 THEN 255

310    IF duel > 0 THEN
         REM *** WIN ***
         PRINT "HEE HEE HEE - THE WUMPUS'LL GET YOU NEXT TIME!!"
       ELSE
         REM *** LOSE ***
         PRINT "HA HA HA - YOU LOSE!"
       ENDIF
       FOR j=1 TO 6
         LET feature(j)=origsetup(j)
       NEXT j
       INPUT "SAME SETUP (Y-N)? ", i$
       IF i$<>"Y" AND i$<>"y" THEN
         GOSUB 320
       ENDIF
     ENDLOOP

320  REM *** LOCATE L ARRAY ITEMS ***
     REM *** 1-YOU, 2-WUMPUS, 3&4-PITS, 5&6-BATS ***

     FOR j=1 TO 6
         LET feature(j)=INT(20*RND(1))+1
         LET origsetup(j)=feature(j)
     NEXT j

     REM *** CHECK FOR CROSSOVERS (IE feature(1)=feature(2), ETC) ***
     FOR j=1 TO 6
         FOR k=1 TO 6
             IF j=k THEN 330
             IF feature(j)=feature(k) THEN 320
330      NEXT k
     NEXT j
     RETURN

375  REM *** INSTRUCTIONS ***
     PRINT "WELCOME TO 'HUNT THE WUMPUS'"
     PRINT "  THE WUMPUS LIVES IN A CAVE OF 20 ROOMS. EACH ROOM"
     PRINT "HAS 3 TUNNELS LEADING TO OTHER ROOMS. (LOOK AT A"
     PRINT "DODECAHEDRON TO SEE HOW THIS WORKS-IF YOU DON'T KNOW"
     PRINT "WHAT A DODECAHEDRON IS, ASK SOMEONE)"
     PRINT
     PRINT "     HAZARDS:"
     PRINT " BOTTOMLESS PITS - TWO ROOMS HAVE BOTTOMLESS PITS IN THEM"
     PRINT "     IF YOU GO THERE, YOU FALL INTO THE PIT (& LOSE!)"
     PRINT " SUPER BATS - TWO OTHER ROOMS HAVE SUPER BATS. IF YOU"
     PRINT "     GO THERE, A BAT GRABS YOU AND TAKES YOU TO SOME OTHER"
     PRINT "     ROOM AT RANDOM. (WHICH MAY BE TROUBLESOME)"
     INPUT "HIT RETURN TO CONTINUE", a$
     PRINT "     WUMPUS:"
     PRINT " THE WUMPUS IS NOT BOTHERED BY HAZARDS (HE HAS SUCKER"
     PRINT " FEET AND IS TOO BIG FOR A BAT TO LIFT).  USUALLY"
     PRINT " HE IS ASLEEP.  TWO THINGS WAKE HIM UP: YOU SHOOTING AN"
     PRINT " ARROW OR YOU ENTERING HIS ROOM."
     PRINT "     IF THE WUMPUS WAKES HE MOVES (P=.75) ONE ROOM"
     PRINT " OR STAYS STILL (P=.25).  AFTER THAT, IF HE IS WHERE YOU"
     PRINT " ARE, HE EATS YOU UP AND YOU LOSE!"
     PRINT
     PRINT "     YOU:"
     PRINT " EACH TURN YOU MAY MOVE OR SHOOT A CROOKED ARROW"
     PRINT "   MOVING:  YOU CAN MOVE ONE ROOM (THRU ONE TUNNEL)"
     PRINT "   ARROWS:  YOU HAVE 5 ARROWS.  YOU LOSE WHEN YOU RUN OUT"
     PRINT "   EACH ARROW CAN GO FROM 1 TO 5 ROOMS. YOU AIM BY TELLING"
     PRINT "   THE COMPUTER THE ROOM#S YOU WANT THE ARROW TO GO TO."
     PRINT "   IF THE ARROW CAN'T GO THAT WAY (IF NO TUNNEL) IT MOVES"
     PRINT "   AT RANDOM TO THE NEXT ROOM."
     PRINT "     IF THE ARROW HITS THE WUMPUS, YOU WIN."
     PRINT "     IF THE ARROW HITS YOU, YOU LOSE."
     INPUT "HIT RETURN TO CONTINUE",a$
     PRINT "    WARNINGS:"
     PRINT "     WHEN YOU ARE ONE ROOM AWAY FROM A WUMPUS OR HAZARD,"
     PRINT "     THE COMPUTER SAYS:"
     PRINT " WUMPUS:  'I SMELL A WUMPUS'"
     PRINT " BAT   :  'BATS NEARBY'"
     PRINT " PIT   :  'I FEEL A DRAFT'"
     PRINT
     RETURN

585  REM *** PRINT LOCATION & HAZARD WARNINGS ***
     PRINT
     FOR j=2 TO 6
         FOR k=1 TO 3
             IF cave(feature(1),k)<>feature(j) THEN 600
             ON j-1 GOSUB 615,625,625,635,635
600      NEXT k
     NEXT j
     PRINT "YOU ARE IN ROOM "; feature(1)
     PRINT "TUNNELS LEAD TO "; cave(lt,1); " "; cave(lt,2); " "; cave(lt,3)
     PRINT
     RETURN

615  PRINT "I SMELL A WUMPUS!"
     RETURN

625  PRINT "I FEEL A DRAFT"
     RETURN

635  PRINT "BATS NEARBY!"
     RETURN

670  REM *** CHOOSE OPTION ***
     LOOP
       INPUT "SHOOT OR MOVE (S-M)? ", i$
       EXITIF i$="S" OR i$="s" THEN
         LET o=1
       ENDEXIT
       EXITIF i$="M" OR i$="m" THEN
         LET o=2
       ENDEXIT
     ENDLOOP
     RETURN

715  REM *** ARROW ROUTINE ***
     LET duel=0
     REM *** PATH OF ARROW ***
     REPEAT
         INPUT "NO. OF ROOMS (1-5)? ", j9
     UNTIL j9 > 0 AND j9 < 6
     FOR k=1 TO j9
         760 INPUT "ROOM # ", path(k)
         IF k<=2 THEN 790
         IF path(k) <> path(k-2) THEN 790
         PRINT "ARROWS AREN'T THAT CROOKED - TRY ANOTHER ROOM"
         GOTO 760
790  NEXT k
     REM *** SHOOT ARROW ***
     LET lt=feature(1)
     FOR k=1 TO j9
         FOR k1=1 TO 3
             IF cave(lt,k1)=path(k) THEN 895
         NEXT k1
         REM *** NO TUNNEL FOR ARROW ***
         LET lt=cave(lt,INT(3*RND(1))+1)
         GOTO 900
840  NEXT k

     PRINT "MISSED"
     LET lt=feature(1)
     REM *** MOVE WUMPUS ***
     GOSUB 940
     REM *** AMMO CHECK ***
     LET a=a-1
     IF a > 0 THEN
         RETURN
     ENDIF
     LET duel= -1
     RETURN

     REM *** SEE IF ARROW IS AT feature(1) OR AT feature(2)
895  LET lt=path(k)
900  IF lt=feature(2) THEN
         PRINT "AHA! YOU GOT THE WUMPUS!"
         LET duel = 1
         RETURN
     ENDIF
     IF lt<>feature(1) THEN 840
     PRINT "OUCH! ARROW GOT YOU!"
     LET duel= -1
     RETURN

940  REM *** MOVE WUMPUS ROUTINE ***
     LET k=INT(4*RND(1))+1
     IF k<>4 THEN
       LET feature(2)=cave(feature(2),k)
     ENDIF
     IF feature(2) = lt THEN
         PRINT "TSK TSK TSK - WUMPUS GOT YOU!"
         LET duel= -1
     ENDIF
     RETURN

975  REM *** MOVE ROUTINE ***
     LET duel=0
     REPEAT
       REPEAT
         INPUT "WHERE TO? ", lt
       UNTIL lt >= 1 AND lt <= 20
       LET legal=FALSE
       FOR k=1 TO 3
         REM *** CHECK IF LEGAL MOVE ***
         IF cave(feature(1),k)=lt THEN
           LET legal=TRUE
         ENDIF
       NEXT k
       IF lt=feature(1) THEN
         LET legal=TRUE
       ENDIF
       IF legal=FALSE THEN
         PRINT "NOT POSSIBLE -";
       ENDIF
     UNTIL legal

     REM *** CHECK FOR HAZARDS ***
1045 LET feature(1)=lt
     REM *** WUMPUS ***
     IF lt = feature(2) THEN
       PRINT "... OOPS! BUMPED A WUMPUS!"
       REM *** MOVE WUMPUS ***
       GOSUB 940
       IF duel<>0 THEN
         RETURN
       ENDIF
     ENDIF
     REM *** PIT ***
     IF lt=feature(3) OR lt=feature(4) THEN
       PRINT "YYYYIIIIEEEE . . . FELL IN PIT"
       LET duel= -1
       RETURN
     ENDIF

     REM *** BATS ***
     IF lt=feature(5) OR lt=feature(6) THEN
       PRINT "ZAP--SUPER BAT SNATCH! ELSEWHEREVILLE FOR YOU!"
       LET lt=INT(20*RND(1))+1
       GOTO 1045
     ENDIF
     RETURN

     END



Sidst opdateret: 2018/10/02
Website vedligeholdt af Søren Roug