primordial-soup/viewer/tutorials.js

486 lines
17 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.",
),
};