From 9117ffa747e07c4209c5f3f152571da2652489b0 Mon Sep 17 00:00:00 2001 From: garbled Date: Thu, 19 Jan 2006 21:20:35 +0000 Subject: 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. --- wump/wump.6 | 4 ++-- wump/wump.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'wump') diff --git a/wump/wump.6 b/wump/wump.6 index 67ae2c30..f2e928c3 100644 --- a/wump/wump.6 +++ b/wump/wump.6 @@ -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. diff --git a/wump/wump.c b/wump/wump.c index 4754146c..1cff6dbc 100644 --- a/wump/wump.c +++ b/wump/wump.c @@ -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("\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 -- cgit v1.2.3-56-ge451