From 9bb75784a8de05e59e52483d913d10598e5e0a71 Mon Sep 17 00:00:00 2001 From: "Felix W. Dekker" Date: Sat, 1 Aug 2020 00:18:51 +0200 Subject: [PATCH] Solve miscellaneous out-of-range bug Occurs sometimes when the number of open squares is less than the number of neighbouring covered squares. --- package.json | 2 +- src/main/js/Solver.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c9c9679..4998c23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minesweeper", - "version": "0.0.40", + "version": "0.0.41", "description": "Just Minesweeper!", "author": "Felix W. Dekker", "browser": "dist/bundle.js", diff --git a/src/main/js/Solver.ts b/src/main/js/Solver.ts index c7cf309..64d6e95 100644 --- a/src/main/js/Solver.ts +++ b/src/main/js/Solver.ts @@ -173,7 +173,10 @@ export class Matrix { return range(this.colCount - 1) .map(it => { - const row = this.getRow(this.getCol(it).findIndex(it => it === 1)); + const rowPivotIndex = this.getCol(it).findIndex(it => it === 1); + if (rowPivotIndex < 0) return undefined; + + const row = this.getRow(rowPivotIndex); if (row.slice(0, it).every(it => it === 0) && row.slice(it + 1, -1).every(it => it === 0)) return row.slice(-1)[0];