Magic-number limination. Improve test coverage.

This commit is contained in:
Eric S. Raymond 2017-06-18 09:44:34 -04:00
parent d363a5c564
commit 937714f31d
7 changed files with 3077 additions and 5 deletions

View file

@ -710,7 +710,7 @@ static int lock(token_t verb, token_t obj)
if (AT(GRATE))obj = GRATE;
if (obj != 0 && HERE(CHAIN)) return GO_UNKNOWN;
if (HERE(CHAIN))obj = CHAIN;
if (obj == 0) {
if (obj == 0 || obj == INTRANSITIVE) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
@ -731,7 +731,7 @@ static int lock(token_t verb, token_t obj)
return chain(verb);
if (game.closng) {
spk = EXIT_CLOSED;
if (!game.panic)game.clock2 = 15;
if (!game.panic)game.clock2 = PANICTIME;
game.panic = true;
} else {
spk = game.prop[GRATE] ? GRATE_LOCKED : ALREADY_LOCKED;

View file

@ -14,6 +14,7 @@
#define INTRANSITIVE -1 /* illegal object number */
#define SPECIALBASE 300 /* base number of special rooms */
#define WARNTIME 30 /* late game starts at game.limit-this */
#define PANICTIME 15 /* time left after closing */
typedef long token_t; /* word token - someday this will be char[TOKLEN+1] */
typedef long vocab_t; /* index into a vocabulary array */

2
main.c
View file

@ -915,7 +915,7 @@ static bool do_command(FILE *cmdin)
if (OUTSID(game.newloc) && game.newloc != 0 && game.closng) {
RSPEAK(EXIT_CLOSED);
game.newloc = game.loc;
if (!game.panic)game.clock2 = 15;
if (!game.panic)game.clock2 = PANICTIME;
game.panic = true;
}

View file

@ -36,6 +36,10 @@ You're in front of building.
You are in a valley in the forest beside a stream tumbling along a
rocky bed.
> lock
There is nothing here with a lock!
> take water
You have nothing in which to carry it.
@ -345,7 +349,7 @@ Okay, "BOO".
> score
You have garnered 27 out of a possible 430 points, using 67 turns.
You have garnered 27 out of a possible 430 points, using 68 turns.
> quit keys
@ -359,7 +363,7 @@ Do you really want to quit now?
OK
You scored 27 out of a possible 430, using 69 turns.
You scored 27 out of a possible 430, using 70 turns.
You are obviously a rank amateur. Better luck next time.

View file

@ -3,6 +3,7 @@ foo
y
seed 1801426495
stream
lock
take water
building
cave

2638
tests/panic.chk Normal file

File diff suppressed because it is too large Load diff

428
tests/panic.log Normal file
View file

@ -0,0 +1,428 @@
## Panic test - ret to unlock grate after game closed.
n
seed 1838473132
in
take lamp
xyzzy
on
take rod
e
take cage
w
w
w
drop rod
take bird
take rod
w
free bird
wave rod
take necklace
drop rod
take bird
take rod
d
d
free bird
drop rod
drop cage
take cage
take bird
w
take coins
e
s
take jewelry
n
up
s
take gold
n
d
n
n
plugh
extinguish lamp
drop coins
drop jewelry
drop necklace
drop gold
plugh
on
s
take silver
s
sw
take axe
w
kill dragon
yes
drink blood
take rug
e
e
up
d
n
n
off
plugh
inven
drop rug
drop silver
out
s
w
n
take appendage
free bird
drop cage
listen
s
s
n
in
take water
plugh
on
plover
ne
take pyramid
s
plover
s
s
take rod
up
w
wave rod
drop rod
west
take diamonds
w
w
w
s
sw
se
s
kill machine
s
s
kill ogre
n
take ruby
s
w
n
n
n
nw
d
e
e
e
e
e
throw axe
take axe
n
n
n
off
plugh
drop ruby
drop diamonds
drop pyramid
plugh
on
s
s
u
n
n
d
bedquilt
throw axe
take axe
slab
s
d
water plant
u
w
u
reservoir
H'CFL
n
n
nw
u
u
u
u
ne
take ebony
sw
d
d
d
d
d
take water
s
s
s
s
d
s
d
water plant
u
drop appendage
e
d
get oil
u
w
d
climb
w
n
oil door
drop bottle
n
take trident
w
d
se
n
w
drop trident
drop ebony
drop axe
drop lantern
e
take emerald
w
take lamp
take axe
take ebony
take trident
nw
s
take vase
se
throw axe
take axe
e
take pillow
w
drop axe
ne
e
n
open clam
s
u
e
u
n
off
plugh
drop pillow
drop vase
drop trident
drop emerald
drop ebony
take keys
take food
plugh
on
s
d
w
d
n
d
d
take pearl
u
u
s
w
w
w
w
d
climb
w
get eggs
n
take bottle
n
w
d
sw
u
toss eggs
ne
ne
barren
in
feed bear
unlock chain
take chain
take bear
fork
ne
e
take spices
fork
w
w
sw
free bear
sw
sw
d
se
se
w
d
get oil
up
e
take axe
w
w
d
climb
w
fee
fie
foe
foo
take eggs
s
d
u
w
u
s
e
e
n
drop keys
n
off
plugh
drop eggs
drop pearl
drop spices
drop chain
take rug
take ruby
take emerald
out
w
n
n
n
inven
fill urn
light urn
rub urn
take amber
drop rug
drop emerald
fly rug
take sapphire
fly rug
take emerald
drop ruby
take rug
drop bottle
take ruby
e
s
e
e
in
drop ruby
drop sapphire
drop amber
drop rug
look
plugh
on
s
s
u
w
w
w
s
e
s
throw axe
take axe
s
s
n
e
e
nw
take emerald
take chest
se
n
d
e
e
off
xyzzy
drop emerald
drop chest
plugh
on
s
d
w
d
e
take magazine
e
drop magazine
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
u
u
# Cave closing announcement at this point
e
u
take keys
s
u
u
e
e
e
e
e
unlock grate