diff --git a/package.json b/package.json index ae36d06..9c31af1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minesweeper", - "version": "0.82.12", + "version": "0.82.13", "description": "Just Minesweeper!", "author": "F.W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/js/Field.ts b/src/main/js/Field.ts index a767435..bfc1ff2 100644 --- a/src/main/js/Field.ts +++ b/src/main/js/Field.ts @@ -249,8 +249,7 @@ export class Field { if (this.isSolvable) { let i = 1; const time = Timer.time(() => { - const solver = new Solver(); - while (!solver.canSolve(this, coords)) { + while (!Solver.canSolve(this, coords)) { this.shuffle(this.rng.uint32()); i++; } diff --git a/src/main/js/Game.ts b/src/main/js/Game.ts index dbdc0cf..8bdf827 100644 --- a/src/main/js/Game.ts +++ b/src/main/js/Game.ts @@ -223,7 +223,7 @@ export class Game { if (this.field !== null) { this.statistics.hintsRequested++; - this.display.hintSquare = (new Solver()).getHint(this.field); + this.display.hintSquare = Solver.getHint(this.field); } blurActiveElement(); } @@ -238,7 +238,7 @@ export class Game { if (this.field !== null) { this.statistics.solverUsages++; - (new Solver()).solve(this.field); + Solver.solve(this.field); } blurActiveElement(); } diff --git a/src/main/js/Solver.ts b/src/main/js/Solver.ts index 6e7ee8f..e590966 100644 --- a/src/main/js/Solver.ts +++ b/src/main/js/Solver.ts @@ -13,7 +13,7 @@ export class Solver { * * @param field the field to solve */ - solve(field: Field): void { + static solve(field: Field): void { if (field.hasWon || field.hasLost) return; if (field.hasStarted && !this.step(field.copy())) return; @@ -52,7 +52,7 @@ export class Solver { * @param field the field to check for solvability * @param initialSquare the initial coordinates to click at */ - canSolve(field: Field, initialSquare: { x: number, y: number } | undefined = undefined): boolean { + static canSolve(field: Field, initialSquare: { x: number, y: number } | undefined = undefined): boolean { const copy = field.copy(); if (initialSquare !== undefined) copy.runUndoably(() => copy.uncover(initialSquare)); this.solve(copy); @@ -65,7 +65,7 @@ export class Solver { * @param field the field to suggest a move for * @returns a suggestion for a next move based on the current state of the field */ - getHint(field: Field): Square | null { + static getHint(field: Field): Square | null { if (!field.hasStarted || field.hasWon || field.hasLost) return null; const knowns = Solver.getKnowns(field); @@ -102,7 +102,7 @@ export class Solver { * @returns `true` if a step could be solved * @private */ - private step(field: Field): boolean { + private static step(field: Field): boolean { let flagCount = field.flagCount; let coveredCount = field.coveredNonMineCount; @@ -134,7 +134,7 @@ export class Solver { * @param field the field to solve * @private */ - private stepSingleSquares(field: Field): void { + private static stepSingleSquares(field: Field): void { Solver.getKnowns(field) .forEach(square => { field.chord(square); @@ -155,7 +155,7 @@ export class Solver { * @param field the field to solve * @private */ - private stepNeighboringSquares(field: Field): void { + private static stepNeighboringSquares(field: Field): void { const knowns = Solver.getKnowns(field); knowns.forEach(known => { Solver.applySolution( @@ -174,7 +174,7 @@ export class Solver { * @param field the field to solve * @private */ - private stepAllSquares(field: Field): void { + private static stepAllSquares(field: Field): void { if (!field.hasStarted || field.hasWon || field.hasLost) return; const knowns = Solver.getKnowns(field); @@ -194,7 +194,7 @@ export class Solver { * @returns the solution that has been found * @private */ - private matrixSolve(field: Field, knowns: Square[], adjacentSquaresOnly: boolean): Solution { + private static matrixSolve(field: Field, knowns: Square[], adjacentSquaresOnly: boolean): Solution { if (knowns.length === 0) return []; let unknowns: Square[];