static char sccsid
[] = " wump.c 4.1 82/10/24 ";
* stolen from PCC Vol 2 No 1
#define BIGINT 2147483648.0
"Welcome to 'Hunt the Wumpus.'\n",
"The Wumpus lives in a cave of %d rooms.\n",
"Each room has %d tunnels leading to other rooms.\n",
"Bottomless Pits - Some rooms have Bottomless Pits in them.\n",
" If you go there, you fall into the pit and lose!\n",
"Super Bats - Some other rooms have super bats.\n",
" If you go there, a bat will grab you and take you to\n",
" somewhere else in the cave where you could\n",
" fall into a pit or run into the . . .\n",
"The Wumpus is not bothered by the hazards since\n",
"he has sucker feet and is too big for a bat to lift.\n",
"Usually he is asleep.\n",
"Two things wake him up:\n",
" your entering his room\n",
" your shooting an arrow anywhere in the cave.\n",
"If the wumpus wakes, he either decides to move one room or\n",
"stay where he was. But if he ends up where you are,\n",
"he eats you up and you lose!\n",
"Each turn you may either move or shoot a crooked arrow.\n",
"Moving - You can move to one of the adjoining rooms;\n",
" that is, to one that has a tunnel connecting it with\n",
" the room you are in.\n",
"Shooting - You have 5 arrows. You lose when you run out.\n",
" Each arrow can go from 1 to 5 rooms.\n",
" You aim by telling the computer\n",
" The arrow's path is a list of room numbers\n",
" telling the arrow which room to go to next.\n",
" The list is terminated with a 0.\n",
" The first room in the path must be connected to the\n",
" room you are in. Each succeeding room must be\n",
" connected to the previous room.\n",
" If there is no tunnel between two of the rooms\n",
" in the arrow's path, the arrow chooses one of the\n",
" three tunnels from the room it's in and goes its\n",
" If the arrow hits the wumpus, you win!\n",
" If the arrow hits you, you lose!\n",
"When you are one or two rooms away from the wumpus,\n",
"When you are one room away from some other hazard, it says:\n",
" Bat - 'Bats nearby'\n",
" Pit - 'I feel a draft'\n",
printf("Instructions? (y-n) ");
printf(intro
[i
], i
&1? NROOM
: NTUNN
);
* initialize the room connections
if(j
== k
|| p
->tunn
[0] >= 0 || p
->tunn
[1] >= 0)
if(p
->tunn
[j
] == p
->tunn
[k
])
qsort(&p
->tunn
[0], NTUNN
, sizeof(p
->tunn
[0]), icomp
);
if((p
->flag
&(PIT
|BAT
)) == 0) {
if((room
[i
].flag
&(PIT
|BAT
|WUMP
)) == 0) {
printf("You are in room %d\n", loc
+1);
printf("You fell into a pit\n");
printf("You were eaten by the wumpus\n");
printf("Theres a bat in your room\n");
if(near(&room
[p
->tunn
[i
]], WUMP
))
printf("I smell a wumpus\n");
printf("I feel a draft\n");
printf("There are tunnels to");
printf(" %d", p
->tunn
[i
]+1);
printf("Move or shoot (m-s) ");
printf("You hit the wall\n");
printf("Give list of rooms terminated by 0\n");
printf("You shot yourself\n");
printf("You slew the wumpus\n");
printf("That was your last shot\n");
printf("Another game? (y-n) ");
printf("Same room setup? (y-n) ");
while((c
=getchar()) == ' ');
while(c
!= '\n' && c
!= ' ') {
if(first
[1]==0) first
[1] = 1;
srand((first
[1]*first
[0])^first
[1]);
return((int)((rand()/BIGINT
) * n
));
while(c
!= '\n' && c
!= ' ') {
if(room
[p
->tunn
[i
]].flag
& haz
)
register FILE *port
= stdin
;
register int iodes
= fileno(port
);
port
->_ptr
= port
->_base
;
if(gtty(iodes
,&arg
) != -1) stty(iodes
,&arg
);