Refine win/loss statistic measurements

Losses are no longer counted since they can be inferred from the existing statistics. Instead, there is now a `minesUncovered` statistics, and redoing an uncovering of a mine will also increase this statistic. Finally, made sure that `wasAutoSolved` cannot be set to `false` again.
This commit is contained in:
Florine W. Dekker 2020-08-13 10:55:53 +02:00
parent 7f491b0ef2
commit f94ee57811
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 24 additions and 26 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "minesweeper", "name": "minesweeper",
"version": "0.81.3", "version": "0.81.4",
"description": "Just Minesweeper!", "description": "Just Minesweeper!",
"author": "Felix W. Dekker", "author": "Felix W. Dekker",
"browser": "dist/bundle.js", "browser": "dist/bundle.js",

View File

@ -44,7 +44,6 @@ export class Field {
return this._hasWon; return this._hasWon;
} }
private _hasLostBefore: boolean = false;
private _hasLost: boolean = false; private _hasLost: boolean = false;
get hasLost(): boolean { get hasLost(): boolean {
return this._hasLost; return this._hasLost;
@ -55,7 +54,11 @@ export class Field {
return this._deathCount; return this._deathCount;
} }
wasAutoSolved: boolean = false; private _wasAutoSolved: boolean = false;
set wasAutoSolved(value: boolean) {
if (this._wasAutoSolved && !value) throw new Error("Cannot set wasAutoSolved to false while it is true.");
this._wasAutoSolved = value;
}
/** /**
@ -270,11 +273,7 @@ export class Field {
this.timer.stop(); this.timer.stop();
this._hasLost = true; this._hasLost = true;
this._deathCount++; this._deathCount++;
this.statistics.minesUncovered++;
if (!this._hasLostBefore && !this.wasAutoSolved) {
this._hasLostBefore = true;
this.statistics.gamesLost++;
}
} else { } else {
this._coveredNonMineCount--; this._coveredNonMineCount--;
if (this.coveredNonMineCount === 0) { if (this.coveredNonMineCount === 0) {
@ -284,11 +283,10 @@ export class Field {
this._flagCount = this.mineCount; this._flagCount = this.mineCount;
this._hasWon = true; this._hasWon = true;
if (!this._hasWonBefore && !this.wasAutoSolved) { if (!this._hasWonBefore && !this._wasAutoSolved) {
this._hasWonBefore = true; this._hasWonBefore = true;
this.statistics.gamesWon++; this.statistics.gamesWon++;
if (this.deathCount === 0) if (this.deathCount === 0) this.statistics.gamesWonWithoutLosing++;
this.statistics.gamesWonWithoutLosing++;
} }
} }
} }

View File

@ -12,7 +12,6 @@ export interface Statistics {
timeSpent: number; timeSpent: number;
gamesStarted: number; gamesStarted: number;
gamesLost: number;
gamesWon: number; gamesWon: number;
gamesWonWithoutLosing: number; gamesWonWithoutLosing: number;
@ -21,6 +20,7 @@ export interface Statistics {
squaresFlagged: number; squaresFlagged: number;
squaresMarked: number; squaresMarked: number;
squaresUncovered: number; squaresUncovered: number;
minesUncovered: number;
hintsRequested: number; hintsRequested: number;
solverUsages: number; solverUsages: number;
@ -84,14 +84,6 @@ export class LocalStatistics implements Statistics {
this.storage.setNumber("gamesStarted", value); this.storage.setNumber("gamesStarted", value);
} }
get gamesLost(): number {
return this.storage.getNumber("gamesLost", 0);
}
set gamesLost(value: number) {
this.storage.setNumber("gamesLost", value);
}
get gamesWon(): number { get gamesWon(): number {
return this.storage.getNumber("gamesWon", 0); return this.storage.getNumber("gamesWon", 0);
} }
@ -148,6 +140,14 @@ export class LocalStatistics implements Statistics {
this.storage.setNumber("squaresUncovered", value); this.storage.setNumber("squaresUncovered", value);
} }
get minesUncovered(): number {
return this.storage.getNumber("minesUncovered", 0);
}
set minesUncovered(value: number) {
this.storage.setNumber("minesUncovered", value);
}
get hintsRequested(): number { get hintsRequested(): number {
return this.storage.getNumber("hintsRequested", 0); return this.storage.getNumber("hintsRequested", 0);
} }
@ -204,10 +204,6 @@ export class LocalStatistics implements Statistics {
<th>Games completed without losing</th> <th>Games completed without losing</th>
<td>${this.gamesWonWithoutLosing}</td> <td>${this.gamesWonWithoutLosing}</td>
</tr> </tr>
<tr>
<th>Games completed with at least one loss</th>
<td>${this.gamesLost}</td>
</tr>
</table> </table>
<h3>Steps taken</h3> <h3>Steps taken</h3>
@ -232,6 +228,10 @@ export class LocalStatistics implements Statistics {
<th>Squares uncovered</th> <th>Squares uncovered</th>
<td>${this.squaresUncovered}</td> <td>${this.squaresUncovered}</td>
</tr> </tr>
<tr>
<th>Mines uncovered</th>
<td>${this.minesUncovered}</td>
</tr>
</table> </table>
<h3>Solver usage</h3> <h3>Solver usage</h3>
@ -256,7 +256,6 @@ export class MemoryStatistics implements Statistics {
actionsRedone: number = 0; actionsRedone: number = 0;
lossesUndone: number = 0; lossesUndone: number = 0;
timeSpent: number = 0; timeSpent: number = 0;
gamesLost: number = 0;
gamesStarted: number = 0; gamesStarted: number = 0;
gamesWon: number = 0; gamesWon: number = 0;
gamesWonWithoutLosing: number = 0; gamesWonWithoutLosing: number = 0;
@ -265,6 +264,7 @@ export class MemoryStatistics implements Statistics {
squaresFlagged: number = 0; squaresFlagged: number = 0;
squaresMarked: number = 0; squaresMarked: number = 0;
squaresUncovered: number = 0; squaresUncovered: number = 0;
minesUncovered: number = 0;
hintsRequested: number = 0; hintsRequested: number = 0;
solverUsages: number = 0; solverUsages: number = 0;
@ -274,7 +274,6 @@ export class MemoryStatistics implements Statistics {
this.actionsRedone = 0; this.actionsRedone = 0;
this.lossesUndone = 0; this.lossesUndone = 0;
this.timeSpent = 0; this.timeSpent = 0;
this.gamesLost = 0;
this.gamesStarted = 0; this.gamesStarted = 0;
this.gamesWon = 0; this.gamesWon = 0;
this.gamesWonWithoutLosing = 0; this.gamesWonWithoutLosing = 0;
@ -283,6 +282,7 @@ export class MemoryStatistics implements Statistics {
this.squaresFlagged = 0; this.squaresFlagged = 0;
this.squaresMarked = 0; this.squaresMarked = 0;
this.squaresUncovered = 0; this.squaresUncovered = 0;
this.minesUncovered = 0;
this.hintsRequested = 0; this.hintsRequested = 0;
this.solverUsages = 0; this.solverUsages = 0;
} }