         Edinburgh IMP77 Compiler - Version 8.4

    1  %EXTERNALROUTINE WUMPUS (%STRING(255) PARMZZZ)
    2   !%EXTERNALROUTINESPEC PROMPT(%STRING(15)S)
    3   !%EXTERNALSTRINGFNSPEC TIME
    4   %INTEGERFNSPEC FNR(%INTEGER I)
    5   %INTEGERARRAY R(1:20,1:3),BOG(1:20)
    6   %ROUTINE DRAIN
    7    SKIP SYMBOL %WHILE NEXT SYMBOL#NL ; SKIP SYMBOL
    8    %END
    9   %INTEGERFN GETANS
   10    %INTEGER SYM
   11     SKIP SYMBOL %WHILE 'N'#NEXTSYMBOL&95#'Y'
   12     SYM=NEXTSYMBOL&95 ; DRAIN ; %RESULT=SYM
   13    %END
   14   %ROUTINE GET REQUEST(%INTEGERNAME SYM)
   15    %CYCLE
   16     SYM=NEXTCH
   17     %IF '0'<=SYM<='9' %THENEXIT
   18     %IF SYM='s' %OR SYM='S' %THENEXIT
   19    SKIPSYMBOL
   20    %REPEAT
   21    %IF SYM='s' %THEN SYM='S'
   22    %IF SYM#'S' %THEN READ(SYM)
   23    DRAIN
   24    %END
   25   %INTEGER NO OF ARROWS, MOVE TO, W, H, B1, B2, P1, P2, WO, PO, BO
   26   %INTEGER N1, N2, I, J, K, L, P, T, A1, ANS
   27   %STRING(255) LINE
   28   %ROUTINE RANDOMISE
   29    %INTEGER TEMP
   30     N1=0
   31     LINE=TIME
   32     %CYCLE I=1,1,LENGTH(LINE)
?Non-local
   33      N1=N1+CHARNO(LINE,I)
   34     %REPEAT
   35     N2=10000-N1
   36     %CYCLE I=1,1,20
?Non-local
   37      TEMP=FNR(20)
   38      BOG(I)=0
   39     %REPEAT
   40     %CYCLE I=1,1,20
?Non-local
   41      %CYCLE J=1,1,3
?Non-local
   42       R(I,J)=0
   43      %REPEAT
   44     %REPEAT
   45     P=1
   46     R(1,1)=99
   47     %CYCLE I=1,1,19
?Non-local
   48      T=FNR(20) %UNTIL R(T,1)=0
   49      R(P,2)=T
   50      R(T,1)=P
   51      P=T
   52     %REPEAT
   53     R(P,2)=1
   54     R(1,1)=P
   55     P2=FNR(20)
   56     R(P2,3)=99
   57     R(R(P2,2),3)=99
   58     P=1
   59     %CYCLE I=1,1,8
?Non-local
   60      P=P+1 %WHILE R(P,3)>0
   61      T=FNR(20) %UNTIL R(T,1)#P  %AND  R(T,2)#P  %AND  P#T  %AND  R(T,3)=0
   62      R(P,3)=T
   63      R(T,3)=P
   64      P=P+1
   65     %REPEAT
   66     LABEL: T=FNR(20) %UNTIL %C
   67+              P2#T  %AND  R(P2,1)#T  %AND  R(P2,2)#T  %AND  R(T,3)=0
   68     P=R(P2,2)
   69     R(P2,3)=T
   70     R(T,3)=P2
   71     %IF R(R(P,1),3)=0 %OR R(R(P,2),3)=0 %THEN R(T,3)=0 %AND ->LABEL
   72     T=FNR(20) %UNTIL P#T %AND R(P,2)#T %AND R(P,1)#T %AND R(T,3)=0
   73     R(P,3)=T
   74     R(T,3)=P
   75     W=FNR(20)
   76     B1=FNR(20)
   77     B2=FNR(20) %UNTIL B2#B1
   78     P1=FNR(20)
   79     P2=FNR(20) %UNTIL P2#P1
   80     H=FNR(20)  %UNTIL  H#W  %AND  H#P1  %AND  H#P2  %AND  H#B1  %AND H#B2
   81    %END
   82   %ROUTINE  GET NOW
   83    %INTEGER H1
   84     WO=0 ; BO=0 ; PO=0
   85     %CYCLE I=1,1,3
?Non-local
   86      H1=R(H,I)
   87      %IF H1=P1 %OR H1=P2 %THEN PO=1
   88      %IF H1=B1 %OR H1=B2 %THEN BO=1
   89      %IF H1=W %THEN WO=1
   90      %CYCLE J=1,1,3
?Non-local
   91       %IF  R(H1,1)=W  %OR  R(H1,2)=W  %OR  R(H1,3)=W  %THEN WO=1
   92      %REPEAT
   93     %REPEAT
   94    %END
   95   %ROUTINE SUMMARIZE(%INTEGER I)
   96    %IF I>0 %THEN ->SKIP
   97    PRINTSTRING("You are in room")
   98    WRITE(H,0);NEWLINE
   99    SKIP:PRINTSTRING("There are passages to")
  100    WRITE(R(H,1),0);PRINTCH(',')
  101    WRITE(R(H,2),0);PRINTCH(',')
  102    WRITE(R(H,3),0);NEWLINE
  103    %IF WO=1 %THEN PRINTSTRING("I smell a Wumpus") %AND NEWLINE
  104    %IF PO=1 %THEN PRINTSTRING("I feel a draft") %AND NEWLINE
  105    %IF BO=1 %THEN PRINTSTRING("I hear squeaking") %AND NEWLINE
  106   %END
  107   %INTEGERFN FNR(%INTEGER I)
  108    %REAL RTEMP
  109    %INTEGER TEMP
  110     TEMP=((3*(N1<<14)+N2)+N2<<14)&(1<<28-1)
  111     N2=TEMP&X'3FFF'
  112     N1=(TEMP-N2)>>14
  113     RTEMP=TEMP/(1<<28)
  114     %RESULT=1+INTPT(I*RTEMP)
  115    %END
  116    PRINTSTRING("Would you like to see the rules?") ; NEWLINE
  117    %IF GETANS='Y' %THENSTART
  118     PRINTSTRING("Sorry, chum - but there aint none!!!")
  119     NEWLINE
  120    %FINISH
  121    PROMPT(":")
  122    BEGIN: RANDOMISE
  123    NO OF ARROWS=5
  124    MOVE LOOP: GET NOW
  125    ERROR INPUT: SUMMARIZE(0)
  126    GET MOVE: PRINTSTRING("Your move, or ""S"" to shoot.") ; NEWLINE
  127    GET REQUEST(MOVE TO)
  128    %IF MOVE TO='S' %THEN ->SHOOT %ELSE ->MOVE
  129    WHAT ERR:
  130    PRINTSTRING("What, er..");PRINTCH(7);NEWLINE;->ERROR INPUT
  131    MOVE:
  132    %IF R(H,1)=MOVETO %OR R(H,2)=MOVETO %OR R(H,3)=MOVETO %START
  133     H=MOVE TO
  134    %FINISHELSESTART
  135     ->WHAT ERR
  136    %FINISH
  137    CHECK: %IF H=W %THEN ->EAT HUNTER
  138    %IF H=P1 %OR H=P2 %THEN ->PIT
  139    %IF H=B1 %OR H=B2 %THEN ->BAT
  140    %IF BOG(H)#0 %THEN ->TOILET
  141    ->MOVE LOOP
  142    BAT: LOOP:
  143    T=FNR(20)
  144    %IF T=H %THEN ->LOOP
  145    H=T
  146    PRINTSTRING("You have been captured by a bat !!!");NEWLINE
  147    PRINTSTRING("You are now in room");WRITE(H,0);NEWLINE
  148    %IF H=W %OR H=B1 %OR H=B2 %OR H=P1 %OR H=P2 %THEN ->CHECK
  149    GET NOW
  150    SUMMARIZE(1)
  151    ->GET MOVE
  152    EAT HUNTER:
  153    PRINTSTRING("You were eaten by the Wumpus!! You LOSE!!!")
  154    ->FINISH
  155    PIT:
  156    PRINTSTRING("You fell into a BOTTOMless pit!! ")
  157    PRINTSTRING("You LOSE!!!") %AND ->FINISH %UNLESS %C
  158+        FNR(10)=10 %AND (H=B1 %OR H=B2)
  159    PRINTSTRING("But .... ");NEWLINE ; ->BAT
  160    SHOOT: %IF NO OF ARROWS=0 %THEN ->NO ARROWS
  161    NO OF ARROWS=NO OF ARROWS-1
  162    A1=H
  163    %CYCLE I=1,1,5
  164     GET ARROW: PRINTSTRING("Where to?") ; NEWLINE
  165     GET REQUEST(J)
  166     %EXITIF J='S'
  167     ->BOUNCE %UNLESS J=R(A1,1)  %OR  J=R(A1,2)  %OR  J=R(A1,3)
  168     ->BOUNCE %UNLESS FNR(10)<10
  169     A1=J ; %IF A1=W %THEN ->KILL ; %IF A1=H %THEN ->SUICIDE
  170     PRINTSTRING("Missed !!!") ; NEWLINE
  171    %REPEAT
  172    WAKE WUMPUS: %IF FNR(4)=4 %THEN ->MOVELOOP
  173    BOG(W)=1
  174    W=R(W,FNR(3));  BOG(W)=0 ;
  175    %IF H#W %THENSTART
  176     PRINTSTRING("You've woken the Wumpus!!!")
  177     NEWLINE
  178     ->MOVE LOOP
  179    %FINISH
  180    PRINTSTRING("The Wumpus moved into your room !!!"); NEWLINE
  181    ->EAT HUNTER
  182    SUICIDE: PRINTSTRING("Fool, you shot yourself !!!"); NEWLINE; ->FINISH
  183    KILL: PRINTSTRING("CONGRATULATIONS, Great White Hunter !!!"); NEWLINE
  184    PRINTSTRING("You slew the dreaded Wumpus !!!"); ->FINISH
  185    NO ARROWS: PRINTSTRING("No arrows left !!!");NEWLINE; ->MOVE LOOP
  186    TOILET: PRINTSTRING("Whoops! You've landed in Wump-Shit!!!")
  187    NEWLINE ; ->MOVE LOOP
  188    BOUNCE:
  189     %CYCLE K=I,1,5
  190      PRINTSTRING("BouNCE!!!")
  191      NEWLINE
  192      A1=R(A1,FNR(3))
  193      %IF A1=H %THEN ->SUICIDE
  194      %IF A1=W %THEN ->KILL
  195     %REPEAT
  196    ->WAKE WUMPUS
  197    FINISH: NEWLINE
  198    PRINTSTRING("Another game?")
  199    NEWLINE
  200    ANS=GETANS
  201    %IF ANS='Y' %THEN ANS=FNR(10000) %AND ->BEGIN
  202   %END
?GETARROW unused
?L unused
?PARMZZZ unused
  203  
  204  %begin
  205    wumpus("")
  206  %end
  207  
  208  %ENDOFFILE

  228 Statements compiled
