Skip to content

Instantly share code, notes, and snippets.

@MightyAlex200
Last active April 22, 2018 03:11
Show Gist options
  • Save MightyAlex200/bcaa6d87094e66b1284cf227fe79e529 to your computer and use it in GitHub Desktop.
Save MightyAlex200/bcaa6d87094e66b1284cf227fe79e529 to your computer and use it in GitHub Desktop.
minesweeper.io bot
// it's p e r f e c t
// 1 - 8 => actual number
// 0 => exploded
// 9 => blank
// 10 => unknown
// else => flag
// 34x48
function a() {
let o = window.appController.minesweeper;
let probabilities = [];
let height = 64;
let width = 64;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const square = o.playGrid.get(x, y);
if (square > 8 || square < 1) { continue; }
const neighbors = o.playGrid.getNeighbors(x, y);
const mines_near = neighbors.filter(a =>
o.playGrid.get(a.x, a.y) > 11 || o.playGrid.get(a.x, a.y) <= 0
).length;
const empty_near = neighbors.filter(a => o.playGrid.get(a.x, a.y) == 10).length;
const prob = (square - mines_near) / empty_near;
if (prob == 1) {
for (const neighbor of neighbors) {
o.placeFlag(neighbor.x, neighbor.y);
}
requestAnimationFrame(a);
return;
}
if (prob == 0) {
for (const neighbor of neighbors) {
o.revealCell(neighbor.x, neighbor.y);
}
requestAnimationFrame(a);
return;
}
}
}
requestAnimationFrame(a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment