parent
6adc3de1c4
commit
0ba2f34146
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "minesweeper",
|
||||
"version": "0.80.1",
|
||||
"version": "0.80.2",
|
||||
"description": "Just Minesweeper!",
|
||||
"author": "Felix W. Dekker",
|
||||
"browser": "dist/bundle.js",
|
||||
|
|
|
@ -95,11 +95,9 @@ export class Solver {
|
|||
*/
|
||||
getHint(field: Field): Square | null {
|
||||
if (!field.hasStarted || field.hasWon || field.hasLost) return null;
|
||||
|
||||
let candidate: Square | undefined;
|
||||
const knowns = this.getKnowns(field);
|
||||
|
||||
candidate = knowns.find(square =>
|
||||
const candidate = knowns.find(square =>
|
||||
// Can chord
|
||||
square.getNeighborCount(it => it.hasFlag) === square.getNeighborCount(it => it.hasMine) ||
|
||||
// Can flag
|
||||
|
@ -108,11 +106,18 @@ export class Solver {
|
|||
);
|
||||
if (candidate !== undefined) return candidate;
|
||||
|
||||
candidate = knowns.find(square =>
|
||||
this.matrixSolve(field, square.neighbors.filter(it => !it.isCovered).concat(square), true)
|
||||
.some(it => it !== undefined)
|
||||
);
|
||||
if (candidate !== undefined) return candidate;
|
||||
for (let i = 0; i < knowns.length; i++) {
|
||||
const square = knowns[i];
|
||||
const solution = this.matrixSolve(field, square.neighbors.filter(it => !it.isCovered).concat(square), true);
|
||||
const candidate = solution.find(it => it !== undefined);
|
||||
if (candidate !== undefined)
|
||||
return candidate[1];
|
||||
}
|
||||
|
||||
const solution = this.matrixSolve(field, knowns, false);
|
||||
const candidate2 = solution.find(it => it !== undefined);
|
||||
if (candidate2 !== undefined)
|
||||
return candidate2[1];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue