New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RandomElement for structured RNG #2868
RandomElement for structured RNG #2868
Conversation
dee9830
to
660ef91
Compare
Converts Tri Attack and Dire Claw to use structured RNG.
660ef91
to
7b306b6
Compare
u32 RandomUniformDefault(enum RandomTag tag, u32 lo, u32 hi) | ||
{ | ||
return lo + (((hi - lo) * Random()) >> 16); | ||
return lo + (((hi - lo + 1) * Random()) >> 16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very serious bug I discovered when testing RandomElementArrayDefault
—it meant that any calls to RandomUniform
(outside of tests) were exclusive of hi
instead of inclusive.
@@ -758,6 +766,8 @@ enum { TURN_CLOSED, TURN_OPEN, TURN_CLOSING }; | |||
#define SKIP_TURN(battler) SkipTurn(__LINE__, battler) | |||
#define SEND_OUT(battler, partyIndex) SendOut(__LINE__, battler, partyIndex) | |||
|
|||
#define WITH_RNG(tag, value) rng: ((struct TurnRNG) { tag, value }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the way the macros work out, the seemingly-unnecessary outer parentheses here are required to keep this whole thing being treated as a single token, which prevents APPEND_TRUE
from inserting a TRUE
between tag
and value
.
We could have instead chosen to have a 1-bit field that doesn't do anything in TurnRNG
* to absorb this value. This would mean we can write something more like rng: { tag, value }
directly in MOVE
, which might be nicer.
* Or use a different struct in MoveContext
which has that field.
if (t <= 0) \ | ||
{ \ | ||
r = FALSE; \ | ||
} \ | ||
else if (t >= 100) \ | ||
{ \ | ||
r = TRUE; \ | ||
} \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes abilities like Compound Eyes which produce a "percentage" that is out of bounds.
Converts Tri Attack and Dire Claw to use structured RNG via
RandomElement
, so that theirKNOWN_FAILING
s can be removed.Also introduces
WITH_RNG
which allows tests to specify an exact RNG value for any arbitrary RNG tag (instead of just the ones supported byhit:
,criticalHit:
, andsecondaryEffect:
), I suspect this is mostly only useful with tags used inRandomElement
calls.NOTE:
WITH_RNG
currently only works if the element type is 32-bit or smaller.