@johnmorrisdotca/houseki 0.1.0 → 0.2.0
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/CHANGELOG.md +53 -8
- package/README.md +259 -46
- package/dist/colour-chains/challenge.js +18 -4
- package/dist/colour-chains/content-data.js +19582 -2
- package/dist/colour-chains/content-types.d.ts +21 -0
- package/dist/colour-chains/content.d.ts +9 -1
- package/dist/colour-chains/content.js +13 -0
- package/dist/colour-chains/engine.js +8 -4
- package/dist/colour-chains/input.js +1 -0
- package/dist/colour-chains/persistence.js +1 -1
- package/dist/colour-chains/types.d.ts +6 -2
- package/dist/colour-chains.d.ts +2 -2
- package/dist/colour-chains.js +1 -1
- package/dist/falling-triplets/engine.js +1 -1
- package/dist/falling-triplets/input.js +1 -0
- package/dist/gem-swap/engine.js +1 -1
- package/dist/gem-swap/specials.js +1 -1
- package/dist/gem-swap/tools.js +1 -1
- package/dist/magnetic-blocks/content-data.d.ts +3 -0
- package/dist/magnetic-blocks/content-data.js +11781 -0
- package/dist/magnetic-blocks/content-types.d.ts +66 -0
- package/dist/magnetic-blocks/content-types.js +1 -0
- package/dist/magnetic-blocks/content.d.ts +16 -0
- package/dist/magnetic-blocks/content.js +38 -0
- package/dist/magnetic-blocks/engine.js +4 -2
- package/dist/magnetic-blocks.d.ts +2 -0
- package/dist/magnetic-blocks.js +1 -0
- package/dist/nature/environment.js +4 -5
- package/dist/nature/rebound.js +1 -1
- package/dist/stone-collapse/engine.js +1 -1
- package/dist/stone-collapse/validation.js +1 -2
- package/package.json +59 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,55 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
All notable changes to this package are written here, newest first, in the form of [Keep a Changelog](https://keepachangelog.com), and this package follows [Semantic Versioning](https://semver.org).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.2.0] - 2026-10-06
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Three dedicated fifty-level campaigns: Magnetic Blocks, Shizen and Arashi, bringing the package to 450 original graded challenges. Exact boards, finite queues, stable IDs, measured difficulty, winning witnesses and deterministic generation are published with the engines.
|
|
12
|
+
- Campaign selectors, fixed rule displays, goal progress, replay and next-level recovery in the players.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- Clear game-over results and disabled play controls; fixed challenge settings; exact save recovery; responsive goal text; shared cloth and piece appearance; generated API imports and markup.
|
|
17
|
+
- Stable board geometry when switching English and Japanese at phone, tablet and desktop widths.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- `CONTRIBUTING.md` is the family's one text with a section of its own for Houseki, held to the master in johnmorrisdotca/.github by `src/family.test.js`; `ci.yml` and `pages.yml` are the family's one text (`pnpm check`, the demo, and the package on Linux, macOS and Windows), and any jobs of the package's own after them.
|
|
23
|
+
- The demo's shared stylesheet is `demo/houseki.css` (it was `game.css`), named for the package like the family's.
|
|
24
|
+
|
|
25
|
+
## [0.1.1] - 2026-10-05
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- The package is brought to the family's standard: the same checks (`pnpm check` is lint, types and tests), tests run by Vitest, a CI workflow on Node 22 and 24, a release workflow that publishes by trusted publishing, and a Pages workflow, all on current action versions; `pnpm test:package` packs, installs and imports every entry point.
|
|
30
|
+
- `package.json` is made like the family's: a description short enough for npm, homepage, author, `module` and `sideEffects`.
|
|
31
|
+
- The README follows the family's order and lists all twenty-four packages of the family, made from the shared template.
|
|
32
|
+
- The demo's four pages are made under the family's header, footer, language chooser, Help switch and table cloths, with a description, an icon and a title in the family's form, and an API reference in the same header. The page's own Theme button is gone: light and dark follow the device, as in the other demos.
|
|
33
|
+
- The demo's tests are Playwright tests that run at a phone's width and a desk's, in Chromium, and the pages themselves in WebKit too.
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- A new game on a page served over plain http, from an address other than localhost, no longer fails: the seed falls back to random bytes where `crypto.randomUUID` does not exist.
|
|
38
|
+
- The API reference no longer widens the page on a phone for a doc comment that names a long entry path.
|
|
39
|
+
- Unused imports and variables are removed from the source; no public export, signature or behaviour changes.
|
|
40
|
+
|
|
41
|
+
## [0.1.0] - 2026-10-05
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- Original Falling Triplets, Colour Chains, Stone Collapse and Gem Swap engines with immutable state, seeded play, validated settings and canonical saves.
|
|
46
|
+
- 300 graded challenges and three bilingual lessons for each game.
|
|
47
|
+
- Family-style keyboard, keypad and touch demos, configurable boards, stored tools, goal progress and shared animation preferences.
|
|
48
|
+
- Optional Black Hole powers, Shizen magnetic stones with bounded rebound, and Arashi jumble and lightning schedules.
|
|
49
|
+
- An experimental Magnetic Blocks engine with bonded squares, magnetic floor schedules, a Floor Switch and impact drops.
|
|
50
|
+
- Typed entry points, a generated API reference, an MIT licence and reproducible package checks.
|
|
51
|
+
|
|
52
|
+
[Unreleased]: https://github.com/johnmorrisdotca/houseki/compare/v0.2.0...HEAD
|
|
53
|
+
[0.2.0]: https://github.com/johnmorrisdotca/houseki/compare/v0.1.1...v0.2.0
|
|
54
|
+
[0.1.1]: https://github.com/johnmorrisdotca/houseki/compare/v0.1.0...v0.1.1
|
|
55
|
+
[0.1.0]: https://github.com/johnmorrisdotca/houseki/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -1,80 +1,293 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">Houseki <sub>宝石</sub></h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center"><strong>Five original gem and stone puzzle games for JavaScript and TypeScript.</strong><br>
|
|
4
|
+
Falling Triplets, Colour Chains, Stone Collapse and Gem Swap: each an immutable, seeded rules engine that runs anywhere, with graded challenges and lessons, saves that replay to the same board, and a keyboard, keypad and touch player in the demo. Magnetic Blocks adds bonded squares, a magnetic floor and its own campaign. Shizen and Arashi each add a separate Colour Chains campaign. In English and Japanese. No dependencies.</p>
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://github.com/johnmorrisdotca/houseki/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/johnmorrisdotca/houseki/actions/workflows/ci.yml/badge.svg"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@johnmorrisdotca/houseki"><img alt="npm" src="https://img.shields.io/npm/v/@johnmorrisdotca/houseki?color=2f5d4a"></a>
|
|
9
|
+
<a href="./LICENSE"><img alt="MIT licence" src="https://img.shields.io/badge/licence-MIT-2f5d4a"></a>
|
|
10
|
+
<img alt="No dependencies" src="https://img.shields.io/badge/dependencies-0-2f5d4a">
|
|
11
|
+
<img alt="TypeScript" src="https://img.shields.io/badge/types-TypeScript-2f5d4a">
|
|
12
|
+
</p>
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
<p align="center"><a href="https://johnmorrisdotca.github.io/houseki/"><strong>Play a game →</strong></a> · <a href="https://johnmorrisdotca.github.io/houseki/api.html">API reference</a></p>
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
<p align="center">
|
|
17
|
+
<img src="docs/images/gem-swap-desktop.png" alt="Gem Swap on a full board in the demo: a grid of red, blue, green, gold, purple and teal gems with permanent symbols on them, the tool tray beside it with Bomb, Row clear and Colour clear, and the family's header above" width="620">
|
|
18
|
+
<img src="docs/images/tool-tray-phone.png" alt="The same tool tray on a phone, under the board" width="200">
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
Houseki is a set of match-style puzzle games made to be dropped into a page or a server. Every game is a set of plain functions on plain data: a state in, a new state out, nothing read from the page, the clock or the network. The demo's players draw those states, and a person can play them with the keyboard, a keypad or a finger.
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
## In 30 seconds
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
```sh
|
|
26
|
+
npm install @johnmorrisdotca/houseki
|
|
27
|
+
```
|
|
19
28
|
|
|
20
|
-
|
|
29
|
+
```ts
|
|
30
|
+
import { createGame, applyAction, advanceTicks } from "@johnmorrisdotca/houseki/falling-triplets";
|
|
31
|
+
|
|
32
|
+
let game = createGame({ mode: "relaxed", seed: "first-game" });
|
|
33
|
+
game = applyAction(game, { kind: "cycle-forward" }).state;
|
|
34
|
+
game = applyAction(game, { kind: "place" }).state;
|
|
35
|
+
game = advanceTicks(game, 22).state;
|
|
36
|
+
```
|
|
21
37
|
|
|
22
|
-
|
|
38
|
+
Every engine is a path of its own, and the main entry groups them by game:
|
|
23
39
|
|
|
24
|
-
|
|
40
|
+
```ts
|
|
41
|
+
import { colourChains } from "@johnmorrisdotca/houseki";
|
|
25
42
|
|
|
26
|
-
|
|
43
|
+
const firstChallenge = colourChains.createLevel(1);
|
|
44
|
+
const goal = firstChallenge.settings.goal;
|
|
45
|
+
```
|
|
27
46
|
|
|
28
|
-
|
|
47
|
+
Or straight from a page, with nothing to build:
|
|
29
48
|
|
|
30
|
-
|
|
49
|
+
```html
|
|
50
|
+
<script type="module">
|
|
51
|
+
import { createGame } from "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/houseki@0/dist/gem-swap.js";
|
|
52
|
+
const game = createGame({ seed: "hello" });
|
|
53
|
+
</script>
|
|
54
|
+
```
|
|
31
55
|
|
|
32
|
-
|
|
56
|
+
## Who it is for
|
|
33
57
|
|
|
34
|
-
|
|
58
|
+
- **Game and puzzle sites** that want match games with the rules already right: challenges everybody plays alike, a win that is witnessed, and saves that cannot drift.
|
|
59
|
+
- **Anyone who needs the rules without a screen**: a server that checks a finished game, a test that plays a campaign, a bot, a solver. Every engine is deterministic from its seed.
|
|
60
|
+
- **Teachers and parents**: nothing is timed against you in Relaxed play, every colour has its own permanent symbol, and every word is plain.
|
|
35
61
|
|
|
36
|
-
|
|
62
|
+
## Features
|
|
37
63
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
64
|
+
- **Five games**, each its own engine and its own entry point: [Falling Triplets](docs/design/01-FALLING-TRIPLETS.md), [Stone Collapse](docs/design/02-STONE-COLLAPSE.md), [Colour Chains](docs/design/03-COLOUR-CHAINS.md) [Gem Swap](docs/design/04-GEM-SWAP.md) and [Magnetic Blocks](docs/design/CAMPAIGN-EXTENSIONS.md).
|
|
65
|
+
- **Graded campaigns and lessons**: 100 Falling Triplets, 50 Colour Chains, 100 Stone Collapse, 50 Gem Swap, 50 Magnetic Blocks, 50 Shizen and 50 Arashi challenges (450 total), ordered by measured difficulty, each with a recorded winning play that the tests replay, and three guided lessons for each game. The boards are original, regenerated from a script, and a challenge keeps its identity if the order changes.
|
|
66
|
+
- **Three modes**: Relaxed (no clock, plan each move), Arcade (a timer drops the pieces) and Daily (the same board for everyone on a date).
|
|
67
|
+
- **Seeded and replayable**: a state is made from a seed and a list of actions, so a save is that list, and it decodes to exactly the board it came from.
|
|
68
|
+
- **Configurable boards**: presets from compact to extra wide and deep, custom sizes within stated limits, up to six colours, and shaped boards (heart, star, hexagon) for the full-board games.
|
|
69
|
+
- **Stored tools** for Gem Swap (Bomb, Row clear, Colour clear) and Stone Collapse (Bomb, Pick): select a tool and a stone, look at the highlighted effect, then confirm or cancel. A run that uses a tool is marked assisted. An optional earned Black Hole shrinks as it consumes nearby gems.
|
|
70
|
+
- **Nature, optional**: Shizen magnetic stones with one bounded rebound, and Arashi weather, a rare or frequent earthquake that jumbles stones and lightning that removes exposed ones, on a seeded schedule.
|
|
71
|
+
- **Magnetic Blocks**: bonded 2×2 squares, a floor that turns magnetic on a schedule, a one-use Floor Switch and impact drops. Its fifty challenges introduce Calm/Pull choices, planned floor schedules, the Floor Switch and impact drops.
|
|
72
|
+
- **Accessible**: permanent colour symbols, keyboard and keypad control, an Animation setting that is on by default and a reduced-motion choice that is respected.
|
|
73
|
+
- **Light and dark** that follow the device, in the demo's family look.
|
|
74
|
+
- **English and Japanese** words for every lesson, challenge, button and line of the demo.
|
|
75
|
+
- **Zero dependencies**, for the package and for the demo.
|
|
76
|
+
|
|
77
|
+
### The games
|
|
78
|
+
|
|
79
|
+
| Game | Entry | You | A match is | Challenges |
|
|
80
|
+
| --- | --- | --- | --- | --- |
|
|
81
|
+
| Falling Triplets | `falling-triplets` | cycle a falling vertical triplet and place it | a line of three, across, down or diagonal | 100 |
|
|
82
|
+
| Stone Collapse | `stone-collapse` | select a connected group and confirm | two or more touching stones of one colour | 100 |
|
|
83
|
+
| Colour Chains | `colour-chains` | rotate a falling pair | a group of four or more | 50 |
|
|
84
|
+
| Gem Swap | `gem-swap` | swap two neighbours | a run of three or more, which can make special gems | 50 |
|
|
85
|
+
| Magnetic Blocks | `magnetic-blocks` | rotate a falling 2×2 block | four connected gems, with Calm/Pull settling | 50 |
|
|
86
|
+
| Shizen | `colour-chains` | anticipate marked stones and rebound | four connected gems after attraction | 50 |
|
|
87
|
+
| Arashi | `colour-chains` | plan around earthquakes and lightning | four connected gems after weather | 50 |
|
|
88
|
+
|
|
89
|
+
## Use it in your project
|
|
90
|
+
|
|
91
|
+
Import a game directly from `@johnmorrisdotca/houseki/falling-triplets`, `@johnmorrisdotca/houseki/stone-collapse`, `@johnmorrisdotca/houseki/colour-chains`, `@johnmorrisdotca/houseki/gem-swap` or `@johnmorrisdotca/houseki/magnetic-blocks`, and the deterministic attraction, rebound and environment utilities from `@johnmorrisdotca/houseki/nature`. The main entry, `@johnmorrisdotca/houseki`, groups the same names as the namespaces `fallingTriplets`, `stoneCollapse`, `colourChains`, `gemSwap`, `nature` and `magneticBlocks`. The engines do not touch the DOM, storage or the network.
|
|
92
|
+
|
|
93
|
+
Every engine works the same way:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { createGame, createLevel, applyAction, advanceTicks, legalActions, encodeGame, decodeGame } from "@johnmorrisdotca/houseki/colour-chains";
|
|
97
|
+
|
|
98
|
+
const level = createLevel(1); // a graded challenge; createGame({ seed }) is a free game
|
|
99
|
+
const move = applyAction(level, { kind: "rotate-clockwise" });
|
|
100
|
+
move.accepted; // false when the action is not allowed
|
|
101
|
+
move.events; // what happened, in order, for a screen to animate
|
|
102
|
+
const later = advanceTicks(move.state, 30).state; // time is a count of ticks, never the clock
|
|
103
|
+
const saved = encodeGame(later); // a string; decodeGame(saved) is the same game again
|
|
43
104
|
```
|
|
44
105
|
|
|
45
|
-
|
|
106
|
+
Every function returns a new state and leaves the one it was given untouched. `legalActions(state)` lists what may be done now, so a bot or a test needs no knowledge of the rules. The two full-board games, Gem Swap and Stone Collapse, also have an undo and a hint (`undoGame` and `hintGame` in Gem Swap, `undo` and `requestHint` in Stone Collapse) and a restart; their stored tools are actions of their own.
|
|
107
|
+
|
|
108
|
+
To run the whole demo, `pnpm install && pnpm site`, then serve `site/` with any static server. A page of the demo takes `?seed=anything` in its address to start the same board again, and `?lang=ja` for Japanese.
|
|
46
109
|
|
|
47
|
-
|
|
110
|
+
### Additional campaigns
|
|
48
111
|
|
|
49
|
-
|
|
112
|
+

|
|
50
113
|
|
|
51
114
|
```ts
|
|
52
|
-
import {
|
|
115
|
+
import { createShizenLevel, createArashiLevel } from "@johnmorrisdotca/houseki/colour-chains";
|
|
116
|
+
import { createLevel } from "@johnmorrisdotca/houseki/magnetic-blocks";
|
|
53
117
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
game = advanceTicks(game, 22).state;
|
|
118
|
+
const magneticStones = createShizenLevel(1);
|
|
119
|
+
const weather = createArashiLevel(1);
|
|
120
|
+
const bondedSquares = createLevel(1);
|
|
58
121
|
```
|
|
59
122
|
|
|
60
|
-
|
|
123
|
+
Each campaign has fifty fixed puzzles ordered from easy to hard. Use its manifest for stable IDs, bilingual titles, objectives, difficulty marks and verified winning plans. Select Shizen or Arashi in the Colour Chains demo, or a challenge in Magnetic Blocks. A campaign uses a finite queue with no falling clock; the goal and progress appear beside the board. Fixed rules stay visible, and the result offers replay or the next challenge. See the [campaign contract](docs/design/CAMPAIGN-EXTENSIONS.md).
|
|
61
124
|
|
|
62
|
-
##
|
|
125
|
+
## API
|
|
63
126
|
|
|
64
|
-
[
|
|
127
|
+
Every export of every entry point is in the [API reference](https://johnmorrisdotca.github.io/houseki/api.html), made from the source when the demo is built, with each signature and doc comment. A test fails when a public export has no doc comment.
|
|
65
128
|
|
|
66
|
-
##
|
|
129
|
+
## Theming
|
|
67
130
|
|
|
68
|
-
|
|
131
|
+
The engines draw nothing. The demo's players take their colours from the family's stylesheet, `demo/family.css`: custom properties for the page, ink, accent and the felt the board sits on, which follow `prefers-color-scheme`, and five table cloths (green, blue, red, black and wood) chosen in the header. The boards add their own `--board`, `--frame` and `--gem-edge` in `demo/houseki.css`, and a Board material choice (ivory, slate or wood). Gems are told apart by their symbol as well as their colour, so no choice of cloth hides a colour.
|
|
69
132
|
|
|
70
|
-
##
|
|
133
|
+
## Limits
|
|
71
134
|
|
|
72
|
-
|
|
135
|
+
| What | Limit |
|
|
136
|
+
| --- | --- |
|
|
137
|
+
| Colours | 4 to 6 |
|
|
138
|
+
| Colour Chains | 5 to 16 columns and 12 to 32 visible rows |
|
|
139
|
+
| Magnetic Blocks | 4 to 16 columns and 4 to 32 rows; at most 200 pieces in the demo |
|
|
140
|
+
| Stone Collapse | presets from 6×8 to 16×10 and 8×32 deep; shaped boards by mask |
|
|
141
|
+
| Daily mode | the standard board and colour count only, from a date |
|
|
142
|
+
| Saves | a replay of the actions taken, checked when it is decoded; a save that does not match its own record is refused |
|
|
143
|
+
| Tools | capped inventory, earned by ordinary clears, and not offered in Daily or in authored challenges |
|
|
73
144
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
145
|
+
## Browser support
|
|
146
|
+
|
|
147
|
+
The engines run wherever JavaScript does: Node 22 or later, and current Chrome, Edge, Firefox and Safari. The demo's tests run in Chromium and WebKit, at a phone's width and a desk's.
|
|
148
|
+
|
|
149
|
+
## Languages
|
|
150
|
+
|
|
151
|
+
The demo is in English and Japanese: every lesson and challenge title, button, status line and the family's header and footer. The Japanese has not yet been read by a native reader: corrections are welcome as a *Fix a translation* issue.
|
|
152
|
+
|
|
153
|
+
## Roadmap
|
|
154
|
+
|
|
155
|
+
Physical-device feel testing, a fluent Japanese review and human difficulty review of the campaigns are next, and new techniques for later campaigns. [docs/COVERAGE.md](docs/COVERAGE.md) says what is verified by tests and what is not. Nothing here is promised for a date.
|
|
156
|
+
|
|
157
|
+
## Architecture
|
|
158
|
+
|
|
159
|
+
```text
|
|
160
|
+
src/
|
|
161
|
+
├── colour-chains/
|
|
162
|
+
│ ├── challenge.ts
|
|
163
|
+
│ ├── content-data.ts
|
|
164
|
+
│ ├── content-types.ts
|
|
165
|
+
│ ├── content.ts
|
|
166
|
+
│ ├── engine.ts
|
|
167
|
+
│ ├── input.ts
|
|
168
|
+
│ ├── match.ts
|
|
169
|
+
│ ├── persistence.ts
|
|
170
|
+
│ ├── random.ts
|
|
171
|
+
│ ├── types.ts
|
|
172
|
+
│ └── validation.ts
|
|
173
|
+
├── colour-chains.ts
|
|
174
|
+
├── falling-triplets/
|
|
175
|
+
│ ├── content-data.ts
|
|
176
|
+
│ ├── content-types.ts
|
|
177
|
+
│ ├── content.ts
|
|
178
|
+
│ ├── engine.ts
|
|
179
|
+
│ ├── input.ts
|
|
180
|
+
│ ├── match.ts
|
|
181
|
+
│ ├── random.ts
|
|
182
|
+
│ └── types.ts
|
|
183
|
+
├── falling-triplets.ts
|
|
184
|
+
├── gem-swap/
|
|
185
|
+
│ ├── black-hole.ts
|
|
186
|
+
│ ├── board.ts
|
|
187
|
+
│ ├── content.ts
|
|
188
|
+
│ ├── engine.ts
|
|
189
|
+
│ ├── persistence.ts
|
|
190
|
+
│ ├── practice.ts
|
|
191
|
+
│ ├── random.ts
|
|
192
|
+
│ ├── specials.ts
|
|
193
|
+
│ ├── tools.ts
|
|
194
|
+
│ └── types.ts
|
|
195
|
+
├── gem-swap.ts
|
|
196
|
+
├── index.ts
|
|
197
|
+
├── magnetic-blocks/
|
|
198
|
+
│ ├── content-data.ts
|
|
199
|
+
│ ├── content-types.ts
|
|
200
|
+
│ ├── content.ts
|
|
201
|
+
│ ├── engine.ts
|
|
202
|
+
│ ├── persistence.ts
|
|
203
|
+
│ ├── physics.ts
|
|
204
|
+
│ ├── random.ts
|
|
205
|
+
│ ├── types.ts
|
|
206
|
+
│ └── validation.ts
|
|
207
|
+
├── magnetic-blocks.ts
|
|
208
|
+
├── nature/
|
|
209
|
+
│ ├── attraction.ts
|
|
210
|
+
│ ├── environment.ts
|
|
211
|
+
│ ├── marking.ts
|
|
212
|
+
│ ├── random.ts
|
|
213
|
+
│ ├── rebound.ts
|
|
214
|
+
│ ├── state.ts
|
|
215
|
+
│ ├── types.ts
|
|
216
|
+
│ └── validation.ts
|
|
217
|
+
├── nature.ts
|
|
218
|
+
├── stone-collapse/
|
|
219
|
+
│ ├── content-data.ts
|
|
220
|
+
│ ├── content-types.ts
|
|
221
|
+
│ ├── content.ts
|
|
222
|
+
│ ├── engine.ts
|
|
223
|
+
│ ├── persistence.ts
|
|
224
|
+
│ ├── types.ts
|
|
225
|
+
│ └── validation.ts
|
|
226
|
+
└── stone-collapse.ts
|
|
78
227
|
```
|
|
79
228
|
|
|
80
|
-
|
|
229
|
+
The [design pack](docs/design/README.md) specifies the rules, controls, materials, accessibility, level generation, grading, persistence and acceptance checks of every game; [level generation](docs/design/LEVEL-GENERATION.md) follows a deliberate complete count: generate and prove original boards, remove duplicates, grade the decisions a player faces, then sort and number from easy to hard.
|
|
230
|
+
|
|
231
|
+
## The name
|
|
232
|
+
|
|
233
|
+
Houseki (宝石) is Japanese for a gem or precious stone: the pieces of these games are cut and polished, and the games are small.
|
|
234
|
+
|
|
235
|
+
## Where it comes from
|
|
236
|
+
|
|
237
|
+
Match games are an old family and their rules are common property. These five are original: the rules are written out in the design pack in our own words, every board is generated and checked by the repository's own scripts, and the pictures are drawn in code. No art, sound or level comes from another game.
|
|
238
|
+
|
|
239
|
+
### The family
|
|
240
|
+
|
|
241
|
+
<!-- family:start (made by scripts/family-readme.mjs from scripts/family-template.mjs; change those, not this) -->
|
|
242
|
+
Houseki is one of twenty-four packages, each made for the same site, each at
|
|
243
|
+
[github.com/johnmorrisdotca](https://github.com/johnmorrisdotca). The code of every one is MIT.
|
|
244
|
+
|
|
245
|
+
- [Korokoro](https://github.com/johnmorrisdotca/korokoro) (コロコロ): dice, with notation, exact odds, real sounds and the dice of many games. [Demo](https://johnmorrisdotca.github.io/korokoro/).
|
|
246
|
+
- [Kyuubu](https://github.com/johnmorrisdotca/kyuubu) (キューブ): a turning cube for the browser, 2×2 to 7×7, with record solves to replay. [Demo](https://johnmorrisdotca.github.io/kyuubu/).
|
|
247
|
+
- [Hitotsu](https://github.com/johnmorrisdotca/hitotsu) (一つ): a colour-card shedding game for two to eight, with the house rules people play. [Demo](https://johnmorrisdotca.github.io/hitotsu/).
|
|
248
|
+
- [Toranpu](https://github.com/johnmorrisdotca/toranpu) (トランプ): a deck of playing cards, card games with computer players, and solitaires. [Demo](https://johnmorrisdotca.github.io/toranpu/).
|
|
249
|
+
- [Tane](https://github.com/johnmorrisdotca/tane) (種): seeded random numbers and daily seeds, the same in every browser and on every server. [Demo](https://johnmorrisdotca.github.io/tane/).
|
|
250
|
+
- [Narabe](https://github.com/johnmorrisdotca/narabe) (並べ): one rules engine for abstract board games, from gomoku and Reversi to Go and checkers. [Demo](https://johnmorrisdotca.github.io/narabe/).
|
|
251
|
+
- [Tenka](https://github.com/johnmorrisdotca/tenka) (天下): world conquest for two to six, on a map of the real world. [Demo](https://johnmorrisdotca.github.io/tenka/).
|
|
252
|
+
- [Kumimoji](https://github.com/johnmorrisdotca/kumimoji) (組み文字): a crossword tile race, in English and Japanese kana. [Demo](https://johnmorrisdotca.github.io/kumimoji/).
|
|
253
|
+
- [Tsunagi](https://github.com/johnmorrisdotca/tsunagi) (繋ぎ): a line-joining logic puzzle whose every level has exactly one answer. [Demo](https://johnmorrisdotca.github.io/tsunagi/).
|
|
254
|
+
- [Jarajara](https://github.com/johnmorrisdotca/jarajara) (ジャラジャラ): mahjong tiles drawn as SVG, stacked layouts, and the matching solitaire Awase. [Demo](https://johnmorrisdotca.github.io/jarajara/).
|
|
255
|
+
- [Suido](https://github.com/johnmorrisdotca/suido) (水道): a pipe puzzle: turn the pieces until the water reaches every drain. [Demo](https://johnmorrisdotca.github.io/suido/).
|
|
256
|
+
- [Domino](https://github.com/johnmorrisdotca/domino) (ドミノ): dominoes and Mexican Train. [Demo](https://johnmorrisdotca.github.io/domino/).
|
|
257
|
+
- [Kotoba](https://github.com/johnmorrisdotca/kotoba) (言葉): word lists and word-game rules in English, French, German and Japanese. [Demo](https://johnmorrisdotca.github.io/kotoba/).
|
|
258
|
+
- [Sugoroku](https://github.com/johnmorrisdotca/sugoroku) (双六): backgammon and its variants, with the doubling cube and match play. [Demo](https://johnmorrisdotca.github.io/sugoroku/).
|
|
259
|
+
- [Kazu](https://github.com/johnmorrisdotca/kazu) (数): grid number puzzles: Sudoku and its variants, Futoshiki and Skyscrapers. [Demo](https://johnmorrisdotca.github.io/kazu/).
|
|
260
|
+
- [Meikyuu](https://github.com/johnmorrisdotca/meikyuu) (迷宮): mazes on squares, hexagons, triangles and circles, made from a seed and drawn through with a finger or the mouse. [Demo](https://johnmorrisdotca.github.io/meikyuu/).
|
|
261
|
+
- [Hikidashi](https://github.com/johnmorrisdotca/hikidashi) (引き出し): a drawer of small Japanese text tools: era dates, kanji numerals, readings and sentence difficulty. [Demo](https://johnmorrisdotca.github.io/hikidashi/).
|
|
262
|
+
- [Chizu](https://github.com/johnmorrisdotca/chizu) (地図): maps of the world and of countries' regions, in English and Japanese, with a quiz and callouts. [Demo](https://johnmorrisdotca.github.io/chizu/).
|
|
263
|
+
- [Bushu](https://github.com/johnmorrisdotca/bushu) (部首): find a kanji by the parts it is made of. [Demo](https://johnmorrisdotca.github.io/bushu/).
|
|
264
|
+
- [Tobiishi](https://github.com/johnmorrisdotca/tobiishi) (飛び石): peg solitaire with nine boards and seeded solvable challenges. [Demo](https://johnmorrisdotca.github.io/tobiishi/).
|
|
265
|
+
- [Jirai](https://github.com/johnmorrisdotca/jirai) (地雷): minesweeper on shaped grids with verified no-guess boards. [Demo](https://johnmorrisdotca.github.io/jirai/).
|
|
266
|
+
- [Gunjin](https://github.com/johnmorrisdotca/gunjin) (軍人): five hidden-rank strategy games with pass-the-device play. [Demo](https://johnmorrisdotca.github.io/gunjin/).
|
|
267
|
+
- [Karakuri](https://github.com/johnmorrisdotca/karakuri) (からくり): eight hyper-casual puzzle games, some of them physics: draw a shield, pull pins, cut ropes, slide blocks, pour tubes. [Demo](https://johnmorrisdotca.github.io/karakuri/).
|
|
268
|
+
- [Houseki](https://github.com/johnmorrisdotca/houseki) (宝石): gem and stone matching puzzles: falling triplets, stone collapse, colour chains and gem swap. [Demo](https://johnmorrisdotca.github.io/houseki/).
|
|
269
|
+
|
|
270
|
+
**This package is Houseki.** The demos of all twenty-four share one header and footer, so each links the rest.
|
|
271
|
+
<!-- family:end -->
|
|
272
|
+
|
|
273
|
+
## Development
|
|
274
|
+
|
|
275
|
+
```sh
|
|
276
|
+
pnpm install
|
|
277
|
+
pnpm check # lint, types and tests: every game's rules, every campaign's recorded wins
|
|
278
|
+
pnpm test:package # pack it as npm does, install it in an empty project, import every entry
|
|
279
|
+
pnpm test:demo # build the demo and play it in a real browser, at a phone's width and a desk's
|
|
280
|
+
pnpm site # build the demo and the API reference into site/
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Contributing
|
|
284
|
+
|
|
285
|
+
Ideas, bug reports and pull requests are welcome in the [issues](https://github.com/johnmorrisdotca/houseki/issues). See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
286
|
+
|
|
287
|
+
## Changes
|
|
288
|
+
|
|
289
|
+
Every release is written up in [CHANGELOG.md](./CHANGELOG.md).
|
|
290
|
+
|
|
291
|
+
## Licence
|
|
292
|
+
|
|
293
|
+
[MIT](./LICENSE) © John Morris. The code, the boards and the words are all the package's own. Report vulnerabilities through [SECURITY.md](./SECURITY.md).
|
|
@@ -61,7 +61,7 @@ function solveWitness(start, witness) {
|
|
|
61
61
|
export function createChallenge(options) {
|
|
62
62
|
if (!options || typeof options !== 'object' || Array.isArray(options))
|
|
63
63
|
throw new StoneChainsOptionsError('invalid-challenge', 'Challenge options must be an object');
|
|
64
|
-
const allowed = ['id', 'width', 'height', 'colourCount', 'seed', 'board', 'queue', 'goal', 'witness'];
|
|
64
|
+
const allowed = ['id', 'width', 'height', 'colourCount', 'seed', 'board', 'queue', 'magneticQueue', 'nature', 'weather', 'goal', 'witness'];
|
|
65
65
|
if (Object.keys(options).some(key => !allowed.includes(key)))
|
|
66
66
|
throw new StoneChainsOptionsError('unknown-challenge-option', 'Challenge options contain unsupported fields');
|
|
67
67
|
if (typeof options.id !== 'string' || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(options.id))
|
|
@@ -75,6 +75,14 @@ export function createChallenge(options) {
|
|
|
75
75
|
const seed = options.seed ?? `challenge:${options.id}`;
|
|
76
76
|
if (typeof seed !== 'string' || seed.length < 1 || seed.length > 200)
|
|
77
77
|
throw new StoneChainsOptionsError('invalid-seed', 'Seed must contain 1–200 characters');
|
|
78
|
+
if (options.nature !== undefined && typeof options.nature !== 'boolean')
|
|
79
|
+
throw new StoneChainsOptionsError('invalid-nature-option', 'nature must be a boolean');
|
|
80
|
+
if (options.weather !== undefined && options.weather !== 'frequent' && options.weather !== 'rare')
|
|
81
|
+
throw new StoneChainsOptionsError('invalid-weather-option', 'weather must be frequent or rare');
|
|
82
|
+
if (options.weather !== undefined && options.nature !== true)
|
|
83
|
+
throw new StoneChainsOptionsError('weather-requires-nature', 'Arashi weather requires nature:true');
|
|
84
|
+
if (options.magneticQueue !== undefined && options.nature !== true)
|
|
85
|
+
throw new StoneChainsOptionsError('magnetic-queue-requires-nature', 'Magnetic queue flags require nature:true');
|
|
78
86
|
if (!Array.isArray(options.board) || options.board.length !== width * height)
|
|
79
87
|
throw new StoneChainsOptionsError('invalid-challenge-board', 'Challenge board must contain width × height visible cells');
|
|
80
88
|
if (!Array.isArray(options.queue) || options.queue.length < 2 || options.queue.length > 12)
|
|
@@ -84,10 +92,10 @@ export function createChallenge(options) {
|
|
|
84
92
|
const board = options.board.map((gem, index) => {
|
|
85
93
|
if (gem === null)
|
|
86
94
|
return null;
|
|
87
|
-
if (!gem || typeof gem !== 'object' || Array.isArray(gem) || Object.keys(gem).some(key => key !== 'id' && key !== 'colour') || !Number.isSafeInteger(gem.id) || gem.id < 1 || gem.id > 0x7fff_ffff || ids.has(gem.id) || !allowedColours.includes(gem.colour))
|
|
95
|
+
if (!gem || typeof gem !== 'object' || Array.isArray(gem) || Object.keys(gem).some(key => key !== 'id' && key !== 'colour' && key !== 'magnetic') || !Number.isSafeInteger(gem.id) || gem.id < 1 || gem.id > 0x7fff_ffff || ids.has(gem.id) || !allowedColours.includes(gem.colour) || gem.magnetic !== undefined && (gem.magnetic !== true || options.nature !== true))
|
|
88
96
|
throw new StoneChainsOptionsError('invalid-challenge-gem', `Invalid challenge gem at cell ${index}`);
|
|
89
97
|
ids.add(gem.id);
|
|
90
|
-
return Object.freeze({ id: gem.id, colour: gem.colour });
|
|
98
|
+
return Object.freeze({ id: gem.id, colour: gem.colour, ...(gem.magnetic ? { magnetic: true } : {}) });
|
|
91
99
|
});
|
|
92
100
|
for (let x = 0; x < width; x++) {
|
|
93
101
|
let gap = false;
|
|
@@ -103,6 +111,12 @@ export function createChallenge(options) {
|
|
|
103
111
|
throw new StoneChainsOptionsError('invalid-challenge-pair', `Invalid queue pair ${index + 1}`);
|
|
104
112
|
return Object.freeze([pair[0], pair[1]]);
|
|
105
113
|
});
|
|
114
|
+
let magneticQueue;
|
|
115
|
+
if (options.magneticQueue !== undefined) {
|
|
116
|
+
if (!Array.isArray(options.magneticQueue) || options.magneticQueue.length !== queue.length || options.magneticQueue.some(pair => !Array.isArray(pair) || pair.length !== 2 || pair.some(flag => typeof flag !== 'boolean')))
|
|
117
|
+
throw new StoneChainsOptionsError('invalid-magnetic-queue', 'Magnetic queue must contain one pair of boolean flags per finite queue pair');
|
|
118
|
+
magneticQueue = Object.freeze(options.magneticQueue.map(pair => Object.freeze([pair[0], pair[1]])));
|
|
119
|
+
}
|
|
106
120
|
const goal = validateChallengeGoal(options.goal, ids);
|
|
107
121
|
if (!Array.isArray(options.witness) || options.witness.length < 1 || options.witness.length > queue.length)
|
|
108
122
|
throw new StoneChainsOptionsError('invalid-witness', 'A challenge requires a complete witness of 1–12 pair placements');
|
|
@@ -111,7 +125,7 @@ export function createChallenge(options) {
|
|
|
111
125
|
throw new StoneChainsOptionsError('invalid-witness-step', `Invalid witness placement ${index + 1}`);
|
|
112
126
|
return Object.freeze({ pivotX: step.pivotX, orientation: step.orientation });
|
|
113
127
|
});
|
|
114
|
-
const settings = Object.freeze({ mode: 'challenge', width, height, colourCount, seed, challengeId: options.id, goal, initialBoard: Object.freeze(board), queue: Object.freeze(queue), witness: Object.freeze(witness) });
|
|
128
|
+
const settings = Object.freeze({ mode: 'challenge', width, height, colourCount, seed, challengeId: options.id, goal, initialBoard: Object.freeze(board), queue: Object.freeze(queue), ...(magneticQueue ? { magneticQueue } : {}), ...(options.nature ? { nature: true } : {}), ...(options.weather ? { weather: options.weather } : {}), witness: Object.freeze(witness) });
|
|
115
129
|
const state = initialChallengeState(settings, settings.initialBoard, settings.queue);
|
|
116
130
|
const solved = solveWitness(state, witness);
|
|
117
131
|
if (solved.phase !== 'won' || stable(solved.settings) !== stable(settings))
|