Skip to content

Commit

Permalink
Merge pull request #2 from gtsiam/pr-count-flags
Browse files Browse the repository at this point in the history
Implements feature for subtracting the number of adjacent flags from each number tile
  • Loading branch information
AlexBuz authored Dec 16, 2023
2 parents 3b6d0f3 + d4bf7fa commit b6d31a6
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 1,085 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/pages.yaml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
/dist
.DS_Store
46 changes: 36 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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.
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.
4 changes: 2 additions & 2 deletions benches/solvable_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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()))
});
c.bench_function("new_expert_mindless", |b| {
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()))
});
Expand Down
4 changes: 0 additions & 4 deletions docs/favicon-243584e0eb10e903.svg

This file was deleted.

Binary file removed docs/favicon-46b4b2a00dd13992.png
Binary file not shown.
10 changes: 0 additions & 10 deletions docs/index.html

This file was deleted.

168 changes: 0 additions & 168 deletions docs/main-610f006d6bf581a5.css

This file was deleted.

Loading

0 comments on commit b6d31a6

Please sign in to comment.