-
Notifications
You must be signed in to change notification settings - Fork 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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,6 +68,11 @@ export class WinCheckExecution implements Execution { | |||||||||
| (this.mg.ticks() - this.mg.config().numSpawnPhaseTurns()) / 10; | ||||||||||
| const numTilesWithoutFallout = | ||||||||||
| this.mg.numLandTiles() - this.mg.numTilesWithFallout(); | ||||||||||
|
|
||||||||||
| if (numTilesWithoutFallout === 0) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
Comment on lines
+72
to
+74
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. Timer-based win conditions are suppressed when all tiles have fallout. The early return before the combined The guard should wrap only the tile-percentage term: - if (numTilesWithoutFallout === 0) {
- return;
- }
-
if (
- (max.numTilesOwned() / numTilesWithoutFallout) * 100 >
- this.mg.config().percentageTilesOwnedToWin() ||
+ (numTilesWithoutFallout > 0 &&
+ (max.numTilesOwned() / numTilesWithoutFallout) * 100 >
+ this.mg.config().percentageTilesOwnedToWin()) ||
(this.mg.config().gameConfig().maxTimerValue !== undefined &&
timeElapsed - this.mg.config().gameConfig().maxTimerValue! * 60 >= 0) ||
timeElapsed >= WinCheckExecution.HARD_TIME_LIMIT_SECONDSApply the same pattern in Also applies to: 113-115 🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| if ( | ||||||||||
| (max.numTilesOwned() / numTilesWithoutFallout) * 100 > | ||||||||||
| this.mg.config().percentageTilesOwnedToWin() || | ||||||||||
|
|
@@ -104,9 +109,14 @@ export class WinCheckExecution implements Execution { | |||||||||
| (this.mg.ticks() - this.mg.config().numSpawnPhaseTurns()) / 10; | ||||||||||
| 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
+118
to
+119
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
}