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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ class MinefieldHandler(
.toArea()
.filter { it.potentialMineReveal() && it.hasUncoveredNeighbor() }

val unrevealedMines =
val unrevealedMinesWithUncoveredNeighbor =
prioritizedMines.ifEmpty {
field.filter { it.potentialMineReveal() && it.hasUncoveredNeighbor() }
}

val unrevealedMines =
unrevealedMinesWithUncoveredNeighbor.ifEmpty {
field.filter { it.potentialMineReveal() }
}

val nearestTarget =
if (lastX != null && lastY != null) {
unrevealedMines.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,13 @@ open class GameViewModel(
}
}

private fun matchExpectedValueStoch(x: Double): Int {

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.

}

private fun calcRewardHints(): Int {
return if (clockManager.timeInSeconds() > MIN_REWARD_GAME_SECONDS && preferencesRepository.isPremiumEnabled()) {
val rewardedHints =
Expand All @@ -789,7 +796,7 @@ open class GameViewModel(
(state.minefield.mines * REWARD_RATIO_WITHOUT_MISTAKES)
}

rewardedHints.toInt().coerceAtLeast(1)
matchExpectedValueStoch(rewardedHints).coerceAtLeast(1)
} else {
0
}
Expand Down
Loading