adopt github pull request #286 - rndmonst()

Eliminate the cache that was supporting rndmonst() and pick a random
monster in a single pass through mons[] via "weighted reservoir
sampling", a term I'm not familiar with.

It had a couple of bugs:  if the first monster examined happened to
be given a weighting of 0, rn2() would divide by 0.  I didn't try
to figure out how to trigger that.  But the second one was easy to
trigger:  if all eligible monsters were extinct or genocided, it
would issue a warning even though the situation isn't impossible.

Aside from fixing those, the rest is mostly as-is.  I included a bit
of formatting in decl.c, moved some declarations to not require C99,
and changed a couple of macros to not hide and duplicate a call to
level_difficulty().

Fixes #286
This commit is contained in:
PatR
2020-02-22 17:40:55 -08:00
parent 5d4b9784ac
commit cbdda9dc9d
10 changed files with 70 additions and 99 deletions

View File

@@ -199,6 +199,7 @@ correct the Guidebook descriptions for msdos video_width and video_height to
state that they work with video:vesa; the video:vga setting that was
described there forces the 640x480x16 mode where video_width and
video_height don't operate (github #294)
redo rndmonst() to operate in a single pass (github pull request #286)
Code Cleanup and Reorganization