Magic-number elimination and fix

More test coverage for some of the cases
This commit is contained in:
NHOrus 2017-07-06 17:55:56 +03:00
parent da6a090b83
commit ca7ac4063f
6 changed files with 3414 additions and 7 deletions

View file

@ -113,12 +113,12 @@ static int attack(struct command_t *command)
state_change(DRAGON, DRAGON_DEAD); state_change(DRAGON, DRAGON_DEAD);
game.prop[RUG] = RUG_FLOOR; game.prop[RUG] = RUG_FLOOR;
/* Hardcoding LOC_SECRET5 as the dragon's death location is ugly. /* Hardcoding LOC_SECRET5 as the dragon's death location is ugly.
* The way it was computed before was wirse; it depended on the * The way it was computed before was worse; it depended on the
* two dragon locations being LOC_SECRET4 and LOC_SECRET6 and * two dragon locations being LOC_SECRET4 and LOC_SECRET6 and
* LOC_SECRET5 being right between them. * LOC_SECRET5 being right between them.
*/ */
move(DRAGON + NOBJECTS, -1); move(DRAGON + NOBJECTS, IS_FIXED);
move(RUG + NOBJECTS, LOC_NOWHERE); move(RUG + NOBJECTS, IS_FREE);
move(DRAGON, LOC_SECRET5); move(DRAGON, LOC_SECRET5);
move(RUG, LOC_SECRET5); move(RUG, LOC_SECRET5);
drop(BLOOD, LOC_SECRET5); drop(BLOOD, LOC_SECRET5);
@ -493,7 +493,7 @@ static int discard(token_t verb, obj_t obj)
} else if (obj == BEAR && AT(TROLL)) { } else if (obj == BEAR && AT(TROLL)) {
state_change(TROLL, TROLL_GONE); state_change(TROLL, TROLL_GONE);
move(TROLL, LOC_NOWHERE); move(TROLL, LOC_NOWHERE);
move(TROLL + NOBJECTS, LOC_NOWHERE); move(TROLL + NOBJECTS, IS_FREE);
move(TROLL2, objects[TROLL].plac); move(TROLL2, objects[TROLL].plac);
move(TROLL2 + NOBJECTS, objects[TROLL].fixd); move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
juggle(CHASM); juggle(CHASM);
@ -1150,7 +1150,7 @@ static int throw (struct command_t *command)
/* Snarf a treasure for the troll. */ /* Snarf a treasure for the troll. */
drop(command->obj, LOC_NOWHERE); drop(command->obj, LOC_NOWHERE);
move(TROLL, LOC_NOWHERE); move(TROLL, LOC_NOWHERE);
move(TROLL + NOBJECTS, LOC_NOWHERE); move(TROLL + NOBJECTS, IS_FREE);
drop(TROLL2, objects[TROLL].plac); drop(TROLL2, objects[TROLL].plac);
drop(TROLL2 + NOBJECTS, objects[TROLL].fixd); drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
juggle(CHASM); juggle(CHASM);

3
misc.c
View file

@ -607,7 +607,8 @@ void drop(obj_t object, loc_t where)
--game.holdng; --game.holdng;
game.place[object] = where; game.place[object] = where;
} }
if (where <= 0) if (where == LOC_NOWHERE ||
where == CARRIED)
return; return;
game.link[object] = game.atloc[where]; game.link[object] = game.atloc[where];
game.atloc[where] = object; game.atloc[where] = object;

View file

@ -24,6 +24,11 @@ z
Sorry, I don't know the word "Z". Sorry, I don't know the word "Z".
go south
You are in a valley in the forest beside a stream tumbling along a
rocky bed.
quit quit
Do you really want to quit now? Do you really want to quit now?
@ -32,7 +37,7 @@ yes
OK OK
You scored 32 out of a possible 430, using 5 turns. You scored 32 out of a possible 430, using 6 turns.
You are obviously a rank amateur. Better luck next time. You are obviously a rank amateur. Better luck next time.

View file

@ -5,5 +5,6 @@ i
l l
x x
z z
go south
quit quit
yes yes

2928
tests/wakedwarves3.chk Normal file

File diff suppressed because it is too large Load diff

472
tests/wakedwarves3.log Normal file
View file

@ -0,0 +1,472 @@
## Wake the dwarves differently and die.
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
drop keys
fork
w
w
sw
free bear
inven
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
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
e
u
n
plover
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
e
# Everything to here is from endgame428
take rod
drop rod
take rod
inven
attack dwarf