Version bump for 1.8 release.
[wumpus.git] / wumpus.c
index bf9f0a6534955fc784c927f5d2fcdcf9b1d65806..857bce2df15bfc267b90165cf3581be85931bf2b 100644 (file)
--- a/wumpus.c
+++ b/wumpus.c
@@ -2,10 +2,7 @@
  * wumpus.c --- a faithful translation of the classic "Hunt The Wumpus" game.
  *
  * Translator: Eric S. Raymond <esr@snark.thyrsus.com>
- * Version: $Id: wumpus.c,v 1.3 1993/11/07 19:19:27 esr Exp esr $
- *
- * This was the state of the art 20 years ago, in 1972.  We've come a long
- * way, baby.
+ * Version: $Id: wumpus.c,v 1.4 1996/05/17 17:30:35 esr Exp esr $
  *
  * The BASIC source is that posted by Magnus Olsson in USENET article
  * <9207071854.AA21847@thep.lu.se>: he wrote
  *
  * So, pretend for a little while that your workstation is an ASR-33 and
  * limber up your fingers for a trip to nostalgia-land...
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
  */
 
 #include <stdio.h>
 #include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/socket.h>
 
 /* 5 REM *** HUNT THE WUMPUS ***                                       */
 
@@ -125,8 +129,6 @@ char *prompt;
 
 void print_instructions()
 {
-    char ebuf[BUFSIZ];
-
 /* 375 REM *** INSTRUCTIONS ***                                                */
 /* 380 PRINT "WELCOME TO 'HUNT THE WUMPUS'"                            */
     puts("WELCOME TO 'HUNT THE WUMPUS'");
@@ -228,16 +230,20 @@ void check_hazards()
     /* 635 PRINT "BATS NEARBY!"                                                */
     /* 640 NEXT K                                                      */
     /* 645 NEXT J                                                      */
-    for (k = 0; k < 3; k++)
+    for (j = WUMPUS; j < LOCS; j++)
     {
-       int room = cave[loc[YOU]][k];
-
-       if (room == loc[WUMPUS])
-           (void) puts("I SMELL A WUMPUS!");
-       else if (room == loc[PIT1] || room == loc[PIT2])
-           (void) puts("I FEEL A DRAFT");
-       else if (room == loc[BATS1] || room == loc[BATS2])
-           (void) puts("BATS NEARBY!");
+       for (k = 0; k < 3; k++)
+       {
+           if (cave[loc[YOU]][k] != loc[j])
+               continue;
+
+           if (j == WUMPUS)
+               (void) puts("I SMELL A WUMPUS!");
+           else if (j == PIT1 || j == PIT2)
+               (void) puts("I FEEL A DRAFT");
+           else if (j == BATS1 || j == BATS2)
+               (void) puts("BATS NEARBY!");
+       }
     }
 
     /* 650 PRINT "YOU ARE IN ROOM "L(1)                                        */
@@ -332,6 +338,11 @@ badrange:
     {
        int     k1;
 
+#ifdef DEBUG
+       (void) printf("Location is %d, looking for tunnel to room %d\n",
+                     scratchloc+1, path[k]+1);
+#endif
+
        /* 810 FOR K1=1 TO 3                                            */
        for (k1 = 0; k1 < 3; k1++)
        {
@@ -349,12 +360,16 @@ badrange:
                 */
                scratchloc = path[k];
 
+#ifdef DEBUG
+               (void) printf("Found tunnel to room %d\n", scratchloc+1);
+#endif
+
                /* this simulates logic at 895 in the BASIC code */
                check_shot();
                if (finished != NOT)
                    return;
+               goto nextpath;
            }
-
            /* 820 NEXT K1                                              */
        }
 
@@ -362,13 +377,20 @@ badrange:
        /* 830 L=S(L,FNB(1))                                            */
        scratchloc = cave[scratchloc][FNB()];
 
+#ifdef DEBUG
+       (void) printf("No tunnel for room %d, new location is %d\n",
+                     path[k]+1, scratchloc+1);
+#endif
+
        /* 835 GOTO 900                                                 */
        check_shot();
+       if (finished != NOT)
+           return;
 
        /* 840 NEXT K                                                   */
+       nextpath: ;
     }
 
-ammo:
     if (finished == NOT)
     {
        /* 845 PRINT "MISSED"                                           */
@@ -428,6 +450,10 @@ void move_wumpus()
     if (k < 3)
        loc[WUMPUS] = cave[loc[WUMPUS]][k];
 
+#ifdef DEBUG
+    (void) printf("Wumpus location is now room %d\n", loc[WUMPUS]+1);
+#endif
+
     /* 955 IF L(2)<>L THEN 970                                         */
     if (loc[WUMPUS] != loc[YOU])
        return;
@@ -495,8 +521,11 @@ goodmove:
        /* 1080 RETURN                                                  */
        (void) puts("... OOPS! BUMPED A WUMPUS!");
        move_wumpus();
+       if (finished < 0)
+           return;
+       /* Fall through since Wumpus could have been in a pit or bat room */
     }
-    else if (scratchloc == loc[PIT1] || scratchloc == loc[PIT2])
+    if (scratchloc == loc[PIT1] || scratchloc == loc[PIT2])
     {
        /* 1085 REM *** PIT ***                                         */
        /* 1090 IF L=L(3) THEN 1100                                     */
@@ -506,8 +535,9 @@ goodmove:
        /* 1110 RETURN                                                  */
        (void) puts("YYYYIIIIEEEE . . . FELL IN PIT");
        finished = LOSE;
+       return;
     }
-    else if (scratchloc == loc[BATS1] || scratchloc == loc[BATS2])
+    if (scratchloc == loc[BATS1] || scratchloc == loc[BATS2])
     {
        /* 1115 REM *** BATS ***                                        */
        /* 1120 IF L=L(5) THEN 1130                                     */
@@ -523,7 +553,7 @@ goodmove:
     }
 }
 
-main(argc, argv)
+int main(argc, argv)
 int argc;
 char *argv[];
 {