A fast Minesweeper solver bot framework built with Node.js + Playwright. The project ships with a local Minesweeper demo, a pluggable DOM adapter system, and a solver tuned for speedy deterministic play with graceful fallbacks when guessing is required.
- Node.js 18+
Install dependencies once before running any scripts:
npm installUse the bundled demo or point the solver at a supported remote page.
-
Open the bundled Minesweeper demo and solve it automatically:
npm run dev -- --level expert --speed 10
-
Point the solver at an allowed remote page (for example, Minesweeper Online):
npm run dev -- --url "https://minesweeperonline.com" --speed 20The runner appends the appropriate hash for the chosen difficulty:
- beginner →
https://minesweeperonline.com/#beginner - intermediate →
https://minesweeperonline.com/#intermediate - expert (default) →
https://minesweeperonline.com/#
- beginner →
When --serve is enabled (the default for npm run dev), the project hosts the local demo at http://localhost:4173 and the solver attaches to it automatically. Use npm run serve if you only need the static demo without launching Playwright.
- Deterministic-first solver that builds constraints from the visible board, searches for forced moves, and only guesses as a last resort.
- Pluggable adapters so the solver can target the bundled demo or other allowed Minesweeper pages.
- HUD overlays inside the controlled page that display elapsed time, move count, solver mode, and guess count while the bot runs.
- Scriptable CLI with presets for common flows (local demo, Minesweeper Online, or custom URLs).
Common flags are documented below; combine them as needed when invoking npm run dev or npm run run:
--levelbeginner|intermediate|expert (default: beginner)--seedseed for deterministic board (default: timestamp)--speeddelay in ms between action batches (default: 0)--headlessrun browser headless (default: false)--servestart the built-in static server (enabled by default innpm run dev)--urlpoint the runner at a different page; omit to use the local demo--keepOpenkeep the Playwright window open after solving (default: true)
The solver overlays a HUD showing elapsed time, moves, guesses, and the active mode (deterministic, search, or guess).
npm run serve– start the demo server without launching the solver.npm run run– run the solver without forcing the local server (useful if you are already hosting a page).npm run run:beginner,npm run run:intermediate,npm run run:expert– convenience presets for Minesweeper Online with--keepOpenenabled.
- Increase
--speed(ms) to slow the solver for debugging and to watch the HUD update. - Pass
--headlessfor automated runs when you do not need to watch the browser. - Disable serving with
--urlwhen pointing at an already-hosted page.
At a high level, the CLI runner starts a browser, chooses an adapter based on the target page, loops through reading board state, computing solver actions, applying them, and updating the HUD, then prints a summary. See docs/how-the-bot-works.md for a deeper walkthrough.
src/solver/*– pure solver logic (board helpers, constraint builder, search enumerator)src/adapter/*– automation interfaces, including the Playwright DOM adapter used for the local appsrc/run.ts– CLI entry point that spins up the server, launches Playwright, and drives the solverweb/– static Minesweeper demo used for local runstests/– vitest unit tests for constraint components and pruning
Implement the DomAdapter interface from src/adapter/types.ts with readState, applyActions, and updateHud methods. The adapter should return the board state as an Int8Array using the encoding:
-1unknown-2flagged0..8revealed numbers
See PlaywrightDomAdapter for an example that uses in-page APIs exposed by the demo app.
npm test