Subject: bin/26501: bugs in /usr/games/wump
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <dholland@eecs.harvard.edu>
List: netbsd-bugs
Date: 08/01/2004 03:09:46
>Number:         26501
>Category:       bin
>Synopsis:       wump hangs if too many games played
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 01 07:37:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     David A. Holland <dholland@eecs.harvard.edu>
>Release:        NetBSD -current of 20040731
>Organization:
   - David A. Holland / dholland@eecs.harvard.edu
>Environment:

System: NetBSD alicante 1.6ZG NetBSD 1.6ZG (ALICANTE) #8: Wed Mar 17 18:47:39 EST 2004 dholland@alicante:/usr/src/sys/arch/i386/compile/ALICANTE i386
Architecture: i386
Machine: i386
>Description:

	I was playing wump tonight (why not?) and discovered that, if
	you lose repeatedly and say that you want to play again in a
	new cave, it eventually hangs.

	It seems that when you do this it doesn't clear the bats and
	pits out of the cave but does add new ones; eventually it
	hangs because every room has a bat and it can't place a new
	one.

	The patch also fixes an operator precedence bug I ran across
	while investigating - this has no overt symptoms but the code
	is clearly wrong.

	Patch is against the latest wump.c as of this writing, 1.16.

>How-To-Repeat:
	as above.
>Fix:

Index: wump.c
===================================================================
RCS file: /cvsroot/src/games/wump/wump.c,v
retrieving revision 1.16
diff -u -r1.16 wump.c
--- wump.c	27 Jan 2004 20:30:31 -0000	1.16
+++ wump.c	1 Aug 2004 06:29:40 -0000
@@ -232,6 +232,7 @@
 	    plural(pit_num), arrow_num);
 
 	for (;;) {
+		clear_things_in_cave();
 		initialize_things_in_cave();
 		arrows_left = arrow_num;
 		do {
@@ -244,9 +245,7 @@
 
 		if (!getans("\nCare to play another game? (y-n) "))
 			exit(0);
-		if (getans("In the same cave? (y-n) "))
-			clear_things_in_cave();
-		else
+		if (getans("In the same cave? (y-n) ") == 0)
 			cave_init();
 	}
 	/* NOTREACHED */
@@ -506,7 +505,7 @@
 		/* each time you shoot, it's more likely the wumpus moves */
 		static int lastchance = 2;
 
-		if (random() % level == EASY ? 12 : 9 < (lastchance += 2)) {
+		if (random() % (level == EASY ? 12 : 9) < (lastchance += 2)) {
 			move_wump();
 			if (wumpus_loc == player_loc)
 				wump_kill();

>Release-Note:
>Audit-Trail:
>Unformatted: