Solve miscellaneous out-of-range bug
Occurs sometimes when the number of open squares is less than the number of neighbouring covered squares.
This commit is contained in:
parent
0affcd0675
commit
9bb75784a8
|
@ -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",
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
|
Loading…
Reference in New Issue