ms-toollib 1.5.6 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -3
- package/ms_toollib.d.ts +467 -463
- package/ms_toollib.js +5 -1
- package/ms_toollib_bg.js +1834 -1870
- package/ms_toollib_bg.wasm +0 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# ms-toollib
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/ms-toollib)
|
|
4
|
+
[](https://github.com/eee555/ms_toollib/blob/main/LICENSE)
|
|
5
|
+
[](https://docs.rs/ms_toollib/latest/ms_toollib)
|
|
6
|
+
|
|
7
|
+
A minesweeper algorithm toolbox with a native Rust core, compiled to WebAssembly.
|
|
8
|
+
|
|
9
|
+
Works in browsers (via bundler) and Node.js. No Python runtime required.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Who is this for?
|
|
14
|
+
|
|
15
|
+
- **Minesweeper enthusiasts** — analyze your replays, compute difficulty metrics (3BV, ZiNi), compare performance
|
|
16
|
+
- **Trainer / bot developers** — generate no-guess boards on demand, compute probabilities, drive a game state machine
|
|
17
|
+
- **Minesweeper website builders** — embed board generation, solving, and replay parsing entirely on the client side
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## What problems does it solve?
|
|
22
|
+
|
|
23
|
+
| Problem | Solution |
|
|
24
|
+
|---|---|
|
|
25
|
+
| I need to generate minesweeper boards that are guaranteed solvable (no-guess) | `laymine_solvable()` / other laymine variants — filter & adjustment methods |
|
|
26
|
+
| I want to rate a board's difficulty objectively | `cal_bbbv()` / `Board.bbbv` → 3BV, ZiNi, openings, islands |
|
|
27
|
+
| I need to know the exact mine probability per cell for advanced play | `cal_probability_onboard()` — block decomposition + enumeration |
|
|
28
|
+
| I want to check if a given board is solvable without guessing | `is_solvable()` — detects guess-while-needless positions |
|
|
29
|
+
| I'm building an interactive minesweeper UI and don't want to write game logic | `MinesweeperBoard` class — handles clicks, flags, chords, win/loss detection |
|
|
30
|
+
| I downloaded a replay (.avf / .evf / .mvf / .rmf) and want to extract metrics | Parse with e.g. `AvfVideo`, then read `.bbbv`, `.zini`, `.rtime`, `.iop`, etc. |
|
|
31
|
+
| I want to embed all of this in a web app without a backend | Package is pure WebAssembly — runs entirely in the browser |
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install ms-toollib
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
import init, {
|
|
47
|
+
cal_bbbv, cal_zini, laymine_solvable, cal_probability_onboard,
|
|
48
|
+
Board, AvfVideo, MinesweeperBoard
|
|
49
|
+
} from "ms-toollib";
|
|
50
|
+
|
|
51
|
+
await init();
|
|
52
|
+
|
|
53
|
+
// ── Generate a no-guess Beginner board ──
|
|
54
|
+
const board = laymine_solvable(9, 9, 10, 0, 0, 8000);
|
|
55
|
+
// board[0] = 2D board, board[1] = success flag
|
|
56
|
+
const grid = board[0];
|
|
57
|
+
console.log("3BV:", cal_bbbv(grid));
|
|
58
|
+
|
|
59
|
+
// ── Board metrics via the Board class ──
|
|
60
|
+
const b = new Board(grid);
|
|
61
|
+
console.log("Openings:", b.op, "Islands:", b.isl);
|
|
62
|
+
|
|
63
|
+
// ── Mine probability per cell ──
|
|
64
|
+
const prob = cal_probability_onboard(grid, 10);
|
|
65
|
+
// prob[0] = probability grid, prob[1] = mine count range [min, max, total]
|
|
66
|
+
|
|
67
|
+
// ── Interactive game state machine ──
|
|
68
|
+
const ms = new MinesweeperBoard(grid);
|
|
69
|
+
ms.step("lc", 4, 4); // left-click (row, col)
|
|
70
|
+
ms.step("lr", 4, 4); // left-release (row, col)
|
|
71
|
+
console.log("Flags placed:", ms.flag, "Cells opened:", ms.lce);
|
|
72
|
+
|
|
73
|
+
// ── Parse a replay ──
|
|
74
|
+
// (requires fetching the file as Uint8Array)
|
|
75
|
+
const response = await fetch("replay.avf");
|
|
76
|
+
const data = new Uint8Array(await response.arrayBuffer());
|
|
77
|
+
const video = new AvfVideo(data, "replay.avf");
|
|
78
|
+
video.parse();
|
|
79
|
+
video.analyse();
|
|
80
|
+
console.log("3BV:", video.bbbv);
|
|
81
|
+
console.log("ZiNi:", video.zini);
|
|
82
|
+
console.log("Time (ms):", video.rtime_ms);
|
|
83
|
+
console.log("3BV/s:", video.bbbv_s);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Public API
|
|
89
|
+
|
|
90
|
+
**Functions (8):**
|
|
91
|
+
`cal_bbbv`, `cal_op`, `cal_probability_onboard`, `is_solvable`, `laymine`, `laymine_op`, `laymine_solvable`, `valid_time_period`
|
|
92
|
+
|
|
93
|
+
**Classes (16):**
|
|
94
|
+
`AvfVideo`, `Board`, `BoardEvent`, `CursorPos`, `Event`, `EvfVideo`, `GameBoard`, `GameStateEvent`, `IndexEvent`, `KeyDynamicParams`, `MinesweeperBoard`, `MouseEvent`, `MvfVideo`, `RmvVideo`, `TimePeriod`, `VideoActionStateRecorder`
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Supported Environments
|
|
99
|
+
|
|
100
|
+
| Environment | Build Target |
|
|
101
|
+
|---|---|
|
|
102
|
+
| Browser (webpack, vite, etc.) | `wasm-pack build` (bundler) |
|
|
103
|
+
| Node.js | `wasm-pack build --target nodejs` |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Build from Source
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Requires wasm-pack: https://rustwasm.github.io/wasm-pack/
|
|
111
|
+
wasm-pack build # browser bundler
|
|
112
|
+
wasm-pack build --target nodejs # Node.js
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Source & Issues
|
|
118
|
+
|
|
119
|
+
- GitHub: <https://github.com/eee555/ms_toollib>
|
|
120
|
+
- Documentation: <https://docs.rs/ms_toollib/latest/ms_toollib>
|
|
121
|
+
- npm: <https://www.npmjs.com/package/ms-toollib>
|