Skip to content

Commit

Permalink
Fix position set-up bug which locks a value in place which can't be c…
Browse files Browse the repository at this point in the history
…hanged.
  • Loading branch information
DavidNHill committed Jul 9, 2023
1 parent 547be93 commit 1f7945a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"\\Minesweeper\\client",
"\\Minesweeper\\Utility"
],
"SelectedNode": "\\Minesweeper\\client\\solver_main.js",
"SelectedNode": "\\Minesweeper\\client\\main.js",
"PreviewInSolutionExplorer": false
}
Binary file modified .vs/slnx.sqlite
Binary file not shown.
8 changes: 6 additions & 2 deletions Minesweeper/client/Board.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,21 @@ class Board {
// optionally treat flags as mines (e.g. in analysis mode but not playing or replay)
// place mines when they are trivially found
// The idea is to get the board into a state as pobability engine friendly as possible
resetForAnalysis(flagIsMine) {
resetForAnalysis(flagIsMine, findObviousMines) {

for (let i = 0; i < this.tiles.length; i++) {
const tile = this.tiles[i];
if (tile.isFlagged()) {
tile.foundBomb = flagIsMine;
} else {
tile.foundBomb = false;
}
}
}

if (!findObviousMines) {
return;
}

for (let i = 0; i < this.tiles.length; i++) {

const tile = this.getTile(i);
Expand Down
25 changes: 13 additions & 12 deletions Minesweeper/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,9 @@ function loadReplayData(file) {

updateMineCount(board.bombs_left);

// enable the analysis button - it might have been previous in an invalid layout
analysisButton.disabled = false;

};

fr.readAsText(file);
Expand Down Expand Up @@ -1496,9 +1499,6 @@ async function replayForward(replayType) {
let hints;
let other;

//board.resetForAnalysis(false);
//board.findAutoMove();

const solve = await solver(board, options); // look for solutions
hints = solve.actions;
other = solve.other;
Expand Down Expand Up @@ -1672,9 +1672,8 @@ async function replayBackward(replayType) {
let hints;
let other;

board.resetForAnalysis(false);
//board.findAutoMove();

board.resetForAnalysis(false, true);

const solve = await solver(board, options); // look for solutions
hints = solve.actions;
other = solve.other;
Expand Down Expand Up @@ -1736,9 +1735,7 @@ async function doAnalysis() {

// this will set all the obvious mines which makes the solution counter a lot more efficient on very large boards
if (analysisMode) {
board.resetForAnalysis(!replayMode); // in replay mode don't treat flags as mines

//board.findAutoMove(); // - this is now done in "resetForAnalysis"
board.resetForAnalysis(!replayMode, true); // in replay mode don't treat flags as mines
}

const solutionCounter = solver.countSolutions(board);
Expand Down Expand Up @@ -1795,7 +1792,7 @@ async function checkBoard() {
}

// this will set all the obvious mines which makes the solution counter a lot more efficient on very large boards
board.resetForAnalysis(true);
//board.resetForAnalysis(true, true);

const currentBoardHash = board.getHashValue();

Expand All @@ -1807,9 +1804,11 @@ async function checkBoard() {

console.log("Checking board with hash " + currentBoardHash);

board.findAutoMove();
// this will set all the obvious mines which makes the solution counter a lot more efficient on very large boards
board.resetForAnalysis(true, true);

const solutionCounter = await solver.countSolutions(board);
board.resetForAnalysis(true);
board.resetForAnalysis(true, false);

if (solutionCounter.finalSolutionsCount != 0) {
analysisButton.disabled = false;
Expand Down Expand Up @@ -2150,6 +2149,8 @@ function on_mouseWheel(event) {
const flagCount = board.adjacentFoundMineCount(tile);
const covered = board.adjacentCoveredCount(tile);

//console.log("flag=" + flagCount + ", Covered=" + covered);

let newValue;
if (tile.isCovered()) {
newValue = flagCount;
Expand Down

0 comments on commit 1f7945a

Please sign in to comment.