Skip to content
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

Merged

Conversation

mrgriffin
Copy link
Collaborator

Converts Tri Attack and Dire Claw to use structured RNG via RandomElement, so that their KNOWN_FAILINGs 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 by hit:, criticalHit:, and secondaryEffect:), I suspect this is mostly only useful with tags used in RandomElement calls.

NOTE: WITH_RNG currently only works if the element type is 32-bit or smaller.

@mrgriffin mrgriffin marked this pull request as draft March 27, 2023 17:46
@mrgriffin mrgriffin marked this pull request as ready for review March 27, 2023 17:47
@mrgriffin mrgriffin marked this pull request as draft March 27, 2023 17:49
Converts Tri Attack and Dire Claw to use structured RNG.
@mrgriffin mrgriffin marked this pull request as ready for review March 27, 2023 17:50
u32 RandomUniformDefault(enum RandomTag tag, u32 lo, u32 hi)
{
return lo + (((hi - lo) * Random()) >> 16);
return lo + (((hi - lo + 1) * Random()) >> 16);
Copy link
Collaborator Author

@mrgriffin mrgriffin Mar 27, 2023

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.

@mrgriffin mrgriffin added bug Bug category: battle-mechanic Pertains to battle mechanics new-feature Adds a feature category: battle-tests Related to the automated test environment labels Mar 27, 2023
@@ -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 })
Copy link
Collaborator Author

@mrgriffin mrgriffin Mar 27, 2023

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.

Comment on lines +84 to +91
if (t <= 0) \
{ \
r = FALSE; \
} \
else if (t >= 100) \
{ \
r = TRUE; \
} \
Copy link
Collaborator Author

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.

@AsparagusEduardo AsparagusEduardo merged commit 5c1efe9 into rh-hideout:upcoming Apr 10, 2023
1 check passed
@AsparagusEduardo AsparagusEduardo mentioned this pull request May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug category: battle-mechanic Pertains to battle mechanics category: battle-tests Related to the automated test environment new-feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants