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

Fix bug when no uncovered neighbors are avaiable and let rewarded hints match expected value #484

Merged
merged 2 commits into from
Nov 30, 2023

Conversation

gboehl
Copy link
Contributor

@gboehl gboehl commented Nov 27, 2023

This PR brings a bugfix and a feature.

The bug is that currently, when using a hint but no mine with uncovered neighbor is available, no mine is revealed (e.g. when the complete coastline is flagged). Fix is to check this and reveal a random mine otherwise.

The feature is that currently, the number of rewarded hints h is always the rounded down fraction q (currenty 5%) of the total number of mines M, thus h = floor(q*M). This means that h/M <= q and thereby induces a negative bias, especially when using small fields. The fix is to let the expected value of h equal q*M by randomly chosing between floor(q*M) and ceil(q*M) with the appropriate probability (all this sounds more complicated than it is).

Cheers!


val randomNum = (1..100).random()

return if (randomNum <= (x - x.toInt())*100) x.toInt() + 1 else x.toInt()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we always round up instead of add randomness?

Copy link
Contributor Author

@gboehl gboehl Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say this would lead to essentially the same problem, but with an additional hint unless q*M is an integer.

The szenario is that people subsequently increase mines to increase difficulty. But difficulty increases disproportionally stronger when adding mines because the number of rewarded hints does not increase with the number of mines.

Any reason why you would like to avoid randomness? Note that the randomness only affects the +1 part.

Copy link
Contributor Author

@gboehl gboehl Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative idea would be to store the number of hints internally as a double, and only display it as an int. Then calcRewardHints() could simply return rewardedHints directly without toInt().

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Makes sense.

@lucasnlm lucasnlm merged commit 49840ac into lucasnlm:main Nov 30, 2023
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants