Prepare wumpus.c for 1TBS reflow.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 29 Jan 2024 09:36:08 +0000 (04:36 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 29 Jan 2024 09:36:08 +0000 (04:36 -0500)
wumpus.c

index 857bce2df15bfc267b90165cf3581be85931bf2b..1c0cdd11f5231ac5f90a7c3ca3c4a9321f6fdc36 100644 (file)
--- a/wumpus.c
+++ b/wumpus.c
@@ -108,10 +108,10 @@ char *prompt;
 {
     (void) printf("%s\n?", prompt);
     if (fgets(inp, sizeof(inp), stdin))
-      return(atoi(inp));
+        return(atoi(inp));
     else {
-      fputs("\n",stdout);
-      exit(1);
+        fputs("\n",stdout);
+        exit(1);
     }
 }
 
@@ -120,10 +120,10 @@ char *prompt;
 {
     (void) printf("%s\n?", prompt);
     if (fgets(inp, sizeof(inp), stdin))
-      return(toupper(inp[0]));
+       return(toupper(inp[0]));
     else {
-      fputs("\n",stdout);
-      exit(1);
+        fputs("\n",stdout);
+        exit(1);
     }
 }
 
@@ -234,15 +234,19 @@ void check_hazards()
     {
        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!");
+           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!");
+           }
        }
     }
 
@@ -276,12 +280,15 @@ badin:
     /* 700 IF I$<>"M" THEN 675                                         */
     /* 705 O=2                                                         */
     /* 710 RETURN                                                      */
-    if (c == 'S')
+    if (c == 'S') {
        return(1);
-    else if (c == 'M')
+    }
+    else if (c == 'M') {
        return(0);
-    else
+    }
+    else {
        goto badin;
+    }
 }
 
 
@@ -303,8 +310,9 @@ badrange:
 
     /* 745 IF J9<1 THEN 735                                            */
     /* 750 IF J9>5 THEN 735                                            */
-    if (j9 < 1 || j9 > 5)
+    if (j9 < 1 || j9 > 5) {
        goto badrange;
+    }
 
     /* 755 FOR K=1 TO J9                                               */
     for (k = 0; k < j9; k++)
@@ -314,12 +322,14 @@ badrange:
        path[k] = getnum("ROOM #") - 1;
 
        /* 770 IF K<=2 THEN 790                                         */
-       if (k <= 1)
+       if (k <= 1) {
            continue;
+       }
 
        /* 775 IF P(K)<>P(K-2) THEN 790                                 */
-       if (path[k] != path[k - 2])
+       if (path[k] != path[k - 2]) {
            continue;
+       }
 
        /* 780 PRINT "ARROWS AREN'T THAT CROOKED - TRY ANOTHER ROOM"    */
        (void) puts("ARROWS AREN'T THAT CROOKED - TRY ANOTHER ROOM");
@@ -366,8 +376,9 @@ badrange:
 
                /* this simulates logic at 895 in the BASIC code */
                check_shot();
-               if (finished != NOT)
+               if (finished != NOT) {
                    return;
+               }
                goto nextpath;
            }
            /* 820 NEXT K1                                              */
@@ -384,8 +395,9 @@ badrange:
 
        /* 835 GOTO 900                                                 */
        check_shot();
-       if (finished != NOT)
+       if (finished != NOT) {
            return;
+       }
 
        /* 840 NEXT K                                                   */
        nextpath: ;
@@ -407,8 +419,9 @@ badrange:
        /* 870 A=A-1                                                    */
        /* 875 IF A>0 THEN 885                                          */
        /* 880 F=-1                                                     */
-       if (--arrows <= 0)
+       if (--arrows <= 0) {
            finished = LOSE;
+       }
     }
 
     /* 885 RETURN                                                      */
@@ -447,16 +460,18 @@ void move_wumpus()
 
     /* 945 IF K=4 THEN 955                                             */
     /* 950 L(2)=S(L(2),K)                                              */
-    if (k < 3)
+    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])
+    if (loc[WUMPUS] != loc[YOU]) {
        return;
+    }
 
     /* 960 PRINT "TSK TSK TSK - WUMPUS GOT YOU!"                       */
     (void) puts("TSK TSK TSK - WUMPUS GOT YOU!");
@@ -480,8 +495,9 @@ badmove:
 
     /* 995 IF L<1 THEN 985                                             */
     /* 1000 IF L>20 THEN 985                                           */
-    if (scratchloc < 1 || scratchloc > 20)
+    if (scratchloc < 1 || scratchloc > 20) {
        goto badmove;
+    }
     scratchloc--;
 
     /* 1005 FOR K=1 TO 3                                               */
@@ -489,8 +505,9 @@ badmove:
     {
        /* 1010 REM *** CHECK IF LEGAL MOVE ***                         */
        /* 1015 IF S(L(1),K)=L THEN 1045                                */
-       if (cave[loc[YOU]][k] == scratchloc)
-           goto goodmove;
+       if (cave[loc[YOU]][k] == scratchloc) {
+             goto goodmove;
+       }
 
        /* 1020 NEXT K                                                  */
     }
@@ -521,8 +538,9 @@ goodmove:
        /* 1080 RETURN                                                  */
        (void) puts("... OOPS! BUMPED A WUMPUS!");
        move_wumpus();
-       if (finished < 0)
+       if (finished < 0) {
            return;
+       }
        /* Fall through since Wumpus could have been in a pit or bat room */
     }
     if (scratchloc == loc[PIT1] || scratchloc == loc[PIT2])
@@ -559,10 +577,12 @@ char *argv[];
 {
     int        c;
 
-    if (argc >= 2 && strcmp(argv[1], "-s") == 0)
+    if (argc >= 2 && strcmp(argv[1], "-s") == 0) {
        srand(atoi(argv[2]));
-    else
+    }
+    else {
        srand((int)time((long *) 0));
+    }
 
     /* 15 PRINT "INSTRUCTIONS (Y-N)";                                  */
     /* 20 INPUT I$                                                     */
@@ -583,8 +603,9 @@ badlocs:
     /* 175 L(J)=FNA(0)                                                 */
     /* 180 M(J)=L(J)                                                   */
     /* 185 NEXT J                                                      */
-    for (j = 0; j < LOCS; j++)
+    for (j = 0; j < LOCS; j++) {
        loc[j] = save[j] = FNA();
+    }
 
     /* 190 REM *** CHECK FOR CROSSOVERS (IE L(1)=L(2), ETC) ***                */
     /* 195 FOR J=1 TO 6                                                        */
@@ -593,12 +614,16 @@ badlocs:
     /* 210 IF L(J)=L(K) THEN 170                                       */
     /* 215 NEXT K                                                      */
     /* 220 NEXT J                                                      */
-    for (j = 0; j < LOCS; j++)
-       for (k = 0; k < LOCS; k++)
-           if (j == k)
-               continue;
-           else if (loc[j] == loc[k])
-               goto badlocs;
+    for (j = 0; j < LOCS; j++) {
+       for (k = 0; k < LOCS; k++) {
+             if (j == k) {
+                   continue;
+             }
+             else if (loc[j] == loc[k]) {
+                 goto badlocs;
+             }
+       }
+    }
 
     /* 225 REM *** SET NO. OF ARROWS ***                               */
 newgame:    
@@ -633,8 +658,9 @@ nextmove:
        shoot();
 
        /* 285 IF F=0 THEN 255                                          */
-       if (finished == NOT)
+       if (finished == NOT) {
            goto nextmove;
+       }
 
        /* 290 GOTO 310                                                 */
     }
@@ -645,8 +671,9 @@ nextmove:
        move();
 
        /* 305 IF F=0 THEN 255                                          */
-       if (finished == NOT)
+       if (finished == NOT) {
            goto nextmove;
+       }
     }
 
     /* 310 IF F>0 THEN 335                                             */
@@ -667,8 +694,9 @@ nextmove:
     /* 340 FOR J=1 TO 6                                                        */
     /* 345 L(J)=M(J)                                                   */
     /* 350 NEXT J                                                      */
-    for (j = YOU; j < LOCS; j++)
+    for (j = YOU; j < LOCS; j++) {
        loc[j] = save[j];
+    }
 
     /* 355 PRINT "SAME SETUP (Y-N)";                                   */
     /* 360 INPUT I$                                                    */
@@ -676,10 +704,12 @@ nextmove:
 
     /* 365 IF I$<>"Y"THEN 170                                          */
     /* 370 GOTO 230                                                    */
-    if (c != 'Y')
+    if (c != 'Y') {
        goto badlocs;
-    else
+    }
+    else {
        goto newgame;
+    }
 }
 
 /* wumpus.c ends here */