diff --git a/package.json b/package.json index 98ec783..c6e4ea5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minesweeper", - "version": "0.79.2", + "version": "0.79.3", "description": "Just Minesweeper!", "author": "Felix W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/js/Field.ts b/src/main/js/Field.ts index fd9b939..26c9920 100644 --- a/src/main/js/Field.ts +++ b/src/main/js/Field.ts @@ -38,11 +38,13 @@ export class Field { return this._hasStarted; } + private _hasWonBefore: boolean = false; private _hasWon: boolean = false; get hasWon(): boolean { return this._hasWon; } + private _hasLostBefore: boolean = false; private _hasLost: boolean = false; get hasLost(): boolean { return this._hasLost; @@ -53,6 +55,8 @@ export class Field { return this._deathCount; } + wasAutoSolved: boolean = false; + /** * Constructs a new playing field for a game of Minesweeper. @@ -290,7 +294,11 @@ export class Field { this.timer.stop(); this._hasLost = true; this._deathCount++; - this.statistics.gamesLost++; + + if (!this._hasLostBefore && !this.wasAutoSolved) { + this._hasLostBefore = true; + this.statistics.gamesLost++; + } } else { this._coveredNonMineCount--; if (this.coveredNonMineCount === 0) { @@ -299,7 +307,13 @@ export class Field { remainingFlags.forEach(it => it.hasFlag = true); this._flagCount = this.mineCount; this._hasWon = true; - this.statistics.gamesWon++; + + if (!this._hasWonBefore && !this.wasAutoSolved) { + this._hasWonBefore = true; + this.statistics.gamesWon++; + if (this.deathCount === 0) + this.statistics.gamesWonWithoutLosing++; + } } } }, diff --git a/src/main/js/Solver.ts b/src/main/js/Solver.ts index 733fded..8469e8e 100644 --- a/src/main/js/Solver.ts +++ b/src/main/js/Solver.ts @@ -15,6 +15,7 @@ export class Solver { */ solve(field: Field): void { if (field.hasWon || field.hasLost) return; + field.wasAutoSolved = true; if (!field.hasStarted) { field.runUndoably(() => { diff --git a/src/main/js/Statistics.ts b/src/main/js/Statistics.ts index a5c9012..7a2e4a9 100644 --- a/src/main/js/Statistics.ts +++ b/src/main/js/Statistics.ts @@ -12,6 +12,7 @@ export interface Statistics { gamesStarted: number; gamesLost: number; gamesWon: number; + gamesWonWithoutLosing: number; squaresChorded: number; squaresChordedLeadingToLoss: number; @@ -118,6 +119,16 @@ export class LocalStatistics implements Statistics { this.write(statistics); } + get gamesWonWithoutLosing(): number { + return +(this.read()["gamesWonWithoutLosing"] ?? 0); + } + + set gamesWonWithoutLosing(value: number) { + const statistics = this.read(); + statistics["gamesWonWithoutLosing"] = "" + value; + this.write(statistics); + } + get squaresChorded(): number { return +(this.read()["squaresChorded"] ?? 0); } @@ -208,6 +219,10 @@ export class LocalStatistics implements Statistics {