/*
* wumpus.c --- a faithful translation of the classic "Hunt The Wumpus" game.
*
- * Translator: Eric S. Raymond <eric@snark.thyrsus.com>
- * Version: $Id$
- *
- * This was the state of the art 20 years ago, in 1972. We've come a long
- * way, baby.
+ * Translator: Eric S. Raymond <esr@snark.thyrsus.com>
+ * 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 *** */
char *prompt;
{
(void) printf("%s\n?", prompt);
- (void) fgets(inp, sizeof(inp), stdin);
- return(atoi(inp));
+ if (fgets(inp, sizeof(inp), stdin))
+ return(atoi(inp));
+ else {
+ fputs("\n",stdout);
+ exit(1);
+ }
}
int getlet(prompt)
char *prompt;
{
(void) printf("%s\n?", prompt);
- (void) fgets(inp, sizeof(inp), stdin);
- return(inp[0]);
+ if (fgets(inp, sizeof(inp), stdin))
+ return(toupper(inp[0]));
+ else {
+ fputs("\n",stdout);
+ exit(1);
+ }
}
void print_instructions()
{
- char ebuf[BUFSIZ];
-
/* 375 REM *** INSTRUCTIONS *** */
/* 380 PRINT "WELCOME TO 'HUNT THE WUMPUS'" */
puts("WELCOME TO 'HUNT THE WUMPUS'");
{
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++)
{
*/
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)
- goto ammo;
- else
+ if (finished != NOT)
return;
+ goto nextpath;
}
-
/* 820 NEXT K1 */
}
/* 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" */
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;
/* 1145 RETURN */
/* 1150 END */
(void) puts("ZAP--SUPER BAT SNATCH! ELSEWHEREVILLE FOR YOU!");
- loc[YOU] = FNA();
+ scratchloc = loc[YOU] = FNA();
+ goto goodmove;
}
}
-main(argc, argv)
+int main(argc, argv)
int argc;
char *argv[];
{
int c;
- if (strcmp(argv[1], "-s") == 0)
- srand(atol(argv[2]));
+ if (argc >= 2 && strcmp(argv[1], "-s") == 0)
+ srand(atoi(argv[2]));
else
- srand(time((long *) 0));
+ srand((int)time((long *) 0));
/* 15 PRINT "INSTRUCTIONS (Y-N)"; */
/* 20 INPUT I$ */