primordial-soup/engine/catalog.js

285 lines
7.3 KiB
JavaScript

import { NEW_GENES } from "./new-genes.js";
export const COLORS = ["green", "red", "blue", "yellow", "black", "burgundy"];
export const COLOR_NAMES = [
"Green",
"Coral",
"Blue",
"Gold",
"Black",
"Burgundy",
];
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. Adds 1 to the gene total used to calculate evolution points at the end of each round.",
),
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 towards the gene total used to calculate evolution points.",
),
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],
"Phase 1 only: if an amoeba cannot feed, spend 1 BP to attack another amoeba in its space. A successful attack feeds the attacker and leaves one cube of each colour. No attack if it can eat normally.",
),
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, 1],
"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],
"Keeps Struggle for Survival: attack to feed in phase 1 when starving. Adds one attack for your whole colony in phase 5, after natural deaths, even if everyone has eaten. Choose one of your amoebas and an opponent in its space; pay 1 BP. A successful phase-5 attack kills the target; Armor reduces this 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"],
),
];
const sixPlayerCopies = {
intelligence: 3,
movement1: 3,
spores: 2,
speed: 2,
defense: 2,
escape: 2,
substitution: 2,
ray: 2,
streamline: 2,
tentacle: 2,
holding: 1,
longevity: 2,
frugality: 2,
struggle: 3,
parasitism: 2,
division: 2,
persistence: 1,
movement2: 2,
aggression: 1,
armor: 1,
};
for (const g of GENES)
g.copies.push(sixPlayerCopies[g.id], sixPlayerCopies[g.id]);
export const ALL_GENES = [...GENES, ...NEW_GENES];
export const GENE = Object.fromEntries(ALL_GENES.map((g) => [g.id, g]));
export const copiesOf = (g, players) =>
Array.isArray(g.copies) ? g.copies[players - 3] : g.copies;
export const populationPoints = (n, players = 4) =>
(players >= 5 ? [0, 0, 1, 2, 3, 4, 5] : [0, 0, 0, 1, 2, 4, 5, 6])[n];
export const amoebaLimit = (players) => (players >= 5 ? 6 : 7);
export const roundIncome = (players) => (players >= 5 ? 11 : 10);
export const tentacleLimit = (players) => (players === 3 ? 2 : 3);
export function geneFor(id, players) {
const g = GENE[id];
if (players < 5) return g;
const overrides = {
streamline: { mutation: 5 },
struggle: { mutation: 5 },
frugality: { cost: 5 },
substitution: {
text: "Eat five food cubes from three other colours instead of four cubes from four colours. You may combine this with Frugality and Parasitism.",
},
tentacle: {
text: "Carry up to three food cubes when moving. You may take any colour, including your own.",
},
};
return overrides[id] ? { ...g, ...overrides[id] } : g;
}
export const genePoints = (n) => Math.min(4, Math.max(0, n - 2));
// Eleven environment cards transcribed and confirmed by the owner.
// Direction indexes follow DIRECTIONS; the two 10/East cards are intentional.
export const ENVIRONMENTS = [
{ ozone: 6, direction: 0 },
{ ozone: 8, direction: 2 },
{ ozone: 9, direction: 0 },
{ ozone: 9, direction: 1 },
{ ozone: 10, direction: 2 },
{ ozone: 10, direction: 3 },
{ ozone: 10, direction: 2 },
{ ozone: 11, direction: 1 },
{ ozone: 12, direction: 0 },
{ ozone: 13, direction: 3 },
{ ozone: 14, direction: 4 },
];