Add debugging of arrow paths
[wumpus.git] / wumpus.c
index 5aef1c3a19608601b9d2f7062b48ffee81c5979c..0bb6315bccfb3f4360ea3c828d679f51d2888401 100644 (file)
--- a/wumpus.c
+++ b/wumpus.c
  *
  * 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 ***                                       */
 
@@ -123,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'");
@@ -330,6 +334,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++)
        {
@@ -347,12 +356,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                                              */
        }
 
@@ -360,13 +373,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"                                           */
@@ -426,6 +446,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;
@@ -521,7 +545,7 @@ goodmove:
     }
 }
 
-main(argc, argv)
+int main(argc, argv)
 int argc;
 char *argv[];
 {