diff --git a/.github/workflows/pages.yaml b/.github/workflows/pages.yaml new file mode 100644 index 0000000..87eceae --- /dev/null +++ b/.github/workflows/pages.yaml @@ -0,0 +1,57 @@ +name: CI + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Install rust toolchain + uses: dtolnay/rust-toolchain@beta + with: + targets: wasm32-unknown-unknown + + - name: Install trunk + uses: taiki-e/install-action@v2 + with: + tool: trunk + + - name: Checkout + uses: actions/checkout@v4 + + - name: Build website + run: trunk build + + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: dist + + deploy: + needs: build + runs-on: ubuntu-latest + + if: github.event_name != 'pull_request' + + permissions: + pages: write + id-token: write + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v3 + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..897a8f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +/dist +.DS_Store diff --git a/README.md b/README.md index b7aa15d..8603df3 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,51 @@ # Mindsweeper — a principled take on minesweeper -To play, visit https://alexbuz.github.io/mindsweeper/. Once the page loads, no further internet connection is required. +To play, visit https://alexbuz.github.io/mindsweeper/. Once the page loads, no further internet +connection is required. ## Background -Traditional minesweeper is a game of logical deduction—until it's not. Sometimes, you end up in a situation where there is not enough information to find a tile that is definitely safe to reveal. In such cases, guessing is required to proceed, and that often leads to the loss of an otherwise smooth-sailing game. However, there's no reason it has to be that way. It's merely a consequence of the random manner in which mines are typically arranged at the start of the game. Some mine arrangements happen to necessitate guessing, while others do not. This is a matter of luck, and it's not a particularly fun aspect of a game that is otherwise about logic. +Traditional minesweeper is a game of logical deduction—until it's not. Sometimes, you end up in a +situation where there is not enough information to find a tile that is definitely safe to reveal. In +such cases, guessing is required to proceed, and that often leads to the loss of an otherwise +smooth-sailing game. However, there's no reason it has to be that way. It's merely a consequence of +the random manner in which mines are typically arranged at the start of the game. Some mine +arrangements happen to necessitate guessing, while others do not. This is a matter of luck, and it's +not a particularly fun aspect of a game that is otherwise about logic. -Eliminating the need for guesswork, then, is a matter of modifying the mine arrangement algorithm. Rather than simply placing each mine under a random tile, it should instead consider each mine arrangement as a whole, choosing a random mine arrangement from the set of mine arrangements that would allow a perfect logician to win without guessing. Ideally, it should sample uniformly from that set of mine arrangements, ensuring that every such arrangement is equally likely to be chosen. That is precisely what mindsweeper is designed to do, and it accomplishes this within a matter of milliseconds after you make your first click. +Eliminating the need for guesswork, then, is a matter of modifying the mine arrangement algorithm. +Rather than simply placing each mine under a random tile, it should instead consider each mine +arrangement as a whole, choosing a random mine arrangement from the set of mine arrangements that +would allow a perfect logician to win without guessing. Ideally, it should sample uniformly from +that set of mine arrangements, ensuring that every such arrangement is equally likely to be chosen. +That is precisely what mindsweeper is designed to do, and it accomplishes this within a matter of +milliseconds after you make your first click. ## Features 1. Guessing is *never* necessary - There's no need to toggle a setting. Mindsweeper is a game of pure skill, always. 2. Guess punishment - - Since guessing is already unnecessary, it's only natural to take the idea of "no guessing" a step further and forbid guessing entirely. This feature, enabled by default, effectively rids the game of all remaining luck aspects. If you click on a tile that *can* be a mine, then it *will* be a mine, guaranteed. + - Since guessing is already unnecessary, it's only natural to take the idea of "no guessing" a + step further and forbid guessing entirely. This feature, enabled by default, effectively rids + the game of all remaining luck aspects. If you click on a tile that *can* be a mine, then it + *will* be a mine, guaranteed. 3. Unrestricted first click - - Mindsweeper does not obligate you to click a particular tile to start the game. The mine arrangement algorithm works on demand, and is fast enough to avoid introducing any delay. + - Mindsweeper does not obligate you to click a particular tile to start the game. The mine + arrangement algorithm works on demand, and is fast enough to avoid introducing any delay. 4. Uniform sampling - - All mine arrangements are viable, except those that necessitate guessing. If a particular mine arrangement is solvable by a perfect logician without guessing, then it's just as likely to be picked by the algorithm as every other viable arrangement. + - All mine arrangements are viable, except those that necessitate guessing. If a particular mine + arrangement is solvable by a perfect logician without guessing, then it's just as likely to be + picked by the algorithm as every other viable arrangement. 5. Post-mortem analysis - - If you reveal a mine and lose the game, you'll get feedback that helps you improve. You get to see which flags you misplaced (if any), as well as which tiles you could (and could not) have safely revealed. Tiles are color-coded to show this information at a glance, and you can also hover over any tile to see this explained in words. + - If you reveal a mine and lose the game, you'll get feedback that helps you improve. You get to + see which flags you misplaced (if any), as well as which tiles you could (and could not) have + safely revealed. Tiles are color-coded to show this information at a glance, and you can also + hover over any tile to see this explained in words. 6. High performance - - Mindsweeper is written in Rust and compiles to WASM. When you make your first click, the mine arrangement algorithm generally finishes running before you even release the mouse button, so there is no first-click delay. + - Mindsweeper is written in Rust and compiles to WASM. When you make your first click, the mine + arrangement algorithm generally finishes running before you even release the mouse button, so + there is no first-click delay. 7. Completely offline - Mindsweeper does not depend on a server. All of the code runs locally in your browser. @@ -35,6 +59,8 @@ cd mindsweeper trunk build ``` -The built files will be placed in the `dist` directory, the contents of which must be placed in `docs` to be served by GitHub Pages. +The built files will be placed in the `dist` directory, the contents of which must be served to the +user. -For development, instead of `trunk build`, you can run `trunk serve --public-url=/ --open` to start a local server that automatically rebuilds the project when you make changes. \ No newline at end of file +For development, instead of `trunk build`, you can run `trunk serve --public-url=/ --open` to start +a local server that automatically rebuilds the project when you make changes. diff --git a/benches/solvable_bench.rs b/benches/solvable_bench.rs index 09dd500..71418a2 100644 --- a/benches/solvable_bench.rs +++ b/benches/solvable_bench.rs @@ -6,7 +6,7 @@ fn criterion_benchmark(c: &mut Criterion) { let game_config = GameConfig { grid_config: GridConfig::expert(), mode: GameMode::Normal, - punish_guessing: true, + ..Default::default() }; b.iter(|| LocalGame::new(game_config, game_config.grid_config.random_tile_id())) }); @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) { let game_config = GameConfig { grid_config: GridConfig::expert(), mode: GameMode::Mindless, - punish_guessing: true, + ..Default::default() }; b.iter(|| LocalGame::new(game_config, game_config.grid_config.random_tile_id())) }); diff --git a/docs/favicon-243584e0eb10e903.svg b/docs/favicon-243584e0eb10e903.svg deleted file mode 100644 index 9c3b84b..0000000 --- a/docs/favicon-243584e0eb10e903.svg +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/docs/favicon-46b4b2a00dd13992.png b/docs/favicon-46b4b2a00dd13992.png deleted file mode 100644 index e6d5e02..0000000 Binary files a/docs/favicon-46b4b2a00dd13992.png and /dev/null differ diff --git a/docs/index.html b/docs/index.html deleted file mode 100644 index 7cc0156..0000000 --- a/docs/index.html +++ /dev/null @@ -1,10 +0,0 @@ -
- -