Add private Primordial Soup playtest with engine and interactive lessons
This commit is contained in:
commit
be2b5e293c
27 changed files with 6045 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
node_modules/
|
||||
dist/
|
||||
*.tgz
|
||||
.local/
|
||||
28
README.md
Normal file
28
README.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Primordial Soup — private BGS playtest
|
||||
|
||||
An original vector-art web adaptation of Doris Matthäus and Frank Nestel's base game, for 3–4 colonies. It includes a server-authoritative engine, practice bots, and ten interactive English lessons using the ordinary board controls.
|
||||
|
||||
```sh
|
||||
pnpm install
|
||||
pnpm build
|
||||
pnpm test
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
Local practice: http://127.0.0.1:5221/ . Lessons start at `/?chapter=drift`.
|
||||
|
||||
## Rules and playtest limits
|
||||
|
||||
Rules: [Z-Man English rulebook](https://cs.uwaterloo.ca/~dtompkin/archive/dtlib/base/Primordial%20Soup.pdf), [publisher's reference sheets](http://doris-frank.de/download/Ursuppe_Rules.pdf), and [publisher FAQ](http://doris-frank.de/UrsuppeFAQ.html).
|
||||
|
||||
The engine implements all six phases, finite food and genes, the twenty base-game gene effects, interruptions for Holding and combat, and scoring/end conditions. Gene quantities follow the publisher's revised reference table; its total differs from the rulebook's component count and should be checked against a physical set.
|
||||
|
||||
**The environment-card manifest in `engine/catalog.js` is provisional.** The rulebook does not list all eleven ozone/direction pairs. The photographed 8/east and 12/west cards are matched, but the remaining distribution is not verified. This affects full-game probabilities; tutorials use explicit prepared environments. Confirm against all eleven printed cards before a public release. This limitation is also shown in the in-game rules.
|
||||
|
||||
No expansion genes are included. The bots are practice opponents, not a competitive AI.
|
||||
|
||||
## Publication
|
||||
|
||||
BGS entry: `primordial-soup`, version 1. Keep `public: false`, metadata `unlisted: true`, and restrict beta access. The private engine is uploaded as an npm-pack tarball to BGS storage; it is not published to npm. The original rules PDF is hosted as a separate BGS asset and linked from the rules panel.
|
||||
|
||||
Artwork is newly drawn SVG, not scans. Bundled fonts retain their OFL notices in `viewer/assets/`.
|
||||
230
engine/catalog.js
Normal file
230
engine/catalog.js
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
export const COLORS = ["green", "red", "blue", "yellow"];
|
||||
export const COLOR_NAMES = ["Green", "Coral", "Blue", "Gold"];
|
||||
export const CELLS = Array.from({ length: 25 }, (_, i) => i).filter(
|
||||
(i) => ![0, 4, 5, 10, 12, 20].includes(i),
|
||||
);
|
||||
export const DIRECTIONS = ["West", "North", "East", "South", "Still"];
|
||||
export const PHASES = [
|
||||
"Movement & feeding",
|
||||
"Environment",
|
||||
"New genes",
|
||||
"Cell division",
|
||||
"Survival",
|
||||
"Evolution",
|
||||
];
|
||||
export const coordinate = (cell) =>
|
||||
`${"ABCDE"[cell % 5]}${Math.floor(cell / 5) + 1}`;
|
||||
export function destination(cell, direction) {
|
||||
const [dx, dy] = [
|
||||
[-1, 0],
|
||||
[0, -1],
|
||||
[1, 0],
|
||||
[0, 1],
|
||||
[0, 0],
|
||||
][direction];
|
||||
const x = (cell % 5) + dx,
|
||||
y = Math.floor(cell / 5) + dy,
|
||||
next = y * 5 + x;
|
||||
return x >= 0 && x < 5 && y >= 0 && y < 5 && CELLS.includes(next)
|
||||
? next
|
||||
: cell;
|
||||
}
|
||||
export const adjacent = (cell) =>
|
||||
[...new Set([0, 1, 2, 3].map((d) => destination(cell, d)))].filter(
|
||||
(x) => x !== cell,
|
||||
);
|
||||
const gene = (id, name, cost, mutation, copies, text, base = []) => ({
|
||||
id,
|
||||
name,
|
||||
cost,
|
||||
mutation,
|
||||
copies,
|
||||
text,
|
||||
base,
|
||||
points: base.length ? 2 : id === "ray" ? 0 : 1,
|
||||
});
|
||||
export const GENES = [
|
||||
gene(
|
||||
"intelligence",
|
||||
"Intelligence",
|
||||
2,
|
||||
3,
|
||||
[1, 2],
|
||||
"No special action, but counts as a gene for evolution.",
|
||||
),
|
||||
gene(
|
||||
"movement1",
|
||||
"Movement I",
|
||||
3,
|
||||
2,
|
||||
[2, 2],
|
||||
"Roll two dice when swimming and choose either result. Swimming still costs 1 BP.",
|
||||
),
|
||||
gene(
|
||||
"spores",
|
||||
"Spores",
|
||||
3,
|
||||
3,
|
||||
[1, 1],
|
||||
"Place new amoebas anywhere without another amoeba of your colour.",
|
||||
),
|
||||
gene(
|
||||
"speed",
|
||||
"Speed",
|
||||
4,
|
||||
3,
|
||||
[1, 2],
|
||||
"After swimming, you may swim a second time for free. Roll again, then feed once after both moves. Does not apply to drift.",
|
||||
),
|
||||
gene(
|
||||
"defense",
|
||||
"Defense",
|
||||
4,
|
||||
4,
|
||||
[1, 1],
|
||||
"When attacked, spend 1 BP to fight. Each side rolls a die; higher wins, ties are rerolled. A successful defense stops the attack.",
|
||||
),
|
||||
gene(
|
||||
"escape",
|
||||
"Escape",
|
||||
4,
|
||||
4,
|
||||
[1, 2],
|
||||
"When attacked, you may swim away for 1 BP using your movement genes. Reaching another space avoids the attack.",
|
||||
),
|
||||
gene(
|
||||
"substitution",
|
||||
"Substitution",
|
||||
4,
|
||||
4,
|
||||
[1, 1],
|
||||
"Replace a missing colour by eating one extra cube: two of each of two colours in a four-player game, or four of one colour in a three-player game.",
|
||||
),
|
||||
gene(
|
||||
"ray",
|
||||
"Ray Protection",
|
||||
5,
|
||||
-2,
|
||||
[1, 2],
|
||||
"Reduces total mutation sensitivity by 2. Does not count as a gene when scoring evolution.",
|
||||
),
|
||||
gene(
|
||||
"streamline",
|
||||
"Streamline",
|
||||
5,
|
||||
4,
|
||||
[1, 1],
|
||||
"Swimming and escaping cost no BP. Dice still determine movement unless you have Movement II.",
|
||||
),
|
||||
gene(
|
||||
"tentacle",
|
||||
"Tentacle",
|
||||
5,
|
||||
4,
|
||||
[1, 2],
|
||||
"Carry up to two food cubes when moving with three players, or three cubes with four players. You may take any colour, including your own.",
|
||||
),
|
||||
gene(
|
||||
"holding",
|
||||
"Holding",
|
||||
5,
|
||||
4,
|
||||
[1, 1],
|
||||
"You may stay instead of drifting. When another amoeba leaves your space, your amoebas may travel with it for free.",
|
||||
),
|
||||
gene(
|
||||
"longevity",
|
||||
"Longevity",
|
||||
5,
|
||||
5,
|
||||
[1, 2],
|
||||
"Your amoebas die with three injuries instead of two during the survival phase.",
|
||||
),
|
||||
gene(
|
||||
"frugality",
|
||||
"Frugality",
|
||||
6,
|
||||
5,
|
||||
[0, 1],
|
||||
"Eat one fewer food cube. Still leave two cubes of your own colour after feeding.",
|
||||
),
|
||||
gene(
|
||||
"struggle",
|
||||
"Struggle for Survival",
|
||||
6,
|
||||
4,
|
||||
[2, 2],
|
||||
"If you cannot feed, spend 1 BP to attack an amoeba in your space. A successful attack feeds you and leaves one cube of each colour.",
|
||||
),
|
||||
gene(
|
||||
"parasitism",
|
||||
"Parasitism",
|
||||
6,
|
||||
5,
|
||||
[0, 1],
|
||||
"Share a space with an opponent who has BP: make them pay 1 BP to eat one fewer food cube. You may use this even when enough food is available.",
|
||||
),
|
||||
gene(
|
||||
"division",
|
||||
"Division Rate",
|
||||
6,
|
||||
5,
|
||||
[1, 2],
|
||||
"New amoebas cost 4 BP instead of 6 BP.",
|
||||
),
|
||||
gene(
|
||||
"persistence",
|
||||
"Persistence",
|
||||
4,
|
||||
4,
|
||||
[1, 2],
|
||||
"After a failed attack or defense, you may make a second attempt for free. Replaces Speed; it does not keep Speed's extra swim.",
|
||||
["speed"],
|
||||
),
|
||||
gene(
|
||||
"movement2",
|
||||
"Movement II",
|
||||
5,
|
||||
5,
|
||||
[1, 2],
|
||||
"Choose a direction when swimming instead of rolling. Swimming still costs 1 BP unless you also have Streamline.",
|
||||
["movement1"],
|
||||
),
|
||||
gene(
|
||||
"aggression",
|
||||
"Aggression",
|
||||
5,
|
||||
5,
|
||||
[1, 1],
|
||||
"After natural deaths, attack one opponent in the same space for 1 BP, once per round. Still allows attacking instead of starving. Armor converts the survival-phase attack to one injury.",
|
||||
["struggle"],
|
||||
),
|
||||
gene(
|
||||
"armor",
|
||||
"Armor",
|
||||
6,
|
||||
6,
|
||||
[1, 1],
|
||||
"Cannot be eaten by Struggle for Survival. Aggression causes one injury instead of immediate death.",
|
||||
["defense", "escape"],
|
||||
),
|
||||
];
|
||||
export const GENE = Object.fromEntries(GENES.map((g) => [g.id, g]));
|
||||
export const populationPoints = (n) => [0, 0, 0, 1, 2, 4, 5, 6][n];
|
||||
export const genePoints = (n) => Math.min(4, Math.max(0, n - 2));
|
||||
|
||||
// Private playtest deck: exact printed card distribution is still awaiting verification.
|
||||
// Keep this separate from movement rules; see README.md.
|
||||
export const ENVIRONMENTS = [
|
||||
{ ozone: 6, direction: 2 },
|
||||
{ ozone: 7, direction: 0 },
|
||||
{ ozone: 8, direction: 2 },
|
||||
{ ozone: 8, direction: 3 },
|
||||
{ ozone: 9, direction: 2 },
|
||||
{ ozone: 10, direction: 4 },
|
||||
{ ozone: 11, direction: 0 },
|
||||
{ ozone: 12, direction: 0 },
|
||||
{ ozone: 12, direction: 3 },
|
||||
{ ozone: 13, direction: 2 },
|
||||
{ ozone: 14, direction: 0 },
|
||||
];
|
||||
1001
engine/index.js
Normal file
1001
engine/index.js
Normal file
File diff suppressed because it is too large
Load diff
23
package.json
Normal file
23
package.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "@boardgamers/primordial-soup",
|
||||
"version": "0.1.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist/engine.js",
|
||||
"files": [
|
||||
"dist/engine.js"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "node scripts/build.mjs",
|
||||
"test": "node --test test/*.test.js",
|
||||
"dev": "node scripts/dev.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.3.3",
|
||||
"@noble/hashes": "2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "0.25.12",
|
||||
"prettier": "3.6.2"
|
||||
}
|
||||
}
|
||||
320
pnpm-lock.yaml
generated
Normal file
320
pnpm-lock.yaml
generated
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
lockfileVersion: '9.0'
|
||||
|
||||
settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
'@boardgamers/protocol':
|
||||
specifier: 0.3.3
|
||||
version: 0.3.3
|
||||
'@noble/hashes':
|
||||
specifier: 2.0.1
|
||||
version: 2.0.1
|
||||
devDependencies:
|
||||
esbuild:
|
||||
specifier: 0.25.12
|
||||
version: 0.25.12
|
||||
prettier:
|
||||
specifier: 3.6.2
|
||||
version: 3.6.2
|
||||
|
||||
packages:
|
||||
|
||||
'@boardgamers/protocol@0.3.3':
|
||||
resolution: {integrity: sha512-AS+x84WHXRudW6xt/s/5I3xYmNTQFbZEBp3V+41w0I2RirSr2fWjYnYf0p11nwTbZ6G5upivKz/sjYLtk8HOYA==}
|
||||
|
||||
'@esbuild/aix-ppc64@0.25.12':
|
||||
resolution: {integrity: sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [ppc64]
|
||||
os: [aix]
|
||||
|
||||
'@esbuild/android-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [android]
|
||||
|
||||
'@esbuild/android-arm@0.25.12':
|
||||
resolution: {integrity: sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm]
|
||||
os: [android]
|
||||
|
||||
'@esbuild/android-x64@0.25.12':
|
||||
resolution: {integrity: sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [android]
|
||||
|
||||
'@esbuild/darwin-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@esbuild/darwin-x64@0.25.12':
|
||||
resolution: {integrity: sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@esbuild/freebsd-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [freebsd]
|
||||
|
||||
'@esbuild/freebsd-x64@0.25.12':
|
||||
resolution: {integrity: sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [freebsd]
|
||||
|
||||
'@esbuild/linux-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-arm@0.25.12':
|
||||
resolution: {integrity: sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-ia32@0.25.12':
|
||||
resolution: {integrity: sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [ia32]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-loong64@0.25.12':
|
||||
resolution: {integrity: sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [loong64]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-mips64el@0.25.12':
|
||||
resolution: {integrity: sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [mips64el]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-ppc64@0.25.12':
|
||||
resolution: {integrity: sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [ppc64]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-riscv64@0.25.12':
|
||||
resolution: {integrity: sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-s390x@0.25.12':
|
||||
resolution: {integrity: sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [s390x]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/linux-x64@0.25.12':
|
||||
resolution: {integrity: sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@esbuild/netbsd-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [netbsd]
|
||||
|
||||
'@esbuild/netbsd-x64@0.25.12':
|
||||
resolution: {integrity: sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [netbsd]
|
||||
|
||||
'@esbuild/openbsd-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [openbsd]
|
||||
|
||||
'@esbuild/openbsd-x64@0.25.12':
|
||||
resolution: {integrity: sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [openbsd]
|
||||
|
||||
'@esbuild/openharmony-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [openharmony]
|
||||
|
||||
'@esbuild/sunos-x64@0.25.12':
|
||||
resolution: {integrity: sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [sunos]
|
||||
|
||||
'@esbuild/win32-arm64@0.25.12':
|
||||
resolution: {integrity: sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [arm64]
|
||||
os: [win32]
|
||||
|
||||
'@esbuild/win32-ia32@0.25.12':
|
||||
resolution: {integrity: sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [ia32]
|
||||
os: [win32]
|
||||
|
||||
'@esbuild/win32-x64@0.25.12':
|
||||
resolution: {integrity: sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==}
|
||||
engines: {node: '>=18'}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
'@noble/hashes@2.0.1':
|
||||
resolution: {integrity: sha512-XlOlEbQcE9fmuXxrVTXCTlG2nlRXa9Rj3rr5Ue/+tX+nmkgbX720YHh0VR3hBF9xDvwnb8D2shVGOwNx+ulArw==}
|
||||
engines: {node: '>= 20.19.0'}
|
||||
|
||||
esbuild@0.25.12:
|
||||
resolution: {integrity: sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==}
|
||||
engines: {node: '>=18'}
|
||||
hasBin: true
|
||||
|
||||
prettier@3.6.2:
|
||||
resolution: {integrity: sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==}
|
||||
engines: {node: '>=14'}
|
||||
hasBin: true
|
||||
|
||||
zod@4.6.5:
|
||||
resolution: {integrity: sha512-v5l/aFXZQeai4awLbOpSoHecE9UiMrnfx75tEXLjNonXVARxQ5mOeipTjROUchszUNCqnE+hqAMujRsRHsut2Q==}
|
||||
|
||||
snapshots:
|
||||
|
||||
'@boardgamers/protocol@0.3.3':
|
||||
dependencies:
|
||||
zod: 4.6.5
|
||||
|
||||
'@esbuild/aix-ppc64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/android-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/android-arm@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/android-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/darwin-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/darwin-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/freebsd-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/freebsd-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-arm@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-ia32@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-loong64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-mips64el@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-ppc64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-riscv64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-s390x@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/linux-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/netbsd-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/netbsd-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/openbsd-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/openbsd-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/openharmony-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/sunos-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/win32-arm64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/win32-ia32@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@esbuild/win32-x64@0.25.12':
|
||||
optional: true
|
||||
|
||||
'@noble/hashes@2.0.1': {}
|
||||
|
||||
esbuild@0.25.12:
|
||||
optionalDependencies:
|
||||
'@esbuild/aix-ppc64': 0.25.12
|
||||
'@esbuild/android-arm': 0.25.12
|
||||
'@esbuild/android-arm64': 0.25.12
|
||||
'@esbuild/android-x64': 0.25.12
|
||||
'@esbuild/darwin-arm64': 0.25.12
|
||||
'@esbuild/darwin-x64': 0.25.12
|
||||
'@esbuild/freebsd-arm64': 0.25.12
|
||||
'@esbuild/freebsd-x64': 0.25.12
|
||||
'@esbuild/linux-arm': 0.25.12
|
||||
'@esbuild/linux-arm64': 0.25.12
|
||||
'@esbuild/linux-ia32': 0.25.12
|
||||
'@esbuild/linux-loong64': 0.25.12
|
||||
'@esbuild/linux-mips64el': 0.25.12
|
||||
'@esbuild/linux-ppc64': 0.25.12
|
||||
'@esbuild/linux-riscv64': 0.25.12
|
||||
'@esbuild/linux-s390x': 0.25.12
|
||||
'@esbuild/linux-x64': 0.25.12
|
||||
'@esbuild/netbsd-arm64': 0.25.12
|
||||
'@esbuild/netbsd-x64': 0.25.12
|
||||
'@esbuild/openbsd-arm64': 0.25.12
|
||||
'@esbuild/openbsd-x64': 0.25.12
|
||||
'@esbuild/openharmony-arm64': 0.25.12
|
||||
'@esbuild/sunos-x64': 0.25.12
|
||||
'@esbuild/win32-arm64': 0.25.12
|
||||
'@esbuild/win32-ia32': 0.25.12
|
||||
'@esbuild/win32-x64': 0.25.12
|
||||
|
||||
prettier@3.6.2: {}
|
||||
|
||||
zod@4.6.5: {}
|
||||
2
pnpm-workspace.yaml
Normal file
2
pnpm-workspace.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
allowBuilds:
|
||||
esbuild: true
|
||||
35
scripts/build.mjs
Normal file
35
scripts/build.mjs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { build } from "esbuild";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
await mkdir("dist", { recursive: true });
|
||||
await build({
|
||||
entryPoints: ["engine/index.js"],
|
||||
bundle: true,
|
||||
platform: "node",
|
||||
format: "esm",
|
||||
target: "node22",
|
||||
outfile: "dist/engine.js",
|
||||
});
|
||||
await build({
|
||||
entryPoints: ["viewer/index.js"],
|
||||
bundle: true,
|
||||
platform: "browser",
|
||||
format: "iife",
|
||||
target: "es2022",
|
||||
outfile: "dist/viewer.js",
|
||||
loader: { ".ttf": "dataurl" },
|
||||
minify: true,
|
||||
});
|
||||
await build({
|
||||
entryPoints: ["viewer/preview.js"],
|
||||
bundle: true,
|
||||
platform: "browser",
|
||||
format: "esm",
|
||||
target: "es2022",
|
||||
outfile: "dist/preview.js",
|
||||
loader: { ".ttf": "dataurl" },
|
||||
minify: false,
|
||||
});
|
||||
await writeFile(
|
||||
"dist/index.html",
|
||||
'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Primordial Soup · Private playtest</title><link rel="stylesheet" href="preview.css"></head><body><div id="preview-nav"></div><div id="game"></div><script type="module" src="preview.js"></script></body></html>',
|
||||
);
|
||||
25
scripts/dev.mjs
Normal file
25
scripts/dev.mjs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { createServer } from "node:http";
|
||||
import { readFile } from "node:fs/promises";
|
||||
const types = {
|
||||
js: "application/javascript",
|
||||
css: "text/css",
|
||||
html: "text/html",
|
||||
};
|
||||
createServer(async (req, res) => {
|
||||
try {
|
||||
const path = new URL(req.url, "http://localhost").pathname;
|
||||
const name = path === "/" ? "index.html" : path.slice(1);
|
||||
if (!/^[a-z.]+$/.test(name)) throw new Error("Invalid path");
|
||||
res.setHeader(
|
||||
"Content-Type",
|
||||
types[name.split(".").at(-1)] ?? "text/plain",
|
||||
);
|
||||
res.setHeader("Cache-Control", "no-store");
|
||||
res.end(await readFile(new URL(`../dist/${name}`, import.meta.url)));
|
||||
} catch {
|
||||
res.writeHead(404);
|
||||
res.end("Not found");
|
||||
}
|
||||
}).listen(5221, "127.0.0.1", () =>
|
||||
console.log("Primordial Soup private playtest: http://127.0.0.1:5221"),
|
||||
);
|
||||
121
scripts/publish-private.mjs
Normal file
121
scripts/publish-private.mjs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { chapterMetadata } from "../viewer/tutorials.js";
|
||||
const token = (await readFile(`${homedir()}/.bgs`, "utf8")).trim();
|
||||
const base =
|
||||
"https://admin.boardgamers.space/api/admin/gameinfo/primordial-soup";
|
||||
async function api(path, method = "GET", body, raw = false) {
|
||||
const response = await fetch(base + path, {
|
||||
method,
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
...(body
|
||||
? {
|
||||
"Content-Type": raw
|
||||
? "application/octet-stream"
|
||||
: "application/json",
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
body: body ? (raw ? body : JSON.stringify(body)) : undefined,
|
||||
});
|
||||
if (!response.ok)
|
||||
throw new Error(
|
||||
`${method} ${path}: ${response.status} ${await response.text()}`,
|
||||
);
|
||||
return response.json();
|
||||
}
|
||||
const before = await api("/1");
|
||||
const meta = await api("/meta");
|
||||
if (before.public || !meta.unlisted)
|
||||
throw new Error(
|
||||
"Publication requires an existing private, unlisted version.",
|
||||
);
|
||||
await mkdir(".local/release", { recursive: true });
|
||||
await writeFile(".local/release/before.json", JSON.stringify(before, null, 2));
|
||||
execFileSync("pnpm", ["pack", "--pack-destination", ".local/release"], {
|
||||
stdio: "inherit",
|
||||
});
|
||||
const pkg = JSON.parse(await readFile("package.json", "utf8"));
|
||||
const tarball = await readFile(
|
||||
`.local/release/boardgamers-primordial-soup-${pkg.version}.tgz`,
|
||||
);
|
||||
const uploaded = await api("/1/engine", "POST", tarball, true);
|
||||
const js = await readFile("dist/viewer.js"),
|
||||
css = await readFile("dist/viewer.css");
|
||||
const bundle = createHash("sha256")
|
||||
.update(js)
|
||||
.update(css)
|
||||
.digest("hex")
|
||||
.slice(0, 16);
|
||||
const viewer = await api(
|
||||
`/1/viewer/file?filename=viewer.js&bundle=${bundle}`,
|
||||
"POST",
|
||||
js,
|
||||
true,
|
||||
);
|
||||
const style = await api(
|
||||
`/1/viewer/file?filename=viewer.css&bundle=${bundle}`,
|
||||
"POST",
|
||||
css,
|
||||
true,
|
||||
);
|
||||
const current = await api("/1");
|
||||
await api("/1", "PUT", {
|
||||
...current,
|
||||
public: false,
|
||||
engine: { ...uploaded.engine, entryPoint: "dist/engine.js" },
|
||||
viewer: {
|
||||
url: viewer.url,
|
||||
topLevelVariable: "primordialSoup",
|
||||
fullScreen: true,
|
||||
fullScreenMobile: true,
|
||||
dependencies: { scripts: [], stylesheets: [style.url] },
|
||||
},
|
||||
tutorial: {
|
||||
sections: [
|
||||
{
|
||||
id: "basics",
|
||||
title: "Life in the soup",
|
||||
description:
|
||||
"Learn a complete round: movement, feeding, genes, division and evolution.",
|
||||
},
|
||||
{
|
||||
id: "adaptations",
|
||||
title: "A more capable colony",
|
||||
description:
|
||||
"Explore advanced genes and interactions between colonies.",
|
||||
},
|
||||
],
|
||||
chapters: chapterMetadata.map((c, i) => ({
|
||||
...c,
|
||||
section: i < 6 ? "basics" : "adaptations",
|
||||
})),
|
||||
},
|
||||
});
|
||||
await api("/beta-users", "POST", { usernameOrEmail: "coyotte508" });
|
||||
const published = await api("/1"),
|
||||
privacy = await api("/meta"),
|
||||
access = await api("/beta-users");
|
||||
if (published.public || !privacy.unlisted)
|
||||
throw new Error("Privacy check failed");
|
||||
await writeFile(
|
||||
".local/release/published.json",
|
||||
JSON.stringify(published, null, 2),
|
||||
);
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
private: !published.public,
|
||||
unlisted: privacy.unlisted,
|
||||
chapters: published.tutorial.chapters.length,
|
||||
access: access.map((x) => x.username),
|
||||
engine: published.engine.package,
|
||||
viewer: published.viewer,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
386
test/engine.test.js
Normal file
386
test/engine.test.js
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import * as E from "../engine/index.js";
|
||||
import { prepared, chapters } from "../viewer/tutorials.js";
|
||||
import { createTutorial } from "@boardgamers/protocol/tutorial";
|
||||
const act = (s, type, extra = {}) => {
|
||||
const m = E.legalMoves(s).find(
|
||||
(m) =>
|
||||
m.type === type && Object.entries(extra).every(([k, v]) => m[k] === v),
|
||||
);
|
||||
assert.ok(m, `Missing ${type}: ${JSON.stringify(s.tasks[0])}`);
|
||||
return E.move(s, m, E.currentPlayer(s));
|
||||
};
|
||||
function conserved(s) {
|
||||
for (let p = 0; p < s.players.length; p++) {
|
||||
assert.ok(s.players[p].bp >= 0);
|
||||
const carried = s.tasks
|
||||
.filter((t) => t.kind === "carry")
|
||||
.reduce((sum, t) => sum + t.cargo.filter((c) => c === p).length, 0);
|
||||
assert.equal(
|
||||
s.food.reduce((sum, v) => sum + v[p], s.supply[p]) + carried,
|
||||
55,
|
||||
);
|
||||
assert.ok(s.food.every((v) => Number.isInteger(v[p]) && v[p] >= 0));
|
||||
const own = E.colony(s, p);
|
||||
assert.ok(own.length <= 7);
|
||||
assert.equal(new Set(own.map((a) => a.n)).size, own.length);
|
||||
for (const a of own) {
|
||||
assert.ok(E.CELLS.includes(a.cell));
|
||||
assert.ok(a.hp >= 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
test("19 spaces, finite food, deterministic setup, and secret random state", () => {
|
||||
assert.equal(E.CELLS.length, 19);
|
||||
const s = E.init(4, [], {}, "seed");
|
||||
assert.deepEqual(s, E.init(4, [], {}, "seed"));
|
||||
assert.equal(s.players[0].bp, 4);
|
||||
conserved(s);
|
||||
const view = E.stripSecret(s);
|
||||
assert.ok(!("_seed" in view));
|
||||
assert.ok(!("_deck" in view));
|
||||
assert.ok(!("_counter" in view));
|
||||
assert.equal(view.moves.length, 4);
|
||||
const before = structuredClone(s);
|
||||
assert.throws(() =>
|
||||
E.move(s, { type: "score", score: 1 }, (E.currentPlayer(s) + 1) % 4),
|
||||
);
|
||||
assert.deepEqual(s, before);
|
||||
});
|
||||
test("setup is snake order; only first amoebas in four-player games are injured", () => {
|
||||
for (const n of [3, 4]) {
|
||||
let s = E.init(n, [], {}, "setup");
|
||||
while (s.phase === "setup-score") s = act(s, "score");
|
||||
const scores = E.scores(s);
|
||||
const asc = scores.map((_, p) => p).sort((a, b) => scores[a] - scores[b]);
|
||||
assert.deepEqual(
|
||||
s.tasks.map((t) => t.p),
|
||||
asc,
|
||||
);
|
||||
while (s.phase === "setup-first") s = act(s, "place");
|
||||
assert.deepEqual(
|
||||
s.tasks.map((t) => t.p),
|
||||
asc.toReversed(),
|
||||
);
|
||||
while (s.round === 0) s = act(s, "place");
|
||||
for (let p = 0; p < n; p++) {
|
||||
assert.deepEqual(
|
||||
E.colony(s, p).map((a) => a.hp),
|
||||
[n === 4 ? 1 : 0, 0],
|
||||
);
|
||||
}
|
||||
conserved(s);
|
||||
}
|
||||
});
|
||||
test("drift is free and blocked by the island and shore, not by other amoebas", () => {
|
||||
assert.equal(E.destination(11, 2), 11);
|
||||
assert.equal(E.destination(1, 0), 1);
|
||||
let s = prepared({ bp: 0 });
|
||||
s.amoebas.find((a) => a.p === 1).cell = 7;
|
||||
s = act(s, "drift");
|
||||
assert.equal(E.amoeba(s, "0-1").cell, 7);
|
||||
assert.equal(s.players[0].bp, 0);
|
||||
assert.equal(s.tasks[0].kind, "feeding");
|
||||
s = act(s, "eat");
|
||||
assert.deepEqual(s.food[7], [4, 1, 1, 1]);
|
||||
conserved(s);
|
||||
});
|
||||
test("unaffordable swimming is rejected without mutating the position", () => {
|
||||
const s = prepared({ bp: 0 }),
|
||||
before = structuredClone(s);
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.type === "swim"));
|
||||
assert.throws(() => E.move(s, { type: "swim" }, 0));
|
||||
assert.deepEqual(s, before);
|
||||
});
|
||||
test("swimming pays once; Movement I rolls two, Movement II chooses, Speed has no second fee", () => {
|
||||
let s = prepared({ genes: ["movement1"] });
|
||||
s = act(s, "swim");
|
||||
assert.equal(s.players[0].bp, 11);
|
||||
assert.equal(s.tasks[0].dice.length, 2);
|
||||
s = prepared({ genes: ["movement2", "speed"] });
|
||||
s = act(s, "swim");
|
||||
assert.equal(E.legalMoves(s).length, 5);
|
||||
s = act(s, "direction", { direction: 1 });
|
||||
assert.equal(s.tasks[0].kind, "speed");
|
||||
s = act(s, "swim-again");
|
||||
assert.equal(s.players[0].bp, 11);
|
||||
s = act(s, "direction", { direction: 3 });
|
||||
assert.equal(s.tasks[0].kind, "feeding");
|
||||
s = prepared({ bp: 0, genes: ["streamline"] });
|
||||
s = act(s, "swim");
|
||||
assert.equal(s.players[0].bp, 0);
|
||||
});
|
||||
test("three-colony meals give a real choice and starvation consumes nothing", () => {
|
||||
let s = prepared({ players: 3, task: { kind: "feeding", a: "0-1" } });
|
||||
assert.deepEqual(
|
||||
E.legalMoves(s)
|
||||
.filter((m) => m.type === "eat")
|
||||
.map((m) => m.food),
|
||||
[
|
||||
[0, 1, 2],
|
||||
[0, 2, 1],
|
||||
],
|
||||
);
|
||||
s.food[6][1] = 0;
|
||||
s.supply[1] += 2;
|
||||
const before = s.food[6].slice();
|
||||
s = act(s, "starve");
|
||||
assert.equal(E.amoeba(s, "0-1").hp, 1);
|
||||
assert.deepEqual(s.food[6], before);
|
||||
conserved(s);
|
||||
});
|
||||
test("combined feeding genes include the one-colour meal", () => {
|
||||
const s = chapters["feeding-genes"].initialState();
|
||||
assert.deepEqual(
|
||||
E.legalMoves(s).find((m) => m.type === "eat").food,
|
||||
[0, 3, 0, 0],
|
||||
);
|
||||
conserved(act(s, "eat"));
|
||||
});
|
||||
test("advanced genes require an earlier-round prerequisite; pool copies are finite", () => {
|
||||
let s = prepared({
|
||||
phase: 2,
|
||||
task: { kind: "genes", p: 0 },
|
||||
genes: ["movement1"],
|
||||
});
|
||||
s.players[0].genes[0].round = 2;
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.gene === "movement2"));
|
||||
s.players[0].genes[0].round = 1;
|
||||
s = act(s, "buy", { gene: "movement2" });
|
||||
assert.ok(E.has(s, 0, "movement2"));
|
||||
assert.ok(!E.has(s, 0, "movement1"));
|
||||
assert.equal(E.geneCount(s, 0), 2);
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.gene === "movement1"));
|
||||
s.players[1].genes = [{ id: "spores", round: 1 }];
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.gene === "spores"));
|
||||
});
|
||||
test("mutation debt can combine a discarded gene and BP", () => {
|
||||
let s = chapters.environment.initialState();
|
||||
s = act(s, "discard", { gene: "intelligence" });
|
||||
assert.equal(s.tasks[0].debt, 1);
|
||||
s = act(s, "pay-defect");
|
||||
assert.equal(s.players[0].bp, 1);
|
||||
assert.ok(E.has(s, 0, "longevity"));
|
||||
assert.equal(s.phase, 2);
|
||||
});
|
||||
test("division uses adjacency, colony cap, affordable cost, and extinction recovery", () => {
|
||||
let s = prepared({ phase: 3, bp: 6, task: { kind: "division", p: 0 } });
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.cell === 9));
|
||||
s = act(s, "divide", { cell: 7 });
|
||||
assert.equal(s.players[0].bp, 0);
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.type === "divide"));
|
||||
s = prepared({ phase: 3, bp: 0, task: { kind: "division", p: 0 } });
|
||||
s.amoebas = s.amoebas.filter((a) => a.p !== 0);
|
||||
assert.ok(E.legalMoves(s).some((m) => m.cell === 9));
|
||||
s = act(s, "divide", { cell: 9 });
|
||||
assert.equal(s.players[0].bp, 0);
|
||||
assert.equal(E.colony(s, 0).length, 1);
|
||||
});
|
||||
test("food left after death and feeding is limited to available supply", () => {
|
||||
let s = chapters.survival.initialState();
|
||||
const c = E.amoeba(s, "0-2").cell,
|
||||
old = s.food[c].slice();
|
||||
s = act(s, "done");
|
||||
assert.ok(!E.amoeba(s, "0-2"));
|
||||
assert.ok(E.amoeba(s, "0-1"));
|
||||
assert.deepEqual(
|
||||
s.food[c],
|
||||
old.map((n) => n + 2),
|
||||
);
|
||||
conserved(s);
|
||||
s = prepared({ task: { kind: "feeding", a: "0-1" } });
|
||||
s.food[1][0] += 16;
|
||||
s.supply[0] = 1;
|
||||
const count = s.food[6][0];
|
||||
s = act(s, "eat");
|
||||
assert.equal(s.food[6][0], count + 1);
|
||||
assert.equal(s.supply[0], 0);
|
||||
conserved(s);
|
||||
});
|
||||
test("Holding interrupts correctly and Tentacle carries with a conserved supply", () => {
|
||||
let s = prepared();
|
||||
s.players[1].genes = [
|
||||
{ id: "holding", round: 1 },
|
||||
{ id: "tentacle", round: 1 },
|
||||
];
|
||||
s.amoebas.find((a) => a.p === 1).cell = 6;
|
||||
s = act(s, "drift");
|
||||
assert.equal(E.currentPlayer(s), 1);
|
||||
assert.equal(s.tasks[0].kind, "follow");
|
||||
s = act(s, "follow");
|
||||
s = act(s, "carry", { color: 0 });
|
||||
conserved(s);
|
||||
s = act(s, "travel");
|
||||
assert.equal(E.amoeba(s, "1-1").cell, 7);
|
||||
assert.equal(E.currentPlayer(s), 0);
|
||||
assert.equal(s.tasks[0].kind, "feeding");
|
||||
conserved(s);
|
||||
});
|
||||
test("Struggle cannot eat Armor; Aggression wounds it and can trigger natural death", () => {
|
||||
let s = chapters.attacks.initialState();
|
||||
s.players[1].genes = [{ id: "armor", round: 1 }];
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.type === "attack"));
|
||||
s.phase = 4;
|
||||
s.tasks = [{ kind: "aggression", p: 0 }];
|
||||
s.players[0].genes = [{ id: "aggression", round: 1 }];
|
||||
s.amoebas.find((a) => a.id === "1-1").hp = 1;
|
||||
s = act(s, "attack");
|
||||
assert.ok(!E.amoeba(s, "1-1"));
|
||||
assert.equal(s.players[0].bp, 11);
|
||||
conserved(s);
|
||||
});
|
||||
test("Escape uses movement genes and returns to the original turn", () => {
|
||||
let s = chapters.attacks.initialState();
|
||||
s.players[1].genes = [
|
||||
{ id: "escape", round: 1 },
|
||||
{ id: "movement2", round: 1 },
|
||||
];
|
||||
s = act(s, "attack");
|
||||
assert.equal(E.currentPlayer(s), 1);
|
||||
s = act(s, "escape");
|
||||
assert.equal(s.players[1].bp, 5);
|
||||
s = act(s, "direction", { direction: 1 });
|
||||
assert.equal(E.amoeba(s, "1-1").cell, 1);
|
||||
assert.equal(E.amoeba(s, "0-1").hp, 1);
|
||||
conserved(s);
|
||||
});
|
||||
test("scoring leapfrogs occupied spaces in descending order", () => {
|
||||
let s = prepared({ phase: 3, bp: 0, task: { kind: "division", p: 0 } });
|
||||
s.players.forEach((p, i) => (p.score = [1, 2, 3, 4][i]));
|
||||
s.amoebas = s.amoebas.filter((a) => a.p !== 0);
|
||||
for (let n = 1; n <= 3; n++)
|
||||
s.amoebas.push({ id: `0-${n}`, p: 0, n, cell: [6, 7, 11][n - 1], hp: 0 });
|
||||
s = act(s, "done");
|
||||
assert.equal(s.players[0].score, 5);
|
||||
assert.equal(s.lastScoring[0].advance, 1);
|
||||
});
|
||||
test("completed games at both player counts remain valid across save/reload", () => {
|
||||
for (const n of [3, 4])
|
||||
for (let seed = 0; seed < 12; seed++) {
|
||||
let s = E.init(n, [], {}, `autoplay-${seed}`),
|
||||
steps = 0;
|
||||
while (!E.ended(s) && steps++ < 2000) {
|
||||
const before = structuredClone(s),
|
||||
next = E.moveAI(s, E.currentPlayer(s));
|
||||
assert.deepEqual(s, before);
|
||||
s = steps % 19 === 0 ? JSON.parse(JSON.stringify(next)) : next;
|
||||
conserved(s);
|
||||
assert.equal(E.stripSecret(s).actor, E.currentPlayer(s));
|
||||
}
|
||||
assert.ok(s.finished, `No finish: ${n}/${seed}`);
|
||||
assert.ok(s.round <= 10);
|
||||
assert.equal(E.currentPlayer(s), undefined);
|
||||
assert.equal(new Set(E.scores(s)).size, n);
|
||||
}
|
||||
});
|
||||
test("dropped colonies get a replacement at any point", () => {
|
||||
let s = E.init(3, [], {}, "drop");
|
||||
const dropped = E.currentPlayer(s);
|
||||
s = E.dropPlayer(s, dropped);
|
||||
assert.notEqual(E.currentPlayer(s), dropped);
|
||||
let count = 0;
|
||||
while (!s.finished && count++ < 2000) {
|
||||
assert.notEqual(E.currentPlayer(s), dropped);
|
||||
s = E.moveAI(s, E.currentPlayer(s));
|
||||
}
|
||||
assert.ok(s.finished);
|
||||
});
|
||||
test("every tutorial is playable, completes, and restores from recorded actions", async () => {
|
||||
const sequences = {
|
||||
drift: ["continue", "drift", "eat"],
|
||||
swim: ["swim", "direction", "eat"],
|
||||
division: ["divide", "divide", "done"],
|
||||
genes: ["buy:movement1", "continue", "done"],
|
||||
environment: ["discard:intelligence", "pay-defect"],
|
||||
survival: ["done", "continue"],
|
||||
"movement-genes": ["buy:movement2", "continue"],
|
||||
"feeding-genes": ["eat", "continue"],
|
||||
interactions: ["follow", "carry", "travel"],
|
||||
attacks: ["attack", "continue"],
|
||||
};
|
||||
for (const [id, config] of Object.entries(chapters)) {
|
||||
const cache = new Map(),
|
||||
storage = {
|
||||
getItem: (k) => cache.get(k) ?? null,
|
||||
setItem: (k, v) => cache.set(k, v),
|
||||
};
|
||||
const c = await createTutorial({ ...config, storage });
|
||||
for (const token of sequences[id]) {
|
||||
if (token === "continue") {
|
||||
await c.continue();
|
||||
continue;
|
||||
}
|
||||
const [type, gene] = token.split(":"),
|
||||
m = E.legalMoves(c.snapshot.state).find(
|
||||
(m) => m.type === type && (!gene || m.gene === gene),
|
||||
);
|
||||
assert.ok(m, `${id}: missing ${token}`);
|
||||
assert.ok(await c.play(m), `${id}: ${c.snapshot.error}`);
|
||||
}
|
||||
assert.ok(c.snapshot.completed, `${id} incomplete`);
|
||||
const expected = c.snapshot.state;
|
||||
c.destroy();
|
||||
const restored = await createTutorial({ ...config, storage });
|
||||
assert.ok(restored.snapshot.completed);
|
||||
assert.deepEqual(restored.snapshot.state, expected);
|
||||
restored.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test("Parasitism combines with other feeding adaptations but cannot charge an empty host", () => {
|
||||
let s = prepared({
|
||||
genes: ["parasitism", "substitution"],
|
||||
task: { kind: "feeding", a: "0-1" },
|
||||
});
|
||||
s.amoebas.find((a) => a.p === 1).cell = 6;
|
||||
for (let p = 0; p < 4; p++) {
|
||||
s.supply[p] += s.food[6][p];
|
||||
s.food[6][p] = 0;
|
||||
}
|
||||
s.food[6][2] = 3;
|
||||
s.supply[2] -= 3;
|
||||
const eat = E.legalMoves(s).find((m) => m.type === "eat");
|
||||
assert.deepEqual(eat.food, [0, 0, 3, 0]);
|
||||
assert.equal(eat.host, 1);
|
||||
const after = E.move(s, eat, 0);
|
||||
assert.equal(after.players[1].bp, 5);
|
||||
conserved(after);
|
||||
s.players[1].bp = 0;
|
||||
assert.ok(!E.legalMoves(s).some((m) => m.type === "eat"));
|
||||
});
|
||||
|
||||
test("random legal play preserves invariants across uncommon gene combinations", () => {
|
||||
for (let run = 0; run < 12; run++) {
|
||||
let s = E.init(4, [], {}, `random-${run}`),
|
||||
rng = run + 1,
|
||||
steps = 0;
|
||||
const random = (n) => {
|
||||
rng = (Math.imul(rng, 1664525) + 1013904223) >>> 0;
|
||||
return rng % n;
|
||||
};
|
||||
while (!E.ended(s) && steps++ < 4000) {
|
||||
const moves = E.legalMoves(s);
|
||||
assert.ok(moves.length);
|
||||
const affordable = moves.filter((m) => m.type === "buy");
|
||||
const choices = affordable.length && random(3) ? affordable : moves;
|
||||
s = E.move(s, choices[random(choices.length)], E.currentPlayer(s));
|
||||
conserved(s);
|
||||
}
|
||||
assert.ok(E.ended(s), `random run ${run} must end`);
|
||||
}
|
||||
});
|
||||
|
||||
test("a bot completes its colony turn but yields to an opponent's Holding decision", () => {
|
||||
let s = prepared();
|
||||
s = E.moveAI(s, 0);
|
||||
assert.notEqual(E.currentPlayer(s), 0);
|
||||
assert.ok(s.history.filter((h) => h.move.type === "eat").length >= 2);
|
||||
s = prepared();
|
||||
s.players[1].genes = [{ id: "holding", round: 1 }];
|
||||
s.amoebas.find((a) => a.p === 1).cell = 6;
|
||||
s = E.moveAI(s, 0);
|
||||
assert.equal(E.currentPlayer(s), 1);
|
||||
assert.equal(s.tasks[0].kind, "follow");
|
||||
assert.equal(s.history.length, 1);
|
||||
});
|
||||
79
viewer/art.js
Normal file
79
viewer/art.js
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
const colors = {
|
||||
green: {
|
||||
body: "#b7d967",
|
||||
shade: "#8cb74a",
|
||||
light: "#e5ef9e",
|
||||
stroke: "#52753c",
|
||||
cheek: "#96bc50",
|
||||
},
|
||||
red: {
|
||||
body: "#e99b8a",
|
||||
shade: "#ce7969",
|
||||
light: "#ffcab2",
|
||||
stroke: "#a06151",
|
||||
cheek: "#d6776e",
|
||||
},
|
||||
blue: {
|
||||
body: "#8eb8d5",
|
||||
shade: "#6398bc",
|
||||
light: "#c5e0e7",
|
||||
stroke: "#4a7c96",
|
||||
cheek: "#7ca8c9",
|
||||
},
|
||||
yellow: {
|
||||
body: "#eed17c",
|
||||
shade: "#d4b14e",
|
||||
light: "#fff0b4",
|
||||
stroke: "#aa8c45",
|
||||
cheek: "#dfb965",
|
||||
},
|
||||
};
|
||||
const iconPaths = {
|
||||
help: '<circle cx="12" cy="12" r="9"/><path d="M9.5 9a2.5 2.5 0 0 1 5 0c0 2-2.5 2-2.5 4m0 3v.1"/>',
|
||||
heart:
|
||||
'<path d="M12 20S3 15 3 8.5A4.5 4.5 0 0 1 12 7a4.5 4.5 0 0 1 9 1.5C21 15 12 20 12 20Z"/>',
|
||||
bio: '<path d="M9 2h6m-5 0v7L5 18q-1 3 3 3h8q4 0 3-3l-5-9V2M8 14h8"/><circle cx="11" cy="17" r="1"/>',
|
||||
grid: '<rect x="3" y="3" width="18" height="18" rx="3"/><path d="M3 9h18M3 15h18M9 3v18M15 3v18"/>',
|
||||
expand: '<path d="M8 3H3v5m13-5h5v5M3 16v5h5m13-5v5h-5"/>',
|
||||
"sound-off": '<path d="M11 4 6 8H3v8h3l5 4Zm5 5 6 6m-6 0 6-6"/>',
|
||||
sound: '<path d="M11 4 6 8H3v8h3l5 4Zm4 4q4 4 0 8m3-11q7 7 0 14"/>',
|
||||
history: '<path d="M3 10a9 9 0 1 1 1 7M3 4v6h6m3-4v6l4 2"/>',
|
||||
spark: '<path d="m12 2 3 7 7 3-7 3-3 7-3-7-7-3 7-3Z"/>',
|
||||
wave: '<path d="M2 8q3-5 7 0t7 0 6 0M2 15q3-5 7 0t7 0 6 0"/>',
|
||||
arrow: '<path d="M4 12h16m-6-6 6 6-6 6"/>',
|
||||
sun: '<circle cx="12" cy="12" r="4"/><path d="M12 1v2m0 18v2M1 12h2m18 0h2M4 4l2 2m12 12 2 2M4 20l2-2M18 6l2-2"/>',
|
||||
divide:
|
||||
'<path d="M11 5C4-2-3 14 5 19c4 3 5-3 7-3s3 6 7 3c8-5 1-21-6-14Z"/><circle cx="7" cy="11" r="2"/><circle cx="17" cy="11" r="2"/>',
|
||||
shield:
|
||||
'<path d="m12 2 9 4v7q-2 6-9 9-7-3-9-9V6Z"/><path d="m8 12 3 3 5-6"/>',
|
||||
undo: '<path d="M4 11a8 8 0 1 1 2 9M4 4v7h7"/>',
|
||||
};
|
||||
const icon = (name) =>
|
||||
`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${iconPaths[name] || iconPaths.spark}</svg>`;
|
||||
|
||||
let artId = 0;
|
||||
function amoeba(color, variant = 0, feature = "") {
|
||||
const c = colors[color];
|
||||
const id = `amoeba-${++artId}`;
|
||||
const body =
|
||||
variant % 3 === 0
|
||||
? "M23 57C9 57 7 43 18 39C8 25 20 16 31 24C35 9 48 9 53 20C64 7 79 16 75 30C95 27 97 43 84 49C100 59 91 73 76 69C72 88 54 83 48 76C37 89 22 79 24 69C9 75 5 62 23 57Z"
|
||||
: variant % 3 === 1
|
||||
? "M18 47C5 34 16 22 29 27C24 10 42 6 49 20C56 5 73 14 70 25C88 16 98 30 84 40C103 49 94 63 81 63C90 80 72 87 61 73C58 90 38 89 34 73C19 84 7 74 18 61C5 63 5 48 18 47Z"
|
||||
: "M19 55C5 48 11 30 25 33C12 17 34 8 40 24C44 5 64 8 66 25C81 11 97 30 83 42C104 43 98 63 82 62C89 80 65 89 59 74C47 93 27 86 31 70C11 82 4 61 19 55Z";
|
||||
return `<svg viewBox="0 0 100 100" aria-hidden="true"><defs><radialGradient id="${id}" cx="40%" cy="24%" r="75%"><stop stop-color="${c.light}"/><stop offset=".48" stop-color="${c.body}"/><stop offset="1" stop-color="${c.shade}"/></radialGradient></defs>
|
||||
${feature === "movement" ? `<path d="M23 65Q-12 45 2 35Q17 40 23 53M77 60Q105 35 99 25Q84 31 77 43" fill="${c.body}" stroke="${c.stroke}" stroke-width="2"/>` : ""}
|
||||
${feature === "spines" ? `<path d="M25 29 17 8 39 23M64 21 80 6 77 31M82 54 99 71 76 69M37 72 31 94 52 76M19 52 0 64 23 67" fill="${c.shade}" stroke="${c.stroke}" stroke-width="2" stroke-linejoin="round"/>` : ""}
|
||||
<path d="${body}" fill="url(#${id})" stroke="${c.stroke}" stroke-width="2" stroke-linejoin="round"/>
|
||||
<path d="M26 32q1-6 7-7M55 24q5-3 9 0" stroke="#fff" stroke-opacity=".65" stroke-width="4" fill="none" stroke-linecap="round"/>
|
||||
<ellipse cx="36" cy="64" rx="7" ry="5" fill="${c.cheek}" opacity=".6"/><ellipse cx="71" cy="60" rx="6" ry="4" fill="${c.cheek}" opacity=".55"/>
|
||||
<circle cx="29" cy="46" r="3" fill="${c.light}"/><circle cx="74" cy="38" r="2" fill="${c.shade}" opacity=".45"/><circle cx="47" cy="70" r="2" fill="${c.shade}" opacity=".7"/>
|
||||
<g class="eyes"><ellipse cx="43" cy="41" rx="12" ry="14" fill="#fffef1" stroke="${c.stroke}" stroke-width="1.7"/><ellipse cx="65" cy="40" rx="12" ry="14.5" fill="#fffef1" stroke="${c.stroke}" stroke-width="1.7"/>
|
||||
<ellipse cx="${45 + (variant % 2)}" cy="44" rx="4.3" ry="6.2" fill="#24433a"/><ellipse cx="${65 + (variant % 2)}" cy="43" rx="4.3" ry="6.2" fill="#24433a"/><circle cx="44" cy="41" r="1.8" fill="white"/><circle cx="64" cy="40" r="1.8" fill="white"/></g>
|
||||
<path d="M47 61q7 8 14-1" stroke="${c.stroke}" stroke-width="2" stroke-linecap="round" fill="none"/>
|
||||
${feature === "food" ? '<path d="M65 70q9-13 11-2q-1 12-11 2" fill="#ffd4a2" stroke="#86613c" stroke-width="1.5"/><rect x="68" y="68" width="9" height="8" rx="2" fill="#ed9785" stroke="#a46c54"/>' : ""}
|
||||
${feature === "shield" ? '<path d="m75 55 18 7v12q-5 10-18 15-12-5-15-15V62Z" fill="#dbe8e0" stroke="#4d7767" stroke-width="2"/><path d="m68 71 5 5 11-11" fill="none" stroke="#6b995b" stroke-width="3"/>' : ""}
|
||||
</svg>`;
|
||||
}
|
||||
|
||||
export { colors, icon, amoeba };
|
||||
93
viewer/assets/DM-Sans-OFL.txt
Normal file
93
viewer/assets/DM-Sans-OFL.txt
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
Copyright 2014 The DM Sans Project Authors (https://github.com/googlefonts/dm-fonts)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
94
viewer/assets/Lilita-One-OFL.txt
Normal file
94
viewer/assets/Lilita-One-OFL.txt
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
Copyright (c) 2011 Juan Montoreano (juan@remolacha.biz),
|
||||
with Reserved Font Name Lilita
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
BIN
viewer/assets/font-0.ttf
Normal file
BIN
viewer/assets/font-0.ttf
Normal file
Binary file not shown.
BIN
viewer/assets/font-1.ttf
Normal file
BIN
viewer/assets/font-1.ttf
Normal file
Binary file not shown.
BIN
viewer/assets/font-2.ttf
Normal file
BIN
viewer/assets/font-2.ttf
Normal file
Binary file not shown.
BIN
viewer/assets/font-3.ttf
Normal file
BIN
viewer/assets/font-3.ttf
Normal file
Binary file not shown.
BIN
viewer/assets/font-4.ttf
Normal file
BIN
viewer/assets/font-4.ttf
Normal file
Binary file not shown.
35
viewer/fonts.css
Normal file
35
viewer/fonts.css
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
@font-face {
|
||||
font-family: "DM Sans";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url(./assets/font-0.ttf) format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "DM Sans";
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
font-display: swap;
|
||||
src: url(./assets/font-1.ttf) format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "DM Sans";
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
font-display: swap;
|
||||
src: url(./assets/font-2.ttf) format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "DM Sans";
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
src: url(./assets/font-3.ttf) format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "Lilita One";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
src: url(./assets/font-4.ttf) format("truetype");
|
||||
}
|
||||
89
viewer/index.js
Normal file
89
viewer/index.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
import "./style.css";
|
||||
import { registerViewer } from "@boardgamers/protocol/viewer";
|
||||
import { createTutorial } from "@boardgamers/protocol/tutorial";
|
||||
import { mountTutorialGuide } from "@boardgamers/protocol/tutorial/dom";
|
||||
import { stripSecret } from "../engine/index.js";
|
||||
import { chapters } from "./tutorials.js";
|
||||
import { mountGame } from "./ui.js";
|
||||
export async function mountLesson(target, options) {
|
||||
const chapter = chapters[options.chapter];
|
||||
if (!chapter) throw new Error("Unknown tutorial chapter.");
|
||||
let storage;
|
||||
try {
|
||||
storage = window.localStorage;
|
||||
} catch {}
|
||||
const tutorial = await createTutorial({
|
||||
...chapter,
|
||||
storage,
|
||||
onProgress: options.onProgress,
|
||||
});
|
||||
const ui = mountGame(target, { onMove: (m) => tutorial.play(m) });
|
||||
ui.setPlayer(0);
|
||||
let previousStep;
|
||||
const off = tutorial.subscribe((snapshot) => {
|
||||
if (previousStep !== snapshot.step) {
|
||||
ui.closeModal();
|
||||
previousStep = snapshot.step;
|
||||
}
|
||||
ui.render(stripSecret(snapshot.state));
|
||||
ui.setEnabled(
|
||||
!snapshot.busy && !snapshot.completed && !snapshot.canContinue,
|
||||
);
|
||||
});
|
||||
const removeGuide = mountTutorialGuide(ui.guide, tutorial, {
|
||||
nextChapter: options.nextChapter,
|
||||
});
|
||||
return () => {
|
||||
off();
|
||||
removeGuide();
|
||||
tutorial.destroy();
|
||||
ui.destroy();
|
||||
};
|
||||
}
|
||||
registerViewer(
|
||||
"primordialSoup",
|
||||
(ctx) => {
|
||||
let pending, timeout;
|
||||
const ui = mountGame(ctx.target, {
|
||||
onMove: (m) =>
|
||||
new Promise((resolve, reject) => {
|
||||
pending = { resolve, reject };
|
||||
timeout = setTimeout(() => {
|
||||
pending = undefined;
|
||||
reject(
|
||||
new Error(
|
||||
"Waiting for the server. Refresh if your move has not appeared.",
|
||||
),
|
||||
);
|
||||
}, 15000);
|
||||
ctx.move(m);
|
||||
}),
|
||||
});
|
||||
return {
|
||||
onPlayer(player) {
|
||||
ui.setPlayer(player.index);
|
||||
},
|
||||
onState(state) {
|
||||
ui.render(state);
|
||||
if (pending) {
|
||||
clearTimeout(timeout);
|
||||
pending.resolve();
|
||||
pending = undefined;
|
||||
}
|
||||
},
|
||||
onError(error) {
|
||||
if (pending) {
|
||||
clearTimeout(timeout);
|
||||
pending.reject(error);
|
||||
pending = undefined;
|
||||
}
|
||||
},
|
||||
destroy() {
|
||||
clearTimeout(timeout);
|
||||
pending?.resolve();
|
||||
ui.destroy();
|
||||
},
|
||||
};
|
||||
},
|
||||
{ tutorial: mountLesson },
|
||||
);
|
||||
34
viewer/pond.js
Normal file
34
viewer/pond.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { CELLS } from "../engine/catalog.js";
|
||||
export function pondArt() {
|
||||
const shore =
|
||||
"M239 38 Q217 37 211 66 L211 347 Q211 365 193 365 L77 365 Q39 367 38 396 L38 443 Q35 475 76 479 L193 479 Q211 479 211 496 L211 563 Q211 604 250 605 L812 605 Q864 602 864 563 L864 184 Q864 148 821 147 L708 147 Q691 146 691 129 L691 70 Q691 37 649 37 Z";
|
||||
let s = `<defs><linearGradient id="soup-water" x1="0" x2=".8" y1="0" y2="1"><stop stop-color="#bee8cc"/><stop offset=".6" stop-color="#9fd7c0"/><stop offset="1" stop-color="#81baa4"/></linearGradient><pattern id="soup-speckle" width="31" height="29" patternUnits="userSpaceOnUse"><circle cx="4" cy="8" r=".65" fill="#3c8875" opacity=".17"/><circle cx="23" cy="22" r=".7" fill="#fff" opacity=".3"/></pattern><clipPath id="soup-pond-clip"><path d="${shore}"/></clipPath></defs><path d="${shore}" fill="#d8e5b9" stroke="#bed0aa" stroke-width="20" stroke-linejoin="round"/><path d="${shore}" fill="url(#soup-water)" stroke="#739d7c" stroke-width="2"/><g clip-path="url(#soup-pond-clip)"><rect width="900" height="650" fill="url(#soup-speckle)"/><g class="grid-lines" fill="none" stroke="#e5f5da" stroke-width="1.3" stroke-opacity=".6">`;
|
||||
for (const cell of CELLS) {
|
||||
const x = 60 + (cell % 5) * 156,
|
||||
y = 55 + Math.floor(cell / 5) * 105;
|
||||
s += `<path d="M${x} ${y}q80 4 156 0v105q-75-4-156 0Z"/>`;
|
||||
}
|
||||
s += "</g>";
|
||||
for (let n = 0; n < 38; n++)
|
||||
s += `<circle class="pond-bubble" cx="${65 + ((n * 173) % 780)}" cy="${53 + ((n * 83) % 535)}" r="${2 + (n % 4)}" fill="none" stroke="#ecffe5" stroke-width="1.2" style="--delay:-${n % 8}s"/>`;
|
||||
s +=
|
||||
'</g><path d="M381 273Q396 263 413 271Q441 260 461 271Q500 266 515 284Q530 301 520 328Q525 359 492 363Q463 374 442 365Q412 373 389 356Q368 340 376 319Q366 291 381 273Z" fill="#dce7c4" stroke="#99b69a" stroke-width="2"/>';
|
||||
for (const [x, y, r] of [
|
||||
[217, 59, 18],
|
||||
[694, 135, 14],
|
||||
[57, 475, 17],
|
||||
[211, 558, 13],
|
||||
[840, 594, 19],
|
||||
[693, 50, 12],
|
||||
])
|
||||
s += `<ellipse cx="${x}" cy="${y}" rx="${r}" ry="${r * 0.55}" fill="#b7c9a5" stroke="#93aa87"/><path d="M${x - r * 0.5} ${y - 2}q${r * 0.5}-6 ${r} 0" fill="none" stroke="#dce8c9" stroke-width="2"/>`;
|
||||
for (const [x, y, r] of [
|
||||
[204, 347, 15],
|
||||
[219, 35, 150],
|
||||
[865, 212, -50],
|
||||
[786, 608, 60],
|
||||
[75, 364, -15],
|
||||
])
|
||||
s += `<g transform="translate(${x} ${y}) rotate(${r})"><path d="M0 0Q-14-29-30-31Q-28-7 0 0M0 0Q-22-4-34 10Q-9 17 0 0M0 0Q-3-33 9-45Q21-18 0 0M0 0Q19-24 35-21Q29 1 0 0" fill="#89ac74" stroke="#658d69" stroke-width="1.5"/><path d="M0 0 9-33M0 0-23-24M0 0 24-16" stroke="#c9dca6" fill="none"/></g>`;
|
||||
return s;
|
||||
}
|
||||
72
viewer/preview.js
Normal file
72
viewer/preview.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import "./style.css";
|
||||
import * as E from "../engine/index.js";
|
||||
import { mountGame } from "./ui.js";
|
||||
import { chapterMetadata } from "./tutorials.js";
|
||||
import { mountLesson } from "./index.js";
|
||||
const params = new URLSearchParams(location.search),
|
||||
chapter = params.get("chapter"),
|
||||
target = document.querySelector("#game"),
|
||||
nav = document.querySelector("#preview-nav");
|
||||
nav.className = "practice-nav";
|
||||
nav.innerHTML = `<span>Private local playtest</span><a href="/">Practice game</a><label>Learn <select aria-label="Tutorial chapter"><option value="">Choose a chapter</option>${chapterMetadata.map((c) => `<option value="${c.id}" ${c.id === chapter ? "selected" : ""}>${c.title}</option>`).join("")}</select></label>${chapter ? "" : '<button id="new-three">New 3-colony game</button><button id="new-four">New 4-colony game</button>'}`;
|
||||
nav.querySelector("select").addEventListener("change", (e) => {
|
||||
location.href = e.target.value ? `/?chapter=${e.target.value}` : "/";
|
||||
});
|
||||
if (chapter) {
|
||||
const next =
|
||||
chapterMetadata[chapterMetadata.findIndex((c) => c.id === chapter) + 1];
|
||||
await mountLesson(target, {
|
||||
chapter,
|
||||
nextChapter: next
|
||||
? {
|
||||
id: next.id,
|
||||
title: next.title,
|
||||
open() {
|
||||
location.href = `/?chapter=${next.id}`;
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
} else {
|
||||
let state;
|
||||
try {
|
||||
state = JSON.parse(localStorage.getItem("soup:practice:1"));
|
||||
} catch {}
|
||||
if (!state || state.version !== 1)
|
||||
state = E.init(3, [], {}, "practice-" + Date.now());
|
||||
state.players.forEach((p, i) => (p.name = ["You", "Maya", "Leo", "Nina"][i]));
|
||||
const ui = mountGame(target, {
|
||||
onMove: async (m) => {
|
||||
state = E.move(state, m, 0);
|
||||
draw();
|
||||
await bots();
|
||||
},
|
||||
});
|
||||
ui.setPlayer(0);
|
||||
const draw = () => {
|
||||
ui.render(E.stripSecret(state));
|
||||
try {
|
||||
localStorage.setItem("soup:practice:1", JSON.stringify(state));
|
||||
} catch {}
|
||||
};
|
||||
async function bots() {
|
||||
let n = 0;
|
||||
while (!E.ended(state) && E.currentPlayer(state) !== 0 && n++ < 500) {
|
||||
await new Promise((r) => setTimeout(r, 180));
|
||||
state = E.moveAI(state, E.currentPlayer(state));
|
||||
draw();
|
||||
}
|
||||
}
|
||||
for (const count of [3, 4])
|
||||
nav
|
||||
.querySelector(count === 3 ? "#new-three" : "#new-four")
|
||||
.addEventListener("click", () => {
|
||||
localStorage.setItem(
|
||||
"soup:practice:1",
|
||||
JSON.stringify(E.init(count, [], {}, "practice-" + Date.now())),
|
||||
);
|
||||
location.reload();
|
||||
});
|
||||
draw();
|
||||
await bots();
|
||||
}
|
||||
1671
viewer/prototype.css
Normal file
1671
viewer/prototype.css
Normal file
File diff suppressed because it is too large
Load diff
802
viewer/style.css
Normal file
802
viewer/style.css
Normal file
|
|
@ -0,0 +1,802 @@
|
|||
@import "./fonts.css";
|
||||
@import "./prototype.css";
|
||||
.soup {
|
||||
min-height: 100dvh;
|
||||
padding-bottom: 18px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.soup .topbar {
|
||||
height: 74px;
|
||||
flex: none;
|
||||
}
|
||||
.edition-tag {
|
||||
margin-left: auto;
|
||||
color: #6e8166;
|
||||
font-size: 11px;
|
||||
padding: 4px 9px;
|
||||
border: 1px solid #cdd8c1;
|
||||
border-radius: 20px;
|
||||
}
|
||||
.utilities .quiet-button svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
.utilities .quiet-button {
|
||||
padding: 5px;
|
||||
}
|
||||
.soup .players {
|
||||
padding: 12px 0;
|
||||
gap: 12px;
|
||||
}
|
||||
.soup .player {
|
||||
text-align: left;
|
||||
}
|
||||
.soup .player-name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: block;
|
||||
}
|
||||
.soup .player-name .you-tag {
|
||||
margin-left: 6px;
|
||||
}
|
||||
.soup .player-stat {
|
||||
display: block;
|
||||
}
|
||||
.soup .play-area {
|
||||
align-items: start;
|
||||
flex: 1;
|
||||
}
|
||||
.soup .board {
|
||||
height: clamp(390px, calc(100dvh - 330px), 660px);
|
||||
width: 100%;
|
||||
aspect-ratio: auto;
|
||||
max-height: none;
|
||||
min-height: 0;
|
||||
}
|
||||
.soup .water-cell {
|
||||
border-radius: 15%;
|
||||
padding: 0;
|
||||
}
|
||||
.soup .water-cell[aria-disabled="true"] {
|
||||
cursor: default;
|
||||
}
|
||||
.soup .water-cell.last-cell {
|
||||
background: #e5f7bf55;
|
||||
}
|
||||
.soup .water-cell.valid {
|
||||
box-shadow: inset 0 0 0 2px #ffffda;
|
||||
}
|
||||
.soup .water-cell.valid:after {
|
||||
font-size: 10px;
|
||||
top: 3%;
|
||||
z-index: 5;
|
||||
}
|
||||
.soup .water-cell .cell-coord {
|
||||
font-size: 10px;
|
||||
color: #426c6388;
|
||||
}
|
||||
.soup .amoeba-button {
|
||||
width: 10%;
|
||||
height: 16%;
|
||||
transform: translate(-50%, -50%) scale(var(--scale));
|
||||
filter: drop-shadow(0 4px 0 #336b6630);
|
||||
}
|
||||
.soup .amoeba-button:active {
|
||||
transform: translate(-50%, -50%) scale(var(--scale));
|
||||
}
|
||||
.soup .amoeba-button.selected:before {
|
||||
left: 5%;
|
||||
width: 90%;
|
||||
}
|
||||
.soup .amoeba-button.acting:before {
|
||||
border-color: #fff7cd;
|
||||
border-style: solid;
|
||||
box-shadow: 0 0 0 5px #fff7cd30;
|
||||
}
|
||||
.soup .amoeba-number {
|
||||
right: 4%;
|
||||
bottom: 4%;
|
||||
font-size: 10px;
|
||||
width: 19px;
|
||||
height: 19px;
|
||||
}
|
||||
.injury {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 5%;
|
||||
border-radius: 10px;
|
||||
background: #fcddd0;
|
||||
color: #97502f;
|
||||
font-size: 10px;
|
||||
padding: 2px 4px;
|
||||
border: 1px solid #bb8f77;
|
||||
}
|
||||
.soup .nutrients {
|
||||
bottom: 10%;
|
||||
left: 4%;
|
||||
right: 4%;
|
||||
gap: 5px;
|
||||
flex-wrap: wrap;
|
||||
height: auto;
|
||||
min-height: 10px;
|
||||
z-index: 4;
|
||||
}
|
||||
.food-amount {
|
||||
display: inline-flex;
|
||||
gap: 2px;
|
||||
align-items: center;
|
||||
font-size: 10px;
|
||||
color: #325e4c;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.food-amount > .food {
|
||||
width: 11px;
|
||||
height: 11px;
|
||||
transform: rotate(-8deg) !important;
|
||||
}
|
||||
.soup .current-compass {
|
||||
top: 43%;
|
||||
height: 13%;
|
||||
}
|
||||
.soup .current-compass > span {
|
||||
font-size: 8px;
|
||||
}
|
||||
.soup .current-compass > b {
|
||||
font-size: 8px;
|
||||
}
|
||||
.soup .current-compass > div {
|
||||
font-size: 32px;
|
||||
line-height: 32px;
|
||||
}
|
||||
.soup .current-compass small {
|
||||
font-size: 9px;
|
||||
}
|
||||
.soup-board-key {
|
||||
position: absolute;
|
||||
left: 1%;
|
||||
top: 9%;
|
||||
width: 19%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
color: #8a9e77;
|
||||
text-align: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.soup-board-key > span {
|
||||
font-size: 9px;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
.soup-board-key > b {
|
||||
font: 48px "Lilita One";
|
||||
}
|
||||
.soup-board-key > small {
|
||||
font-size: 10px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.soup .pond-bottom {
|
||||
margin: 0;
|
||||
min-height: 32px;
|
||||
gap: 15px;
|
||||
padding-top: 6px;
|
||||
}
|
||||
.soup .last-move {
|
||||
font-size: 11px;
|
||||
line-height: 1.45;
|
||||
color: #688165;
|
||||
flex: 1;
|
||||
}
|
||||
.food-reserve {
|
||||
display: flex;
|
||||
gap: 7px;
|
||||
align-items: center;
|
||||
}
|
||||
.food-reserve > small {
|
||||
font-size: 10px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.soup .colony-panel {
|
||||
padding-top: 10px;
|
||||
}
|
||||
.soup .colony-heading h2 {
|
||||
font-size: 25px;
|
||||
max-width: 165px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.soup .bio-balance > svg {
|
||||
width: 21px;
|
||||
height: 27px;
|
||||
grid-row: span 2;
|
||||
}
|
||||
.soup .specimen {
|
||||
height: 120px;
|
||||
}
|
||||
.soup #selected-portrait {
|
||||
width: 118px;
|
||||
}
|
||||
.soup .diet {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.soup .gene-heading {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.soup .gene-list {
|
||||
max-height: 230px;
|
||||
overflow: auto;
|
||||
}
|
||||
.soup .gene-list > .gene {
|
||||
flex: none;
|
||||
padding: 9px;
|
||||
}
|
||||
.soup .gene-sensitivity > svg {
|
||||
height: 12px;
|
||||
width: 12px;
|
||||
}
|
||||
.soup .gene p {
|
||||
font-size: 10px;
|
||||
}
|
||||
.empty-genes {
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: var(--muted);
|
||||
margin: 4px 0;
|
||||
}
|
||||
.colony-metrics {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
font-size: 11px;
|
||||
color: #748669;
|
||||
padding: 15px 0;
|
||||
}
|
||||
.colony-metrics > span {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
align-items: center;
|
||||
}
|
||||
.colony-metrics svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
.soup .turnbar {
|
||||
position: sticky;
|
||||
bottom: 10px;
|
||||
z-index: 12;
|
||||
margin-top: 14px;
|
||||
flex-wrap: wrap;
|
||||
padding: 14px 18px;
|
||||
gap: 12px;
|
||||
background: #fbfaf1f7;
|
||||
backdrop-filter: blur(8px);
|
||||
flex: none;
|
||||
}
|
||||
.soup .phase-label {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--ink);
|
||||
}
|
||||
.phase-instruction {
|
||||
font-size: 12px;
|
||||
color: #708064;
|
||||
margin-top: 5px;
|
||||
line-height: 1.5;
|
||||
max-width: 630px;
|
||||
}
|
||||
.soup .turn-details {
|
||||
flex: 1 1 300px;
|
||||
}
|
||||
.soup .action-buttons {
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.soup .action {
|
||||
font-size: 12px;
|
||||
white-space: normal;
|
||||
max-width: 340px;
|
||||
line-height: 1.4;
|
||||
padding: 10px 13px;
|
||||
}
|
||||
.action > svg {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
flex: none;
|
||||
}
|
||||
.action > small {
|
||||
font-size: 10px;
|
||||
opacity: 0.75;
|
||||
}
|
||||
.action.primary .food-amount {
|
||||
color: #f2f6d8;
|
||||
}
|
||||
.game-message {
|
||||
color: #9a4636;
|
||||
font-size: 12px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
.amoeba-picker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 12px;
|
||||
margin-top: 14px;
|
||||
gap: 8px;
|
||||
}
|
||||
.amoeba-picker select {
|
||||
font: inherit;
|
||||
color: var(--ink);
|
||||
border: 1px solid #c8d7b5;
|
||||
border-radius: 6px;
|
||||
background: #fffcf3;
|
||||
padding: 5px 14px;
|
||||
}
|
||||
.soup dialog {
|
||||
max-width: 870px;
|
||||
max-height: 85dvh;
|
||||
overflow: auto;
|
||||
}
|
||||
.soup .shop-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 15px;
|
||||
}
|
||||
.soup .shop-art {
|
||||
height: 105px;
|
||||
}
|
||||
.soup .shop-body h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
.soup .shop-body p {
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: #64795e;
|
||||
}
|
||||
.gene-price {
|
||||
font-size: 10px;
|
||||
color: #75875f;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.shop-body > small {
|
||||
font-size: 10px;
|
||||
margin-bottom: 12px;
|
||||
color: #7b846e;
|
||||
}
|
||||
.gene-unavailable {
|
||||
font-size: 11px;
|
||||
color: #8d9883;
|
||||
}
|
||||
.soup .journal-list {
|
||||
max-height: 65dvh;
|
||||
}
|
||||
.soup .journal-list li {
|
||||
font-size: 13px;
|
||||
}
|
||||
.results-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
.results-list li {
|
||||
display: flex;
|
||||
gap: 18px;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid var(--line);
|
||||
padding: 8px;
|
||||
}
|
||||
.results-list svg {
|
||||
width: 55px;
|
||||
height: 55px;
|
||||
}
|
||||
.results-list li > b {
|
||||
margin-left: auto;
|
||||
font: 30px "Lilita One";
|
||||
}
|
||||
.tutorial-slot:empty {
|
||||
display: none;
|
||||
}
|
||||
.bgs-tutorial-guide {
|
||||
padding: 14px 18px;
|
||||
border: 1px solid #d0dcc0;
|
||||
border-left: 4px solid #7da75d;
|
||||
border-radius: 10px;
|
||||
background: #fbfceef5;
|
||||
margin: 10px 0 0;
|
||||
}
|
||||
.bgs-tutorial-heading {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.bgs-tutorial-heading strong {
|
||||
font-size: 15px;
|
||||
}
|
||||
.bgs-tutorial-guide p {
|
||||
margin: 8px 0 10px;
|
||||
max-width: 1000px;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.bgs-tutorial-guide button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
border: 1px solid #bfceb0;
|
||||
background: #f9fbed;
|
||||
border-radius: 6px;
|
||||
padding: 6px 9px;
|
||||
font-size: 12px;
|
||||
min-height: 33px;
|
||||
}
|
||||
.bgs-tutorial-controls,
|
||||
.bgs-tutorial-playback,
|
||||
.bgs-tutorial-help {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.bgs-tutorial-controls {
|
||||
justify-content: space-between;
|
||||
}
|
||||
.bgs-tutorial-guide small {
|
||||
display: block;
|
||||
font-size: 10px;
|
||||
color: #8a977a;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.bgs-tutorial-highlight {
|
||||
outline: 3px solid #bb892d;
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.bgs-tutorial-feedback {
|
||||
color: #4f7941;
|
||||
font-weight: 600;
|
||||
}
|
||||
.bgs-tutorial-guide [role="alert"] {
|
||||
color: #a04630;
|
||||
}
|
||||
.bgs-tutorial-guide [hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
.bgs-tutorial-next-chapter svg {
|
||||
flex: none;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .board {
|
||||
height: clamp(375px, calc(100dvh - 500px), 580px);
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .specimen {
|
||||
height: 80px;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) #selected-portrait {
|
||||
width: 90px;
|
||||
}
|
||||
.practice-nav {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 14px;
|
||||
padding: 10px;
|
||||
background: #234c44;
|
||||
color: #f9f6dc;
|
||||
font:
|
||||
12px "DM Sans",
|
||||
sans-serif;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.practice-nav a {
|
||||
color: inherit;
|
||||
}
|
||||
.practice-nav select,
|
||||
.practice-nav button {
|
||||
font: inherit;
|
||||
background: #fff1;
|
||||
color: inherit;
|
||||
border: 1px solid #ffffff50;
|
||||
border-radius: 4px;
|
||||
padding: 5px 8px;
|
||||
}
|
||||
.practice-nav select option {
|
||||
color: #234c44;
|
||||
background: #f8f8eb;
|
||||
}
|
||||
@media (max-width: 1000px) {
|
||||
.soup .play-area {
|
||||
grid-template-columns: minmax(0, 1fr) 230px;
|
||||
gap: 15px;
|
||||
}
|
||||
.soup .board {
|
||||
height: 430px;
|
||||
}
|
||||
.soup .food-amount {
|
||||
font-size: 9px;
|
||||
}
|
||||
.soup .nutrients {
|
||||
gap: 3px;
|
||||
}
|
||||
.soup .colony-heading h2 {
|
||||
font-size: 22px;
|
||||
}
|
||||
.soup .food-reserve {
|
||||
display: none;
|
||||
}
|
||||
.soup .player-stat {
|
||||
font-size: 10px;
|
||||
}
|
||||
.soup .gene-list {
|
||||
max-height: 190px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.soup {
|
||||
padding: 0 10px 14px;
|
||||
}
|
||||
.soup .topbar {
|
||||
height: 68px;
|
||||
}
|
||||
.soup .brand h1 {
|
||||
font-size: 23px;
|
||||
}
|
||||
.soup .brand > span {
|
||||
width: 35px;
|
||||
}
|
||||
.edition-tag {
|
||||
display: none;
|
||||
}
|
||||
.soup .players {
|
||||
gap: 4px;
|
||||
padding: 10px 0;
|
||||
}
|
||||
.soup .player {
|
||||
display: grid;
|
||||
padding: 7px 5px;
|
||||
}
|
||||
.soup .player-name {
|
||||
font-size: 10px;
|
||||
}
|
||||
.soup .player-stat {
|
||||
font-size: 8px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.soup .player-portrait {
|
||||
width: 29px;
|
||||
}
|
||||
.soup .player-score {
|
||||
font-size: 20px;
|
||||
}
|
||||
.soup .play-area {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
}
|
||||
.soup .pond-subtitle {
|
||||
font-size: 10px;
|
||||
}
|
||||
.soup .board,
|
||||
.soup:has(.bgs-tutorial-guide) .board {
|
||||
height: auto;
|
||||
aspect-ratio: 900/750;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
.soup .amoeba-button {
|
||||
height: 14%;
|
||||
width: 13%;
|
||||
}
|
||||
.soup .current-compass > div {
|
||||
font-size: 25px;
|
||||
line-height: 25px;
|
||||
}
|
||||
.soup .current-compass > span,
|
||||
.soup .current-compass > b {
|
||||
font-size: 6px;
|
||||
}
|
||||
.soup .current-compass small {
|
||||
font-size: 7px;
|
||||
}
|
||||
.soup .water-cell.valid:after {
|
||||
font-size: 7px;
|
||||
padding: 2px 4px;
|
||||
}
|
||||
.soup .water-cell .cell-coord {
|
||||
font-size: 7px;
|
||||
}
|
||||
.soup .food-amount {
|
||||
font-size: 8px;
|
||||
gap: 1px;
|
||||
}
|
||||
.food-amount > .food {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
.soup .nutrients {
|
||||
bottom: 7%;
|
||||
gap: 2px;
|
||||
}
|
||||
.soup .amoeba-number {
|
||||
height: 14px;
|
||||
min-width: 14px;
|
||||
width: 14px;
|
||||
font-size: 8px;
|
||||
}
|
||||
.soup .injury {
|
||||
font-size: 8px;
|
||||
}
|
||||
.soup-board-key > span {
|
||||
font-size: 6px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.soup-board-key > b {
|
||||
font-size: 31px;
|
||||
}
|
||||
.soup-board-key > small {
|
||||
font-size: 7px;
|
||||
}
|
||||
.soup .pond-bottom {
|
||||
padding: 3px 5px 9px;
|
||||
}
|
||||
.soup .last-move {
|
||||
font-size: 10px;
|
||||
}
|
||||
.soup .colony-panel {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
padding: 12px 5px;
|
||||
gap: 9px 16px;
|
||||
}
|
||||
.soup .specimen,
|
||||
.soup .specimen-heading,
|
||||
.soup .diet {
|
||||
display: none;
|
||||
}
|
||||
.soup .colony-heading {
|
||||
grid-column: 1;
|
||||
grid-row: 1;
|
||||
}
|
||||
.soup .colony-heading h2 {
|
||||
font-size: 20px;
|
||||
max-width: 105px;
|
||||
}
|
||||
.soup .gene-heading {
|
||||
grid-column: 2;
|
||||
grid-row: 1;
|
||||
margin: 0;
|
||||
}
|
||||
.soup .gene-list {
|
||||
grid-column: 2;
|
||||
grid-row: 2 / span 2;
|
||||
max-height: 140px;
|
||||
}
|
||||
.soup .gene {
|
||||
padding: 5px !important;
|
||||
gap: 6px;
|
||||
}
|
||||
.soup .gene-art {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
}
|
||||
.soup .gene-art svg {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
.soup .gene p {
|
||||
display: none;
|
||||
}
|
||||
.soup .colony-metrics {
|
||||
grid-column: 1;
|
||||
grid-row: 2;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 0;
|
||||
}
|
||||
.amoeba-picker {
|
||||
grid-column: 1;
|
||||
margin: 0;
|
||||
font-size: 10px;
|
||||
}
|
||||
.soup .turnbar {
|
||||
bottom: 5px;
|
||||
padding: 10px;
|
||||
gap: 8px;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.soup .turn-details {
|
||||
flex: 1 1 210px;
|
||||
}
|
||||
.soup .phase-label {
|
||||
font-size: 12px;
|
||||
}
|
||||
.phase-instruction {
|
||||
font-size: 11px;
|
||||
}
|
||||
.soup .action-buttons {
|
||||
justify-content: flex-start;
|
||||
max-height: 160px;
|
||||
overflow: auto;
|
||||
width: auto;
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
.soup .action {
|
||||
flex: initial;
|
||||
min-height: 38px;
|
||||
padding: 8px 10px;
|
||||
font-size: 11px;
|
||||
}
|
||||
.soup .action .food-amount {
|
||||
font-size: 11px;
|
||||
}
|
||||
.soup dialog {
|
||||
padding: 24px 18px;
|
||||
}
|
||||
.soup .shop-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.soup .shop-card {
|
||||
grid-template-columns: 75px 1fr;
|
||||
}
|
||||
.soup .shop-art {
|
||||
height: auto;
|
||||
}
|
||||
.soup .shop-art svg {
|
||||
width: 70px;
|
||||
}
|
||||
.soup .shop-body h3 {
|
||||
font-size: 14px;
|
||||
}
|
||||
.bgs-tutorial-guide {
|
||||
padding: 10px 12px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
.bgs-tutorial-guide p {
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.bgs-tutorial-heading strong {
|
||||
font-size: 13px;
|
||||
}
|
||||
.bgs-tutorial-guide small {
|
||||
font-size: 9px;
|
||||
}
|
||||
.utilities .quiet-button {
|
||||
font-size: 10px;
|
||||
}
|
||||
.soup .empty-genes {
|
||||
font-size: 10px;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1001px) and (max-height: 850px) {
|
||||
.soup:has(.bgs-tutorial-guide) .topbar {
|
||||
height: 60px;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .players {
|
||||
padding: 7px 0;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .player {
|
||||
padding: 8px;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .board {
|
||||
height: clamp(300px, calc(100dvh - 420px), 430px);
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .pond-toolbar {
|
||||
min-height: 25px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .specimen {
|
||||
display: none;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .specimen-heading {
|
||||
margin-top: 12px;
|
||||
}
|
||||
.soup:has(.bgs-tutorial-guide) .turnbar {
|
||||
padding: 9px 13px;
|
||||
margin-top: 7px;
|
||||
}
|
||||
.bgs-tutorial-guide {
|
||||
padding: 9px 14px;
|
||||
}
|
||||
.bgs-tutorial-guide p {
|
||||
line-height: 1.5;
|
||||
margin: 6px 0;
|
||||
}
|
||||
}
|
||||
486
viewer/tutorials.js
Normal file
486
viewer/tutorials.js
Normal file
|
|
@ -0,0 +1,486 @@
|
|||
import * as E from "../engine/index.js";
|
||||
export const chapterMetadata = [
|
||||
{
|
||||
id: "drift",
|
||||
version: 1,
|
||||
title: "A little life in the soup",
|
||||
description:
|
||||
"Drift with the current, feed your first amoeba and recognise the food colours.",
|
||||
},
|
||||
{
|
||||
id: "swim",
|
||||
version: 1,
|
||||
title: "Swimming against the current",
|
||||
description:
|
||||
"Spend a biological point, roll for movement and choose a destination.",
|
||||
},
|
||||
{
|
||||
id: "division",
|
||||
version: 1,
|
||||
title: "Grow your colony",
|
||||
description:
|
||||
"Receive income, place newborn amoebas and understand where they can go.",
|
||||
},
|
||||
{
|
||||
id: "genes",
|
||||
version: 1,
|
||||
title: "Evolve new genes",
|
||||
description:
|
||||
"Buy abilities for your whole colony and balance their mutation sensitivity.",
|
||||
},
|
||||
{
|
||||
id: "environment",
|
||||
version: 1,
|
||||
title: "When the ozone layer thins",
|
||||
description:
|
||||
"Protect genes with BP or give up an adaptation when the environment changes.",
|
||||
},
|
||||
{
|
||||
id: "survival",
|
||||
version: 1,
|
||||
title: "Survival and evolution",
|
||||
description:
|
||||
"Resolve injuries, recycle nutrients and see how the score advances.",
|
||||
},
|
||||
{
|
||||
id: "movement-genes",
|
||||
version: 1,
|
||||
title: "From dice to directions",
|
||||
description:
|
||||
"Upgrade Movement I to Movement II and take control of swimming.",
|
||||
},
|
||||
{
|
||||
id: "feeding-genes",
|
||||
version: 1,
|
||||
title: "A different diet",
|
||||
description:
|
||||
"Combine Frugality and Substitution to survive when food colours are missing.",
|
||||
},
|
||||
{
|
||||
id: "interactions",
|
||||
version: 1,
|
||||
title: "Sharing a tiny world",
|
||||
description:
|
||||
"Use Holding to follow another amoeba, and Tentacle to carry nutrients.",
|
||||
},
|
||||
{
|
||||
id: "attacks",
|
||||
version: 1,
|
||||
title: "A struggle for survival",
|
||||
description:
|
||||
"Feed by attacking, and learn how Defense, Escape and Armor can protect a colony.",
|
||||
},
|
||||
];
|
||||
export function prepared({
|
||||
players = 4,
|
||||
phase = 0,
|
||||
genes = [],
|
||||
bp = 12,
|
||||
round = 2,
|
||||
amoebas,
|
||||
task,
|
||||
seed = "learn-soup",
|
||||
} = {}) {
|
||||
const s = E.init(players, [], {}, seed);
|
||||
s.round = round;
|
||||
s.phase = phase;
|
||||
s.players.forEach((p, i) => {
|
||||
p.name = ["You", "Maya", "Leo", "Nina"][i];
|
||||
p.score = [4, 3, 2, 1][i];
|
||||
p.bp = 6;
|
||||
});
|
||||
s.players[0].bp = bp;
|
||||
s.players[0].genes = genes.map((id) => ({ id, round: 1 }));
|
||||
s.amoebas = amoebas ?? [
|
||||
{ id: "0-1", p: 0, n: 1, cell: 6, hp: 0 },
|
||||
{ id: "0-2", p: 0, n: 2, cell: 21, hp: 0 },
|
||||
{ id: "1-1", p: 1, n: 1, cell: 8, hp: 0 },
|
||||
{ id: "2-1", p: 2, n: 1, cell: 18, hp: 0 },
|
||||
...(players === 4 ? [{ id: "3-1", p: 3, n: 1, cell: 23, hp: 0 }] : []),
|
||||
];
|
||||
s.environment = { ozone: 8, direction: 2 };
|
||||
s.tasks = task
|
||||
? [task]
|
||||
: [
|
||||
{ kind: "movement", a: "0-1" },
|
||||
{ kind: "movement", a: "0-2" },
|
||||
];
|
||||
s.log = [];
|
||||
s.history = [];
|
||||
s.lastCells = [];
|
||||
return s;
|
||||
}
|
||||
const step = (
|
||||
id,
|
||||
title,
|
||||
text,
|
||||
complete,
|
||||
validateMove,
|
||||
target = "actions",
|
||||
success = "",
|
||||
) => ({ id, title, text, complete, validateMove, target, success });
|
||||
const only =
|
||||
(...types) =>
|
||||
(s, m) =>
|
||||
types.includes(m.type)
|
||||
? undefined
|
||||
: "Try the action described in this step first.";
|
||||
const move = (s, m) => E.move(s, m, 0);
|
||||
const config = (
|
||||
id,
|
||||
initialState,
|
||||
steps,
|
||||
completionText,
|
||||
customMove = move,
|
||||
) => ({
|
||||
game: "primordial-soup",
|
||||
id,
|
||||
version: 1,
|
||||
initialState,
|
||||
move: customMove,
|
||||
steps,
|
||||
completion: {
|
||||
title: "A little wiser. A little more evolved.",
|
||||
text: completionText,
|
||||
},
|
||||
});
|
||||
export const chapters = {
|
||||
drift: config(
|
||||
"drift",
|
||||
() => prepared({ round: 1, bp: 4 }),
|
||||
[
|
||||
step(
|
||||
"welcome",
|
||||
"A little life in the soup",
|
||||
"You are the green colony. Grow your population and evolve genes to advance along the evolution track. Highest score wins. These short lessons use prepared positions so you can learn one idea at a time.",
|
||||
undefined,
|
||||
undefined,
|
||||
"colonies",
|
||||
),
|
||||
step(
|
||||
"drift",
|
||||
"Go with the flow",
|
||||
"The arrow on the island points east. Your amoebas act in number order. Amoeba #1 is selected: click C2 to drift there for free. You can also click the amoeba first, then its destination.",
|
||||
(s) => s.tasks[0]?.kind === "feeding",
|
||||
only("drift"),
|
||||
"board",
|
||||
"You drifted one space and kept all 4 BP.",
|
||||
),
|
||||
step(
|
||||
"food",
|
||||
"Eat other colours",
|
||||
"With four colonies, an amoeba eats one nutrient of each other colour: coral, blue and gold. It never eats green. Use Eat below; it will leave two green nutrients for the others.",
|
||||
(s) => s.history.some((h) => h.move.type === "eat"),
|
||||
only("eat"),
|
||||
"actions",
|
||||
"Your amoeba ate three nutrients and returned two green ones.",
|
||||
),
|
||||
],
|
||||
"Each amoeba moves and then feeds. Drift follows the current for free; at a shore or the island, it stays in place. With three colonies, a meal is two cubes of one other colour and one of the remaining colour.",
|
||||
),
|
||||
swim: config(
|
||||
"swim",
|
||||
() => prepared({ bp: 4, round: 1, seed: "swimming-lesson" }),
|
||||
[
|
||||
step(
|
||||
"choose",
|
||||
"A little effort",
|
||||
"To try another direction, use Swim. It costs 1 biological point (BP). Without movement genes, a die chooses the direction: 1 west, 2 north, 3 east, 4 south, 5 stay, 6 choose.",
|
||||
(s) => s.tasks[0]?.kind === "direction",
|
||||
only("swim"),
|
||||
"actions",
|
||||
),
|
||||
step(
|
||||
"destination",
|
||||
"Read the die, then the board",
|
||||
"Your roll is shown below. Click a highlighted destination. A blocked direction means staying here; a 6 lets you choose a direction. You pay the BP even if you stay.",
|
||||
(s) => s.tasks[0]?.kind === "feeding",
|
||||
only("direction"),
|
||||
"board",
|
||||
),
|
||||
step(
|
||||
"eat",
|
||||
"Movement comes before dinner",
|
||||
"Feed using the ordinary Eat control. If the right food is unavailable, an amoeba eats nothing, leaves nothing and receives one injury.",
|
||||
(s) =>
|
||||
s.history.some(
|
||||
(h) => h.move.type === "eat" || h.move.type === "starve",
|
||||
),
|
||||
only("eat", "starve"),
|
||||
"actions",
|
||||
),
|
||||
],
|
||||
"Movement I lets you choose between two dice. Movement II lets you choose a direction without rolling. Streamline removes the BP cost. Speed adds an optional second swim, then you feed once.",
|
||||
),
|
||||
division: config(
|
||||
"division",
|
||||
() => prepared({ phase: 3, bp: 14, task: { kind: "division", p: 0 } }),
|
||||
[
|
||||
step(
|
||||
"income",
|
||||
"Time to multiply",
|
||||
"During cell division, each colony receives 10 BP. This position has 14 BP: 4 saved plus 10 income. A new amoeba costs 6 BP. Click a highlighted space next to one of your green amoebas.",
|
||||
(s) => E.colony(s, 0).length === 3,
|
||||
only("divide"),
|
||||
"board",
|
||||
"A newborn has no injuries and its own number.",
|
||||
),
|
||||
step(
|
||||
"another",
|
||||
"Grow from a newborn",
|
||||
"You have 8 BP left, enough for another amoeba. A new amoeba may be placed next to the one you just created. It cannot share a space with another green amoeba. Place one more.",
|
||||
(s) => E.colony(s, 0).length === 4,
|
||||
only("divide"),
|
||||
"board",
|
||||
),
|
||||
step(
|
||||
"finish",
|
||||
"Keep the rest",
|
||||
"You may create as many amoebas as you can afford, up to seven. Finish with Done to keep your remaining 2 BP.",
|
||||
(s) => s.history.some((h) => h.move.type === "done"),
|
||||
only("done"),
|
||||
"actions",
|
||||
),
|
||||
],
|
||||
"Division Rate reduces the cost to 4 BP; Spores allows any space without your colour. If only one amoeba survives, its second may go anywhere for the normal price. If your colony is extinct, the first returns anywhere for free.",
|
||||
),
|
||||
genes: config(
|
||||
"genes",
|
||||
() => prepared({ phase: 2, bp: 12, task: { kind: "genes", p: 0 } }),
|
||||
[
|
||||
step(
|
||||
"buy",
|
||||
"An adaptation for the whole colony",
|
||||
"Open Evolve genes and buy Movement I for 3 BP. It affects all your amoebas: when swimming, roll two dice and choose either result.",
|
||||
(s) => E.has(s, 0, "movement1"),
|
||||
(s, m) =>
|
||||
m.type === "buy" && m.gene === "movement1"
|
||||
? undefined
|
||||
: "For this lesson, choose Movement I in the gene pool.",
|
||||
"genes",
|
||||
"Movement I costs 3 BP and adds 2 mutation sensitivity.",
|
||||
),
|
||||
step(
|
||||
"mutation",
|
||||
"Power comes with sensitivity",
|
||||
"The sun number on a gene is its mutation sensitivity. Add these numbers across your genes and compare them with the ozone layer. A thinner layer can force you to pay BP or lose genes next round.",
|
||||
undefined,
|
||||
undefined,
|
||||
"colony",
|
||||
),
|
||||
step(
|
||||
"finish",
|
||||
"One shopping turn",
|
||||
"The highest-scoring colony buys genes first. Copies are limited, and you cannot own duplicates. You may buy several in one turn; for now choose Done.",
|
||||
(s) => s.history.some((h) => h.move.type === "done"),
|
||||
only("done"),
|
||||
),
|
||||
],
|
||||
"Genes change the basic rules. Open any gene you own, or the gene pool, to read its full effect. Most count once for evolution; advanced genes count twice and Ray Protection does not count.",
|
||||
),
|
||||
environment: config(
|
||||
"environment",
|
||||
() => {
|
||||
const s = prepared({
|
||||
phase: 1,
|
||||
bp: 2,
|
||||
genes: ["movement1", "intelligence", "longevity"],
|
||||
task: { kind: "defect", p: 0, debt: 4 },
|
||||
});
|
||||
s.environment.ozone = 6;
|
||||
return s;
|
||||
},
|
||||
[
|
||||
step(
|
||||
"exposure",
|
||||
"A thinner ozone layer",
|
||||
"Your three genes have mutation 2 + 3 + 5 = 10. The new ozone layer is 6, leaving a difference of 4. You only have 2 BP, so you must return at least one gene. Give up Intelligence (mutation 3).",
|
||||
(s) => !E.has(s, 0, "intelligence"),
|
||||
(s, m) =>
|
||||
m.type === "discard" && m.gene === "intelligence"
|
||||
? undefined
|
||||
: "Give up Intelligence to reduce the difference from 4 to 1.",
|
||||
"actions",
|
||||
),
|
||||
step(
|
||||
"pay",
|
||||
"Protect what remains",
|
||||
"Now your mutation is 7 against ozone 6. Pay 1 BP to keep Movement I and Longevity. Returned genes become available in the gene pool again.",
|
||||
(s) => s.history.some((h) => h.move.type === "pay-defect"),
|
||||
only("pay-defect"),
|
||||
),
|
||||
],
|
||||
"Every round reveals a new environment card after movement. Its current applies next round; its ozone layer applies immediately. There are no gene defects during round one. Ray Protection reduces your mutation by 2.",
|
||||
),
|
||||
survival: config(
|
||||
"survival",
|
||||
() => {
|
||||
const s = prepared({ phase: 3, bp: 0, task: { kind: "division", p: 0 } });
|
||||
s.players[0].score = 8;
|
||||
s.amoebas = s.amoebas.filter((a) => a.p !== 0);
|
||||
for (let n = 1; n <= 5; n++)
|
||||
s.amoebas.push({
|
||||
id: `0-${n}`,
|
||||
p: 0,
|
||||
n,
|
||||
cell: [6, 7, 11, 16, 17][n - 1],
|
||||
hp: n === 2 ? 2 : n === 1 ? 1 : 0,
|
||||
});
|
||||
return s;
|
||||
},
|
||||
[
|
||||
step(
|
||||
"injuries",
|
||||
"Some scars stay with you",
|
||||
"Green amoeba #2 has two injuries. #1 has one. Injuries are not healed by eating. Choose Done to finish division and resolve survival.",
|
||||
(s) => !E.amoeba(s, "0-2"),
|
||||
only("done"),
|
||||
"board",
|
||||
"The amoeba with two injuries died; the one with one injury survived.",
|
||||
),
|
||||
step(
|
||||
"scoring",
|
||||
"Four survivors advance two spaces",
|
||||
"A dead amoeba leaves two nutrients of every colour, if available. Your four survivors earn 2 evolution spaces. Genes can add more. Scoring starts with the leader, and occupied scores are jumped over without using a step.",
|
||||
undefined,
|
||||
undefined,
|
||||
"colonies",
|
||||
),
|
||||
],
|
||||
"Population scoring: 0–2 / 3 / 4 / 5 / 6 / 7 amoebas → 0 / 1 / 2 / 4 / 5 / 6 spaces. Gene scoring: 0–2 / 3 / 4 / 5 / 6+ genes → 0 / 1 / 2 / 3 / 4. Finish the round when someone reaches 42 or the last environment card is drawn; highest score wins.",
|
||||
),
|
||||
"movement-genes": config(
|
||||
"movement-genes",
|
||||
() =>
|
||||
prepared({
|
||||
phase: 2,
|
||||
bp: 10,
|
||||
genes: ["movement1"],
|
||||
task: { kind: "genes", p: 0 },
|
||||
}),
|
||||
[
|
||||
step(
|
||||
"upgrade",
|
||||
"An advanced gene",
|
||||
"Movement I was bought in a previous round. Open the gene pool and buy Movement II for 5 BP. It replaces Movement I; you cannot buy both in the same round.",
|
||||
(s) => E.has(s, 0, "movement2"),
|
||||
(s, m) =>
|
||||
m.type === "buy" && m.gene === "movement2"
|
||||
? undefined
|
||||
: "Choose Movement II in the gene pool.",
|
||||
"genes",
|
||||
),
|
||||
step(
|
||||
"double",
|
||||
"Count the new gene correctly",
|
||||
"You now choose a swimming direction without rolling. The move still costs 1 BP. Movement II counts as two genes for evolution and has mutation 5. It does not include Streamline or Speed.",
|
||||
undefined,
|
||||
undefined,
|
||||
"genes",
|
||||
),
|
||||
],
|
||||
"Advanced genes replace a prerequisite owned since an earlier round. Persistence replaces Speed; Aggression replaces Struggle for Survival; Armor replaces Defense or Escape. Read the new card's effect — it is not always the same ability with a bonus.",
|
||||
),
|
||||
"feeding-genes": config(
|
||||
"feeding-genes",
|
||||
() => {
|
||||
const s = prepared({
|
||||
genes: ["frugality", "substitution"],
|
||||
task: { kind: "feeding", a: "0-1" },
|
||||
});
|
||||
for (let p = 0; p < 4; p++) {
|
||||
s.supply[p] += s.food[6][p];
|
||||
s.food[6][p] = 0;
|
||||
}
|
||||
s.food[6][1] = 3;
|
||||
s.supply[1] -= 3;
|
||||
return s;
|
||||
},
|
||||
[
|
||||
step(
|
||||
"diet",
|
||||
"One colour can be enough",
|
||||
"Only three coral nutrients are here. Normally, your green amoeba would starve. Frugality reduces its meal by one cube, and Substitution allows a missing colour in exchange for one extra cube. Together, they allow three cubes of a single other colour. Use Eat.",
|
||||
(s) => s.history.some((h) => h.move.type === "eat"),
|
||||
only("eat"),
|
||||
"actions",
|
||||
"You fed on three coral nutrients and still left two green ones.",
|
||||
),
|
||||
step(
|
||||
"choice",
|
||||
"Genes create choices",
|
||||
"Feeding adaptations are optional. If several meals are legal, choose the one that leaves useful food on the board. Parasitism lets you eat one fewer cube by making an opponent in your space pay 1 BP.",
|
||||
undefined,
|
||||
undefined,
|
||||
"genes",
|
||||
),
|
||||
],
|
||||
"Other genes can help you reach food, carry it with Tentacle, or survive an extra injury with Longevity. Your food is someone else's dinner: all colonies share the same supply.",
|
||||
),
|
||||
interactions: config(
|
||||
"interactions",
|
||||
() => {
|
||||
const s = prepared({
|
||||
genes: ["holding", "tentacle"],
|
||||
task: { kind: "follow", a: "0-1", from: 6, to: 7 },
|
||||
});
|
||||
s.amoebas.find((a) => a.id === "1-1").cell = 7;
|
||||
return s;
|
||||
},
|
||||
[
|
||||
step(
|
||||
"ride",
|
||||
"A free ride with Holding",
|
||||
"Maya's amoeba has just left your space for C2. Your Holding gene lets amoeba #1 follow for free, even outside your own movement turn. Choose Follow.",
|
||||
(s) => s.tasks[0]?.kind === "carry",
|
||||
only("follow"),
|
||||
"actions",
|
||||
),
|
||||
step(
|
||||
"cargo",
|
||||
"Bring dinner with Tentacle",
|
||||
"Tentacle lets you bring up to three nutrients in a four-colony game (two with three colonies). Pick a nutrient, then use Ready · move. Picking up food is optional.",
|
||||
(s) => E.amoeba(s, "0-1").cell === 7,
|
||||
only("carry", "return-food", "travel"),
|
||||
"actions",
|
||||
),
|
||||
],
|
||||
"Holding can also keep you still instead of drifting. Following does not use your normal movement turn. Tentacle works when drifting, swimming or escaping; you can carry your own colour too.",
|
||||
),
|
||||
attacks: config(
|
||||
"attacks",
|
||||
() => {
|
||||
const s = prepared({
|
||||
genes: ["struggle"],
|
||||
task: { kind: "feeding", a: "0-1" },
|
||||
seed: "hunt-lesson",
|
||||
});
|
||||
s.amoebas.find((a) => a.id === "1-1").cell = 6;
|
||||
for (let p = 0; p < 4; p++) {
|
||||
s.supply[p] += s.food[6][p];
|
||||
s.food[6][p] = 0;
|
||||
}
|
||||
return s;
|
||||
},
|
||||
[
|
||||
step(
|
||||
"hungry",
|
||||
"A last resort",
|
||||
"Amoeba #1 cannot feed here. Struggle for Survival lets it spend 1 BP to attack another amoeba in the same space. Attack Maya's amoeba.",
|
||||
(s) => !E.amoeba(s, "1-1"),
|
||||
only("attack"),
|
||||
"actions",
|
||||
"The attack fed your amoeba. One nutrient of each colour returns to the space.",
|
||||
),
|
||||
step(
|
||||
"protection",
|
||||
"The other colony can respond",
|
||||
"Defense costs 1 BP: both sides roll, with the higher roll winning. Escape attempts a swim away using movement genes. Armor prevents being eaten. Aggression allows one attack after natural deaths; Armor turns that attack into one injury.",
|
||||
undefined,
|
||||
undefined,
|
||||
"genes",
|
||||
),
|
||||
],
|
||||
"Attacks and defenses use the regular game controls, including responses during another colony's turn. Persistence offers a second attempt after failure. All gene descriptions remain available in the gene pool.",
|
||||
),
|
||||
};
|
||||
415
viewer/ui.js
Normal file
415
viewer/ui.js
Normal file
|
|
@ -0,0 +1,415 @@
|
|||
import {
|
||||
COLORS,
|
||||
COLOR_NAMES,
|
||||
CELLS,
|
||||
GENES,
|
||||
GENE,
|
||||
DIRECTIONS,
|
||||
PHASES,
|
||||
coordinate,
|
||||
} from "../engine/catalog.js";
|
||||
import {
|
||||
colony,
|
||||
mutation,
|
||||
evolution,
|
||||
geneCount,
|
||||
amoeba as findAmoeba,
|
||||
} from "../engine/index.js";
|
||||
import { amoeba, icon, colors } from "./art.js";
|
||||
import { pondArt } from "./pond.js";
|
||||
export const RULES_URL =
|
||||
"https://s3.fr-par.scw.cloud/bgs-assets/assets/primordial-soup/rules-en/69e877694adc4a15/rules-en.pdf";
|
||||
export const esc = (x) =>
|
||||
String(x ?? "").replace(
|
||||
/[&<>"']/g,
|
||||
(c) =>
|
||||
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[
|
||||
c
|
||||
],
|
||||
);
|
||||
const food = (p, n = 1) =>
|
||||
`<span class="food-amount" role="img" aria-label="${n} ${COLOR_NAMES[p].toLowerCase()} nutrient${n === 1 ? "" : "s"}" title="${n} ${COLOR_NAMES[p].toLowerCase()} nutrient${n === 1 ? "" : "s"}"><span class="food ${COLORS[p]}" aria-hidden="true"></span><span>${n}</span></span>`;
|
||||
const nutrients = (vector) =>
|
||||
vector.map((n, p) => (n ? food(p, n) : "")).join("");
|
||||
export function moveLabel(m, s) {
|
||||
const t = s.tasks[0],
|
||||
a = findAmoeba(s, t?.a);
|
||||
const ref = (id) => {
|
||||
const b = findAmoeba(s, id);
|
||||
return b ? `${esc(s.players[b.p].name)} #${b.n}` : "amoeba";
|
||||
};
|
||||
switch (m.type) {
|
||||
case "score":
|
||||
return `Start at ${m.score}`;
|
||||
case "place":
|
||||
return `Place #${m.n}`;
|
||||
case "drift":
|
||||
return `${m.cell === a?.cell ? "Stay" : "Drift"} · free`;
|
||||
case "hold":
|
||||
return "Hold position · free";
|
||||
case "swim":
|
||||
return `${icon("wave")} Swim ${s.players[s.actor].genes.some((g) => g.id === "movement2") ? "" : "· roll"} <small>${s.players[s.actor].genes.some((g) => g.id === "streamline") ? 0 : 1} BP</small>`;
|
||||
case "direction":
|
||||
return m.cell === a?.cell ? "Stay here" : DIRECTIONS[m.direction];
|
||||
case "carry":
|
||||
return `Carry ${food(m.color)}`;
|
||||
case "return-food":
|
||||
return `Put back ${food(m.color)}`;
|
||||
case "travel":
|
||||
return "Ready · move";
|
||||
case "follow":
|
||||
return `Follow to ${coordinate(t.to)} · free`;
|
||||
case "decline":
|
||||
return "Stay here";
|
||||
case "swim-again":
|
||||
return "Swim again · free";
|
||||
case "feed-now":
|
||||
return "Finish moving";
|
||||
case "eat":
|
||||
return `Eat ${nutrients(m.food)}${m.host === undefined ? "" : `<small>−1 BP for ${esc(s.players[m.host].name)}</small>`}`;
|
||||
case "starve":
|
||||
return `${icon("heart")} Take 1 injury`;
|
||||
case "pay-defect":
|
||||
return `Pay ${m.amount} BP`;
|
||||
case "discard":
|
||||
return `Give up ${GENE[m.gene].name}`;
|
||||
case "buy":
|
||||
return `Evolve · ${GENE[m.gene].cost} BP`;
|
||||
case "divide":
|
||||
return `New amoeba #${m.n}`;
|
||||
case "done":
|
||||
return "Done";
|
||||
case "attack":
|
||||
return `${m.attacker ? ref(m.attacker) + " → " : "Attack "}${ref(m.victim)} · 1 BP`;
|
||||
case "accept-attack":
|
||||
return "Accept attack";
|
||||
case "defend":
|
||||
return "Defend · 1 BP";
|
||||
case "escape":
|
||||
return `Escape · ${s.players[s.actor].genes.some((g) => g.id === "streamline") ? 0 : 1} BP`;
|
||||
case "retry-attack":
|
||||
return `Try again against ${ref(m.victim)} · free`;
|
||||
case "stop-attack":
|
||||
return "End attack";
|
||||
case "retry-defense":
|
||||
return "Defend again · free";
|
||||
case "accept-defense-roll":
|
||||
return "Keep this roll";
|
||||
default:
|
||||
return esc(m.type);
|
||||
}
|
||||
}
|
||||
function instruction(s, seat) {
|
||||
if (s.finished) return `${s.players[s.winner].name} wins!`;
|
||||
if (s.actor !== seat) return `Waiting for ${s.players[s.actor].name}.`;
|
||||
const t = s.tasks[0],
|
||||
a = findAmoeba(s, t.a);
|
||||
switch (t.kind) {
|
||||
case "setup-score":
|
||||
return "Choose a starting score. Lower scores move and feed first; higher scores buy genes first.";
|
||||
case "setup-place":
|
||||
return `Click an empty space for your ${s.phase === "setup-first" ? "first" : "second"} amoeba${t.injury ? " (starts with one injury)" : ""}.`;
|
||||
case "movement":
|
||||
return `Amoeba #${a.n} · Click the drift destination, or swim to roll for a direction.`;
|
||||
case "direction":
|
||||
return `Amoeba #${a.n} · ${s.players[a.p].genes.some((g) => g.id === "movement2") ? "Choose your direction." : `Rolled ${t.dice.join(" / ")}. Click a highlighted destination.`}`;
|
||||
case "feeding":
|
||||
return `Amoeba #${a.n} · ${s.moves.some((m) => m.type === "eat") ? "Choose a meal, then leave two nutrients of your colour." : "Not enough food here. This amoeba will take an injury unless it can hunt."}`;
|
||||
case "speed":
|
||||
return "Speed lets you swim once more, for free, before feeding.";
|
||||
case "carry":
|
||||
return `Tentacle · Pick up to ${t.limit} nutrients to carry, then move. ${t.cargo.length} selected.`;
|
||||
case "follow":
|
||||
return `Holding · Amoeba #${a.n} can follow to ${coordinate(t.to)} for free.`;
|
||||
case "defect":
|
||||
return `Your mutation sensitivity exceeds the ozone layer by ${t.debt}. Pay BP, give up genes, or combine both.`;
|
||||
case "genes":
|
||||
return "Evolve your colony with new genes, then choose Done.";
|
||||
case "division":
|
||||
return "You received 10 BP. Click a highlighted space to grow your colony, or finish with Done.";
|
||||
case "aggression":
|
||||
return "You may make one attack with Aggression, or finish with Done.";
|
||||
case "combat":
|
||||
return "One of your amoebas is being attacked. Choose how to respond.";
|
||||
case "retry-defense":
|
||||
return "Persistence gives you a second defense roll for free.";
|
||||
case "retry-attack":
|
||||
return "Persistence gives you a second attack for free.";
|
||||
default:
|
||||
return "Choose an action.";
|
||||
}
|
||||
}
|
||||
export function mountGame(
|
||||
target,
|
||||
{ onMove, onFullscreen, onOpenPlayer, practice = false } = {},
|
||||
) {
|
||||
const root = document.createElement("div");
|
||||
root.className = "soup game-shell";
|
||||
target.append(root);
|
||||
root.innerHTML = `<header class="topbar"><div class="brand"><span>${amoeba("green", 0)}</span><div><h1>primordial soup<span class="title-dot">.</span></h1><span class="byline">DORIS MATTHÄUS & FRANK NESTEL</span></div></div><span class="edition-tag">Private playtest</span><nav class="utilities" aria-label="Game options"><button class="quiet-button" data-ui="genes">${icon("spark")} Genes</button><button class="icon-button" data-ui="rules" aria-label="How to play">${icon("help")}</button><button class="icon-button" data-ui="fullscreen" aria-label="Fullscreen">${icon("expand")}</button></nav></header>
|
||||
<div class="tutorial-slot"></div><section class="players" aria-label="The colonies" data-tutorial="colonies"></section>
|
||||
<main class="play-area"><section class="pond-section" aria-label="Primordial soup board"><div class="pond-toolbar"><div><span class="eyebrow">A LITTLE LIFE IN A BIG SOUP</span><span class="pond-subtitle" id="turn-order"></span></div><button class="quiet-button" data-ui="journal">${icon("history")} Journal</button></div><div class="board-wrap"><div class="board" data-tutorial="board"><svg id="pond-art" viewBox="0 0 900 650" preserveAspectRatio="none" aria-hidden="true">${pondArt()}</svg><div class="cells"></div><div class="organisms"></div><div class="current-compass" data-tutorial="current"><span>CURRENT</span><div class="compass-arrow">➜</div><b class="compass-label"></b><small>Ozone <strong class="ozone"></strong></small></div><div class="soup-board-key"><span>EVOLUTION</span><b>42</b><small>Finish the round<br>when a colony reaches 42.</small></div></div></div><div class="pond-bottom"><span class="last-move" aria-live="polite"></span><span class="food-reserve" title="Food cubes remaining in the common supply"></span></div></section><aside class="colony-panel" data-tutorial="colony"></aside></main>
|
||||
<footer class="turnbar" data-tutorial="actions"><div class="round"><span>ROUND</span><strong class="round-number"></strong></div><div class="turn-details"><div class="phase-label"></div><div class="phase-instruction" aria-live="polite"></div><div class="phase-dots"></div></div><div class="action-buttons"></div></footer><div class="game-message" role="alert"></div>
|
||||
<dialog><button class="close-modal icon-button" data-ui="close" aria-label="Close">×</button><div class="modal-content"></div></dialog>`;
|
||||
const $ = (q) => root.querySelector(q),
|
||||
$$ = (q) => [...root.querySelectorAll(q)];
|
||||
let state,
|
||||
seat,
|
||||
selected,
|
||||
viewPlayer,
|
||||
number = 1,
|
||||
busy = false,
|
||||
locked = false,
|
||||
modalKind,
|
||||
oldTask;
|
||||
const dialog = $("dialog");
|
||||
const canAct = () =>
|
||||
!busy &&
|
||||
!locked &&
|
||||
!state?.finished &&
|
||||
seat !== undefined &&
|
||||
state?.actor === seat;
|
||||
const actions = () => (canAct() ? state.moves : []);
|
||||
const doMove = async (m) => {
|
||||
if (!canAct()) return;
|
||||
busy = true;
|
||||
$(".game-message").textContent = "";
|
||||
render();
|
||||
try {
|
||||
await onMove(m);
|
||||
} catch (e) {
|
||||
$(".game-message").textContent = e.message;
|
||||
} finally {
|
||||
busy = false;
|
||||
render();
|
||||
}
|
||||
};
|
||||
function actionButton(m, index, extra = "") {
|
||||
return `<button class="action ${m.type === "done" || m.type === "eat" ? "primary" : "secondary"} ${extra}" data-move="${index}">${moveLabel(m, state)}</button>`;
|
||||
}
|
||||
function render() {
|
||||
if (!state) return;
|
||||
const t = state.tasks[0],
|
||||
taskKey = JSON.stringify(t),
|
||||
actor = state.actor;
|
||||
if (oldTask !== taskKey) {
|
||||
oldTask = taskKey;
|
||||
if (t?.a) selected = t.a;
|
||||
viewPlayer = seat ?? actor ?? 0;
|
||||
}
|
||||
const a = findAmoeba(state, selected) ?? colony(state, viewPlayer ?? 0)[0];
|
||||
selected = a?.id;
|
||||
const shown = viewPlayer ?? seat ?? actor ?? 0,
|
||||
pl = state.players[shown];
|
||||
$(".players").style.gridTemplateColumns =
|
||||
`repeat(${state.players.length},1fr)`;
|
||||
$(".players").innerHTML = state.players
|
||||
.map(
|
||||
(p, i) =>
|
||||
`<button class="player ${i === actor ? "active" : ""}" data-player="${i}" style="--player:${colors[p.color].shade}"><span class="player-color"></span><span class="player-portrait">${amoeba(p.color, i)}</span><span class="player-info"><span class="player-name">${esc(p.name)}${i === seat && p.name !== "You" ? '<span class="you-tag">You</span>' : ""}</span><span class="player-stat">${p.bp} BP · ${colony(state, i).length} amoeba${colony(state, i).length === 1 ? "" : "s"} · ${geneCount(state, i)} genes</span></span><span class="player-score" title="Evolution points">${icon("spark")}${p.score}</span></button>`,
|
||||
)
|
||||
.join("");
|
||||
const positions = actions().filter((m) =>
|
||||
["place", "divide"].includes(m.type),
|
||||
);
|
||||
if (positions.length && !positions.some((m) => m.n === number))
|
||||
number = positions[0].n;
|
||||
const cellMoves = actions().filter(
|
||||
(m) =>
|
||||
["drift", "direction", "place", "divide"].includes(m.type) &&
|
||||
(!("n" in m) || m.n === number),
|
||||
);
|
||||
$(".cells").innerHTML = Array.from({ length: 25 }, (_, cell) => {
|
||||
if (!CELLS.includes(cell)) return '<span class="land-cell"></span>';
|
||||
const move = cellMoves.find((m) => m.cell === cell),
|
||||
last = state.lastCells.includes(cell);
|
||||
return `<button class="water-cell ${move ? "valid" : ""} ${move?.type === "drift" ? "drift" : ""} ${last ? "last-cell" : ""}" data-cell="${cell}" data-destination="${move ? esc(["place", "divide"].includes(move.type) ? `#${number}` : moveLabel(move, state)) : ""}" aria-label="Space ${coordinate(cell)}${move ? " · " + esc(moveLabel(move, state)) : ""}" ${move ? "" : 'aria-disabled="true"'}><span class="cell-coord">${coordinate(cell)}</span><span class="nutrients">${nutrients(state.food[cell])}</span></button>`;
|
||||
}).join("");
|
||||
$(".organisms").innerHTML = state.amoebas
|
||||
.map((a) => {
|
||||
const group = state.amoebas.filter((b) => b.cell === a.cell),
|
||||
i = group.indexOf(a),
|
||||
scale = group.length > 4 ? 0.55 : group.length > 2 ? 0.72 : 1,
|
||||
dx =
|
||||
((i % 3) - (Math.min(group.length, 3) - 1) / 2) *
|
||||
(group.length > 2 ? 37 : 45),
|
||||
dy = group.length > 3 ? Math.floor(i / 3) * 30 - 15 : 0;
|
||||
const hp = a.hp
|
||||
? `<span class="injury" title="${a.hp} injuries">${a.hp} ♥</span>`
|
||||
: "";
|
||||
return `<button class="amoeba-button ${selected === a.id ? "selected" : ""} ${t?.a === a.id ? "acting" : ""}" data-amoeba="${a.id}" aria-label="${esc(state.players[a.p].name)} amoeba #${a.n}, ${coordinate(a.cell)}${a.hp ? ", " + a.hp + " injuries" : ""}" aria-pressed="${selected === a.id}" style="left:${(60 + (a.cell % 5) * 156 + 78 + dx) / 9}%;top:${(55 + Math.floor(a.cell / 5) * 105 + 49 + dy) / 6.5}%;--scale:${scale};--delay:-${a.n * 0.7}s">${amoeba(COLORS[a.p], a.n, state.players[a.p].genes.some((g) => g.id === "armor") ? "shield" : "")}<span class="amoeba-number">${a.n}</span>${hp}</button>`;
|
||||
})
|
||||
.join("");
|
||||
const direction = state.environment.direction;
|
||||
$(".compass-arrow").textContent = direction === 4 ? "·" : "➜";
|
||||
$(".compass-arrow").style.transform =
|
||||
`rotate(${[180, 270, 0, 90, 0][direction]}deg)`;
|
||||
$(".compass-label").textContent = DIRECTIONS[direction].toUpperCase();
|
||||
$(".ozone").textContent = state.environment.ozone;
|
||||
$("#turn-order").textContent = state.finished
|
||||
? "A new branch on the tree of life."
|
||||
: `${state.deckRemaining} environment cards left · ${state.actor === seat ? "Your turn" : ` ${state.players[state.actor].name}'s turn`}`;
|
||||
$(".last-move").textContent = state.log.at(-1)?.text ?? "";
|
||||
$(".food-reserve").innerHTML =
|
||||
`<small>Supply</small>${nutrients(state.supply)}`;
|
||||
$(".colony-panel").innerHTML =
|
||||
`<div class="colony-heading"><div><span class="eyebrow">${shown === seat ? "YOUR COLONY" : "THE COLONY"}</span><h2>${esc(pl.name)}</h2></div><div class="bio-balance" data-tutorial="bp" title="Biological points">${icon("bio")}<strong>${pl.bp}</strong><span>BP</span></div></div><div class="specimen"><div class="specimen-orbit"></div><div id="selected-portrait">${amoeba(pl.color, a?.n ?? 1)}</div><span class="specimen-coord">${a ? coordinate(a.cell) : "—"}</span></div><div class="specimen-heading"><h3>${a ? `Amoeba #${a.n}` : "Ready to grow"}</h3><span class="health ${a?.hp ? "hurt" : ""}">${a?.hp ? `${a.hp} ${a.hp === 1 ? "injury" : "injuries"}` : "Feeling great"}</span></div><div class="diet"><span>Food colours</span><div>${state.players.map((_, p) => (p !== shown ? food(p) : "")).join("")}</div></div>${positions.length ? `<label class="amoeba-picker">New amoeba <select aria-label="Amoeba number">${[...new Set(positions.map((m) => m.n))].map((n) => `<option value="${n}" ${n === number ? "selected" : ""}>#${n}</option>`).join("")}</select></label>` : ""}<div class="gene-heading"><h3>Genes <span>${geneCount(state, shown)}</span></h3><button class="text-button" data-ui="genes">${t?.kind === "genes" && canAct() ? "Evolve ↗" : "Gene pool ↗"}</button></div><div class="gene-list" data-tutorial="genes">${pl.genes.map((g) => `<button class="gene" data-gene="${g.id}"><span class="gene-art">${icon(g.id === "movement1" || g.id === "movement2" ? "wave" : g.id === "division" ? "divide" : g.id === "armor" || g.id === "defense" ? "shield" : "spark")}</span><span class="gene-text"><strong>${GENE[g.id].name}</strong><p>${GENE[g.id].points === 2 ? "Advanced gene" : "Colony adaptation"}</p></span><span class="gene-sensitivity" title="Mutation sensitivity">${icon("sun")}${GENE[g.id].mutation}</span></button>`).join("") || '<p class="empty-genes">No genes yet. New abilities evolve in phase 3.</p>'}</div><div class="colony-metrics"><span>${icon("sun")} <strong>${mutation(state, shown)}</strong> mutation</span><span title="Evolution before any further division or deaths">${icon("spark")} <strong>+${evolution(state, shown)}</strong> evolution</span></div>`;
|
||||
$(".round-number").textContent = state.round || "—";
|
||||
$(".phase-label").textContent = state.finished
|
||||
? "Evolution complete"
|
||||
: typeof state.phase === "number"
|
||||
? `${state.phase + 1} / 6 · ${PHASES[state.phase]}`
|
||||
: "Life begins · Setup";
|
||||
$(".phase-instruction").textContent = instruction(state, seat);
|
||||
$(".phase-dots").innerHTML = PHASES.map(
|
||||
(p, i) =>
|
||||
`<span title="${i + 1}. ${p}" class="${typeof state.phase === "number" && i <= state.phase ? "active" : ""}"></span>`,
|
||||
).join("");
|
||||
$(".action-buttons").innerHTML =
|
||||
`${canAct() && t.kind === "genes" ? '<button class="action primary" data-ui="genes">' + icon("spark") + " Evolve genes</button>" : ""}${actions()
|
||||
.map((m, i) =>
|
||||
["place", "divide", "buy", "direction", "drift"].includes(m.type)
|
||||
? ""
|
||||
: actionButton(m, i),
|
||||
)
|
||||
.join(
|
||||
"",
|
||||
)}${state.finished ? '<button class="action primary" data-ui="results">Final scores</button>' : ""}`;
|
||||
if (dialog.open) renderModal();
|
||||
}
|
||||
function renderModal() {
|
||||
if (!state) return;
|
||||
let html = "";
|
||||
if (modalKind === "genes")
|
||||
html = `<span class="eyebrow">THE GENE POOL</span><h2>Little changes. New possibilities.</h2><p>Each gene affects your whole colony. ${canAct() && state.tasks[0].kind === "genes" ? `You have ${state.players[seat].bp} BP to evolve.` : "Buy genes during phase 3."}</p><div class="shop-grid">${GENES.filter(
|
||||
(g) => g.copies[state.players.length - 3],
|
||||
)
|
||||
.map((g) => {
|
||||
const held = state.players.reduce(
|
||||
(n, p) => n + p.genes.filter((x) => x.id === g.id).length,
|
||||
0,
|
||||
),
|
||||
remaining = g.copies[state.players.length - 3] - held;
|
||||
const moves = actions()
|
||||
.map((m, i) => ({ m, i }))
|
||||
.filter(({ m }) => m.type === "buy" && m.gene === g.id);
|
||||
return `<article class="shop-card" data-tutorial="gene-${g.id}"><div class="shop-art">${amoeba("green", g.cost, g.id.includes("movement") ? "movement" : g.id === "armor" ? "shield" : g.id === "frugality" ? "food" : "")}</div><div class="shop-body"><h3>${g.name}</h3><span class="gene-price">${g.cost} BP · ${g.mutation} mutation · ${remaining} left</span><p>${g.text}</p>${g.base.length ? `<small>Trade in ${g.base.map((id) => GENE[id].name).join(" or ")}, owned since a previous round.</small>` : ""}${moves.map(({ m, i }) => actionButton(m, i)).join("") || `<span class="gene-unavailable">${state.players[seat ?? 0].genes.some((x) => x.id === g.id) ? "Already owned" : !remaining ? "All copies owned" : g.base.length ? "Requires an earlier gene" : `${g.cost} BP`}</span>`}</div></article>`;
|
||||
})
|
||||
.join("")}</div>`;
|
||||
else if (modalKind === "journal")
|
||||
html = `<span class="eyebrow">LIFE IN THE SOUP</span><h2>Journal</h2><ol class="journal-list">${state.log
|
||||
.slice(-150)
|
||||
.reverse()
|
||||
.map(
|
||||
(l) =>
|
||||
`<li><small>Round ${l.round}</small><span>${esc(l.text)}</span></li>`,
|
||||
)
|
||||
.join("")}</ol>`;
|
||||
else if (modalKind === "results")
|
||||
html = `<h2>A little life goes a long way.</h2><p>${esc(state.players[state.winner]?.name ?? "")} wins.</p><ol class="results-list">${state.players
|
||||
.map((p, i) => ({ ...p, index: i }))
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.map(
|
||||
(p) =>
|
||||
`<li>${amoeba(p.color)}<strong>${esc(p.name)}</strong><b>${p.score}</b></li>`,
|
||||
)
|
||||
.join("")}</ol>`;
|
||||
else if (GENE[modalKind]) {
|
||||
const g = GENE[modalKind];
|
||||
html = `<div class="gene-explainer-art">${amoeba("green", g.cost)}</div><span class="eyebrow">${g.points === 2 ? "ADVANCED GENE" : "COLONY GENE"}</span><h2>${g.name}</h2><p>${g.text}</p><p>${g.cost} BP · ${g.mutation} mutation · counts as ${g.points} gene${g.points === 1 ? "" : "s"} for evolution.</p><div class="action-buttons">${actions()
|
||||
.map((m, i) =>
|
||||
m.type === "discard" && m.gene === g.id ? actionButton(m, i) : "",
|
||||
)
|
||||
.join("")}</div>`;
|
||||
} else
|
||||
html = `<span class="eyebrow">HOW LIFE WORKS</span><h2>Welcome to the soup.</h2><p>Grow your population and evolve genes. At the end of each round, advance along the evolution track. When a colony reaches 42 — or the last environment card is revealed — finish the round. The highest score wins.</p><p class="playtest-note">Private playtest: the exact printed environment-card distribution still needs verification. Full games currently use a provisional deck; tutorial positions are prepared.</p><div class="help-steps"><section><h3>1 · Move & feed</h3><p>Lowest score first; amoebas act in number order. Drift with the current for free, or pay 1 BP to swim: roll a die for direction. 1 west, 2 north, 3 east, 4 south, 5 stay, 6 choose. A blocked move stays in place.</p></section><section><h3>Food & injuries</h3><p>Eat three nutrients, never your own colour. With four colonies, eat one of each other colour; with three, eat two of one and one of the other. Leave two of your own. If you cannot eat, take one injury instead.</p></section><section><h3>2 · Environment</h3><p>A new card sets the next current and ozone layer. If your mutation exceeds the ozone, pay the difference in BP or discard genes. No defects in round one.</p></section><section><h3>3 · New genes</h3><p>Highest score first. Buy as many genes as you can afford. Advanced genes replace a prerequisite owned since a previous round.</p></section><section><h3>4 · Cell division</h3><p>Receive 10 BP. Each new amoeba costs 6 BP and goes next to one of yours, without sharing your colour's space. With one amoeba, the second may go anywhere. With none, the first returns anywhere for free.</p></section><section><h3>5 · Survival</h3><p>Two injuries cause death, or three with Longevity. Return two food cubes of every colour to that space. Aggression happens after natural deaths.</p></section><section><h3>6 · Evolution</h3><p>3 / 4 / 5 / 6 / 7 amoebas advance 1 / 2 / 4 / 5 / 6 spaces. 3 / 4 / 5 / 6+ genes add 1 / 2 / 3 / 4. Advanced genes count twice; Ray Protection does not count. Jump over occupied scores.</p></section><section><h3>Food supply</h3><p>There are 55 cubes of each colour. If the supply runs out, place only the cubes still available. Dead amoeba numbers may be used again.</p></section></div><p><a href="${RULES_URL}" target="_blank" rel="noopener">Read the original English rules (PDF) ↗</a></p>`;
|
||||
$(".modal-content").innerHTML = html;
|
||||
}
|
||||
function open(kind) {
|
||||
modalKind = kind;
|
||||
renderModal();
|
||||
if (!dialog.open) dialog.showModal();
|
||||
}
|
||||
root.addEventListener("click", (e) => {
|
||||
const el = e.target.closest("button");
|
||||
if (!el) return;
|
||||
if (el.dataset.move !== undefined) {
|
||||
void doMove(actions()[Number(el.dataset.move)]);
|
||||
return;
|
||||
}
|
||||
if (el.dataset.cell !== undefined) {
|
||||
const cell = Number(el.dataset.cell);
|
||||
const m = actions().find(
|
||||
(m) => m.cell === cell && (!("n" in m) || m.n === number),
|
||||
);
|
||||
if (m) void doMove(m);
|
||||
return;
|
||||
}
|
||||
if (el.dataset.amoeba) {
|
||||
const a = findAmoeba(state, el.dataset.amoeba);
|
||||
const m = actions().find(
|
||||
(m) => m.cell === a.cell && ["drift", "direction"].includes(m.type),
|
||||
);
|
||||
if (m) {
|
||||
void doMove(m);
|
||||
return;
|
||||
}
|
||||
selected = a.id;
|
||||
viewPlayer = a.p;
|
||||
render();
|
||||
return;
|
||||
}
|
||||
if (el.dataset.player !== undefined) {
|
||||
viewPlayer = Number(el.dataset.player);
|
||||
selected = colony(state, viewPlayer)[0]?.id;
|
||||
render();
|
||||
return;
|
||||
}
|
||||
if (el.dataset.gene) {
|
||||
open(el.dataset.gene);
|
||||
return;
|
||||
}
|
||||
if (el.dataset.ui === "close") {
|
||||
dialog.close();
|
||||
return;
|
||||
}
|
||||
if (el.dataset.ui === "fullscreen") {
|
||||
if (onFullscreen) onFullscreen();
|
||||
else if (!document.fullscreenElement)
|
||||
root.requestFullscreen?.().catch(() => {});
|
||||
else document.exitFullscreen?.().catch(() => {});
|
||||
return;
|
||||
}
|
||||
if (el.dataset.ui) open(el.dataset.ui);
|
||||
});
|
||||
root.addEventListener("change", (e) => {
|
||||
if (e.target.matches("select")) {
|
||||
number = Number(e.target.value);
|
||||
render();
|
||||
}
|
||||
});
|
||||
return {
|
||||
root,
|
||||
guide: $(".tutorial-slot"),
|
||||
render(s) {
|
||||
state = s;
|
||||
render();
|
||||
},
|
||||
setPlayer(p) {
|
||||
seat = p;
|
||||
viewPlayer = p;
|
||||
render();
|
||||
},
|
||||
setEnabled(enabled) {
|
||||
locked = !enabled;
|
||||
render();
|
||||
},
|
||||
closeModal() {
|
||||
dialog.close();
|
||||
},
|
||||
destroy() {
|
||||
dialog.close();
|
||||
root.remove();
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue