Fix some minor buglets in wump:

1) Don't put two pits in the same room.
2) Don't put bats and pits in the same room.  (you will never hit the bat)
3) Don't start the player in a room with a pit or bad, if possible.  Some
caves are so crowded the loop may go on forever, so we give up after 100
tries to put them in a safe location (as long as it's not with the wumpus).
4) Make the manpage reflect reality WRT the default number of rooms.

Bug #3 pointed out by salo.
This commit is contained in:
garbled 2006-01-19 21:20:35 +00:00
parent c2c322c5a5
commit 19fe295582
2 changed files with 11 additions and 7 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: wump.6,v 1.6 2003/08/07 09:37:57 agc Exp $
.\" $NetBSD: wump.6,v 1.7 2006/01/19 21:20:35 garbled Exp $
.\"
.\" Copyright (c) 1989, 1993
.\" The Regents of the University of California. All rights reserved.
@ -74,7 +74,7 @@ Specifies the number of rooms in the cave which contain bottomless pits.
The default is three.
.It Fl r
Specifies the number of rooms in the cave.
The default cave size is twenty-five rooms.
The default cave size is twenty rooms.
.It Fl t
Specifies the number of tunnels connecting each room in the cave to
another room.

View File

@ -1,4 +1,4 @@
/* $NetBSD: wump.c,v 1.19 2006/01/19 20:15:31 garbled Exp $ */
/* $NetBSD: wump.c,v 1.20 2006/01/19 21:20:35 garbled Exp $ */
/*
* Copyright (c) 1989, 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
#if 0
static char sccsid[] = "@(#)wump.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: wump.c,v 1.19 2006/01/19 20:15:31 garbled Exp $");
__RCSID("$NetBSD: wump.c,v 1.20 2006/01/19 21:20:35 garbled Exp $");
#endif
#endif /* not lint */
@ -643,7 +643,7 @@ initialize_things_in_cave()
for (i = 0; i < pit_num; ++i) {
do {
loc = (random() % room_num) + 1;
} while (cave[loc].has_a_pit && cave[loc].has_a_bat);
} while (cave[loc].has_a_pit || cave[loc].has_a_bat);
cave[loc].has_a_pit = 1;
#ifdef DEBUG
if (debug)
@ -657,10 +657,14 @@ initialize_things_in_cave()
(void)printf("<wumpus in room %d>\n", loc);
#endif
i = 0;
do {
player_loc = (random() % room_num) + 1;
} while (player_loc == wumpus_loc || (level == HARD ?
(link_num / room_num < 0.4 ? wump_nearby() : 0) : 0));
i++;
} while (player_loc == wumpus_loc || cave[player_loc].has_a_pit ||
cave[player_loc].has_a_bat || (level == HARD ?
(link_num / room_num < 0.4 ? wump_nearby() : 0) : 0) ||
(i > 100 && player_loc != wumpus_loc));
}
int