primordial-soup/engine/new-genes.js

145 lines
6.4 KiB
JavaScript
Raw Permalink 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.

// Rules and errata: http://doris-frank.de/download/Ursuppe_Frisch_Abgeschmeckt.pdf
// http://doris-frank.de/Ursuppe.html#ERRATA
export const NEW_GENES_OPTION = {
name: "newGenes",
label: "New genes",
type: "checkbox",
default: false,
};
export const NEW_GENES_TITLE = "Primordial Soup: Freshly Spiced";
const extra = (id, name, cost, mutation, base = [], details = {}) => ({
id,
name,
cost,
mutation,
base,
copies: 1,
points: base.length ? 2 : 1,
implemented: true,
...details,
});
export const NEW_GENES = [
extra("doris-frank", "Doris & Frank Gene", 2, 3),
extra("glutton", "Glutton", 3, -2),
extra("alarm", "Alarm", 3, 3),
extra("cleanliness", "Cleanliness", 3, 3),
extra("hard-crust", "Hard Crust", 3, 3),
extra("migration", "Migration Sensing", 3, 3),
extra("social", "Social Gene", 4, 3, [], { transferCost: 2 }),
extra("fast-food", "Fast Food", 4, 3),
extra("adaptable", "Highly Adaptable", 4, 3),
extra("mouthful", "More than a Mouthful", 4, 3),
extra("camouflage1", "Camouflage I", 4, 4),
extra("suction1", "Suction I", 4, 4),
extra("threat", "Threat Display", 4, 4),
extra("flexible", "Flexible", 5, 4),
extra("healing1", "Healing I", 5, 4),
extra("rebound", "Rebound", 5, 4),
extra("bang", "Go Out With a Bang", 5, 5),
extra("short-life", "Short Life Span", 5, 5, [], { defectRelief: 4 }),
extra("toxic", "Toxic Excretions", 5, 5),
extra("population", "Population Explosion", 6, 5),
extra("energy", "Energy Conservation", 6, 6),
extra("phd", "PhD", 3, 4, ["intelligence"]),
extra("environmental", "Environmental Sensing", 4, 3, ["migration"]),
extra("camouflage2", "Camouflage II", 5, 5, ["camouflage1"]),
extra("healing2", "Healing II", 5, 5, ["healing1"]),
extra("suction2", "Suction II", 6, 6, ["suction1"]),
];
const descriptions = {
"doris-frank":
"At the end of the game, you choose which game everyone plays next.",
glutton:
"Every amoeba must eat one extra nutrient of another colour at each meal. Its negative sensitivity protects your other genes.",
alarm:
"After one of your amoebas is eaten in phase 1, your remaining amoebas can use Escape for the rest of that phase.",
cleanliness:
"After feeding, you may excrete in an adjacent space instead. Both nutrients go to the same space.",
"hard-crust":
"After overcoming your defenses, an attacker must pay one extra BP to complete its attack. Otherwise the attack fails.",
migration:
"At the start of phase 1, privately see the environment card that will be revealed in phase 2.",
social:
"Only the last colony may buy this gene: 4 BP from the bank, or 2 BP paid to its current owner. In phase 6, receive 1 BP from each colony at least six score spaces ahead.",
"fast-food":
"Your amoebas may feed before moving, instead of after moving, in phase 1.",
adaptable:
"During phase 3, exchange an owned gene, including this one, for an available gene. Pay only the positive difference in printed prices. Advanced prerequisites still apply.",
mouthful:
"When an enemy successfully feeds on your amoeba, it takes one injury instead of being eaten. The attacker feeds, but no nutrients appear.",
camouflage1:
"When attacking, roll a die. On 4–6, ignore Defense, Escape and Alarm for this attack. Armor still works.",
suction1:
"You may take one nutrient for a meal from one horizontally or vertically adjacent space.",
threat:
"Your amoebas can only be attacked by amoebas with an equal or lower number.",
flexible: "Pay one BP less when acquiring a gene.",
healing1:
"During phase 4, pay 3 BP to remove one injury from one of your amoebas. You may repeat this.",
rebound:
"When a move hits an obstacle, you may bounce to the space immediately beyond it, if that space exists.",
bang: "When one of your amoebas dies, every other amoeba in its space takes one injury. Lethal injuries cause immediate chain reactions.",
"short-life":
"Your amoebas die at one injury, or two with Longevity, and cost 4 BP to divide. Mandatory while owned. Discarding this gene relieves only 4 sensitivity.",
toxic:
"Each excretion leaves one toxin. The next amoeba to enter the space takes all its toxins as injuries.",
population:
"In phase 4, you may surrender all your BP and receive no income. Instead, divide for free until you have as many amoebas as the score leader. Normal placement rules apply.",
energy:
"Each amoeba that drifts in phase 1 earns you one BP, even if its drift is blocked.",
phd: "An advanced Intelligence gene: counts as two genes when calculating evolution points.",
environmental:
"Immediately after the environment changes in phase 2, privately see the next environment card.",
camouflage2:
"Your attacks ignore Defense, Escape and Alarm. Armor still works.",
healing2:
"During phase 4, pay 3 BP to remove one injury, or transfer an injury to another amoeba in the same space for free. The recipient dies immediately.",
suction2:
"You may take up to two nutrients for a meal from one adjacent space, including diagonally.",
};
for (const g of NEW_GENES) g.text = descriptions[g.id];
export const INITIAL_NEW_GENES = ["social", "population"];
// randomIndex must use the engine's seeded RNG; never Math.random in a game.
export function createNewGeneMarket(options, randomIndex) {
if (options.newGenes !== undefined && typeof options.newGenes !== "boolean")
throw new Error("New genes must be enabled or disabled.");
if (!options.newGenes) return undefined;
const remaining = NEW_GENES.map((g) => g.id).filter(
(id) => !INITIAL_NEW_GENES.includes(id),
);
for (let i = remaining.length - 1; i > 0; i--) {
const j = randomIndex(i + 1);
if (!Number.isInteger(j) || j < 0 || j > i)
throw new Error("Invalid shuffle index.");
[remaining[i], remaining[j]] = [remaining[j], remaining[i]];
}
return {
available: [...INITIAL_NEW_GENES],
_deck: remaining,
revealedRound: 0,
};
}
export function revealNewGenesAfterPurchases(
market,
{ phase, round, player, leader, finishedBuying },
) {
if (
!market ||
phase !== 2 ||
!finishedBuying ||
player !== leader ||
round <= market.revealedRound
)
return market;
return {
available: [...market.available, ...market._deck.slice(0, 2)],
_deck: market._deck.slice(2),
revealedRound: round,
};
}
export function publicNewGeneMarket(market) {
return market
? { available: [...market.available], remaining: market._deck.length }
: undefined;
}