-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: guard division-by-zero in WinCheck when all tiles have fallout #3882
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,6 +67,11 @@ export class WinCheckExecution implements Execution { | |||||||||
| const timeElapsed = this.mg.elapsedGameSeconds(); | ||||||||||
| const numTilesWithoutFallout = | ||||||||||
| this.mg.numLandTiles() - this.mg.numTilesWithFallout(); | ||||||||||
|
|
||||||||||
| if (numTilesWithoutFallout <= 0) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if ( | ||||||||||
| (max.numTilesOwned() / numTilesWithoutFallout) * 100 > | ||||||||||
| this.mg.config().percentageTilesOwnedToWin() || | ||||||||||
|
|
@@ -102,9 +107,14 @@ export class WinCheckExecution implements Execution { | |||||||||
| const timeElapsed = this.mg.elapsedGameSeconds(); | ||||||||||
| const numTilesWithoutFallout = | ||||||||||
| this.mg.numLandTiles() - this.mg.numTilesWithFallout(); | ||||||||||
| const percentage = (max[1] / numTilesWithoutFallout) * 100; | ||||||||||
|
|
||||||||||
| if (numTilesWithoutFallout <= 0) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if ( | ||||||||||
| percentage > this.mg.config().percentageTilesOwnedToWin() || | ||||||||||
| (max[1] / numTilesWithoutFallout) * 100 > | ||||||||||
| this.mg.config().percentageTilesOwnedToWin() || | ||||||||||
|
Comment on lines
+116
to
+117
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Floating-point division on a changed line violates the Line 118 still computes Replace with an integer comparison (no division, no floats): - (max[1] / numTilesWithoutFallout) * 100 >
- this.mg.config().percentageTilesOwnedToWin() ||
+ max[1] * 100 >
+ this.mg.config().percentageTilesOwnedToWin() * numTilesWithoutFallout ||As per coding guidelines: "Ensure deterministic behavior in 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| (this.mg.config().gameConfig().maxTimerValue !== undefined && | ||||||||||
| timeElapsed - this.mg.config().gameConfig().maxTimerValue! * 60 >= 0) || | ||||||||||
| timeElapsed >= WinCheckExecution.HARD_TIME_LIMIT_SECONDS | ||||||||||
|
|
||||||||||
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.
why nut just do:
if numTilesWithoutFallout === this.mg.numLandTiles() {
return
}