forked from WikiDeck/wikideck
Deterministic, off-chain rules engine in shared/game: createMatch, legalActions, applyAction, isOver, result, viewFor, serialisation, Ruleset as data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
3.1 KiB
TypeScript
67 lines
3.1 KiB
TypeScript
/**
|
||
* PLACEHOLDER loaner cards and starter decks (DESIGN §2) so the engine, UI and
|
||
* sims can run before council-data's docs/game/starter-cards.json lands.
|
||
* Loaners are off-chain preview cards: not NFTs, never minted or moved.
|
||
* engine-b / council-data replace STARTER_POOL with derived cards (cards.ts).
|
||
*/
|
||
import { Rng } from './rng.ts';
|
||
import type { Faction, GameCard, Stat } from './types.ts';
|
||
|
||
type Spec = [pageId: number, title: string, faction: Faction, cost: number, home: Stat];
|
||
|
||
/** DESIGN §1.3 powerByCost and §10.1 keyword choice (cost 1 = vanilla +vanillaBonus). pageIds outside shared/catalog.ts are unverified. */
|
||
const POWER_BY_COST = [0, 1, 2, 4, 6, 8, 10];
|
||
const VANILLA_BONUS = 1;
|
||
const FACTION_KEYWORD: Record<Faction, string> = {
|
||
Culture: 'viral', Nature: 'rising', People: 'local', Science: 'encyclopedic', History: 'nostalgic', Space: 'translated',
|
||
};
|
||
|
||
export const STARTER_POOL: readonly Spec[] = [
|
||
[22780, 'Octopus', 'Nature', 1, 'depth'],
|
||
[19331, 'Moon', 'Space', 1, 'reach'],
|
||
[23053, 'Periodic table', 'Science', 1, 'depth'],
|
||
[3383, 'Bronze Age', 'History', 1, 'depth'],
|
||
[5843419, 'Chess', 'Culture', 2, 'attention'],
|
||
[9228, 'Earth', 'Space', 2, 'reach'],
|
||
[2008, 'Ada Lovelace', 'People', 2, 'attention'],
|
||
[21830, 'Honey bee', 'Nature', 2, 'depth'],
|
||
[736, 'Albert Einstein', 'People', 3, 'reach'],
|
||
[10979, 'Fungus', 'Nature', 3, 'depth'],
|
||
[26903, 'Solar System', 'Space', 3, 'reach'],
|
||
[30758, 'Roman Empire', 'History', 3, 'depth'],
|
||
[9649, 'Evolution', 'Science', 4, 'depth'],
|
||
[8424, 'Jazz', 'Culture', 4, 'attention'],
|
||
[12898, 'Marie Curie', 'People', 4, 'reach'],
|
||
[14533, 'Silk Road', 'History', 4, 'reach'],
|
||
[19468, 'Mount Everest', 'Nature', 5, 'attention'],
|
||
[22936, 'Photosynthesis', 'Science', 5, 'depth'],
|
||
[18110, 'Leonardo da Vinci', 'People', 5, 'reach'],
|
||
[14627, 'Ancient Egypt', 'History', 5, 'attention'],
|
||
[4177, 'Black hole', 'Space', 6, 'attention'],
|
||
[25443, 'Quantum mechanics', 'Science', 6, 'depth'],
|
||
[17867, 'Library of Alexandria', 'History', 6, 'depth'],
|
||
[20217, 'Music', 'Culture', 6, 'reach'],
|
||
];
|
||
|
||
export function loanerCard(spec: Spec, copy = 0): GameCard {
|
||
const [pageId, title, faction, cost, home] = spec;
|
||
const keyword = cost === 1 ? null : FACTION_KEYWORD[faction];
|
||
return {
|
||
cardId: `loaner:${pageId}:${copy}`, pageId, title, faction, rarity: 'Common', cost,
|
||
power: POWER_BY_COST[cost] + (keyword ? 0 : VANILLA_BONUS), home, trend: 0, keyword, source: 'loaner', check: 'loaner',
|
||
};
|
||
}
|
||
|
||
/** Every placeholder loaner card, once each (24 cards). Draft modes can sample from this. */
|
||
export function previewPool(): GameCard[] { return STARTER_POOL.map(spec => loanerCard(spec)); }
|
||
|
||
/** A deterministic 12-card loaner deck: 2 cards of each cost 1–6, chosen by `seed`. */
|
||
export function starterDeck(seed: number | string): GameCard[] {
|
||
const rng = Rng.fromSeed(`starter:${seed}`);
|
||
const deck: GameCard[] = [];
|
||
for (let cost = 1; cost <= 6; cost++) {
|
||
deck.push(...rng.shuffle(STARTER_POOL.filter(spec => spec[3] === cost)).slice(0, 2).map(spec => loanerCard(spec)));
|
||
}
|
||
return deck;
|
||
}
|