get_rnd_text() equal odds for all lines#1482
get_rnd_text() equal odds for all lines#1482GorillaSapiens wants to merge 2 commits intoNetHack:NetHack-3.7from
Conversation
Renames rumors.tru to rumors_t.txt and rumors.fal to rumors_f.txt. Splits rumors into rumors_t and rumors_f. Removes padding from engrave, epitaph, and bogusmon. Adds sidecar *.idx files for all of the above to guarantee all lines have the exact same odds of appearing, regardless of length. Removes kludgey get_rnd_line(). Adds new files to various Makefiles etc.
|
While I am in favor of making all lines from data files equal-probability, I think it could be achieved more cleanly and elegantly:
|
"clean" and "elegant", like "beauty", are in the eye of the beholder. your proposed solution is effectively the same; build an index of file offsets. where this PR stores that index on disk, your proposal stores it in memory. which of course uses more memory by definition. further, this PR builds the index once at compile time. your proposal builds it every time the program is run, which is less efficient. you also propose reading the file in 2 passes when an index can easily be built in a single pass. (hint: realloc() is your friend) another possible solution would be "just read the whole thing into memory". the obvious downside is "uses way more memory". it's clear from the previous implementation that it was written at a time when memory was much more scarce than disk space. this PR preserves that design goal by keeping the index on disk. it's not clear to me how many of these legacy "low on memory" platforms are still supported, but i'm willing to bet there's at least one. you are, of course, free to write your own implementation and submit it as a PR. |
Renames rumors.tru to rumors_t.txt and rumors.fal to rumors_f.txt. Splits rumors into rumors_t and rumors_f.
Removes kludgey padding from engrave, epitaph, and bogusmon. Adds sidecar *.idx files for all of the above to guarantee all lines have the exact same odds of appearing, regardless of length. Removes kludgey get_rnd_line().
Adds new files to various Makefiles etc.