election-game/backend/packages/engine/test/fixtures.ts

202 lines
6.4 KiB
TypeScript
Raw Permalink Normal View History

import { CELLS_PER_VILLAGE, DEFAULT_PARAMS, type ActionDef, type Content, type PackData, type Scenario, type World } from "../src/index.ts";
/** 測試用的小資料包:兩個區、四個里,每個選民群 100 人 */
export function tinyPack(): PackData {
const villages = [0, 1, 2, 3].map((i) => ({
code: `680000${i < 2 ? "10" : "20"}00${i}`,
name: `第${i + 1}里`,
townIndex: i < 2 ? 0 : 1,
adults: 100 * CELLS_PER_VILLAGE,
electors: 100 * CELLS_PER_VILLAGE,
baseTurnout: 0.6,
density: 1_000 * (i + 1),
templesPer1000: 0.2 * (i + 1),
}));
const history = {
elections: [{ id: "prior", name: "上一次", date: "2020-01-11", office: "president" as const, weight: 1 }],
byVillage: Object.fromEntries(
villages.map((v, i) => [
v.code,
{ prior: { electors: 3_000, ballots: 1_800, valid: 1_780, votes: { 甲黨: 900 + 50 * i, 乙黨: 880 - 50 * i }, allocated: false } },
]),
),
reconciliation: [],
};
return {
packId: "tiny",
countyCode: "68000",
partySlots: { a: "甲黨", b: "乙黨", c: "丙黨" },
villages,
towns: [
{ code: "68000010", name: "東區", adults: 6_000, electors: 6_000, villages: [0, 1], hakkaShare: null },
{ code: "68000020", name: "西區", adults: 6_000, electors: 6_000, villages: [2, 3], hakkaShare: 0.3 },
],
cells: new Float32Array(villages.length * CELLS_PER_VILLAGE).fill(100),
history,
meanTemples: 0.5,
meanDensity: 2_500,
};
}
const base = {
duration: 1 as const,
visibility: "public" as const,
risk: null,
phase: "campaign" as const,
amount: null,
};
export const TEST_ACTIONS: ActionDef[] = [
{
...base,
id: "street_canvass",
name: "掃街",
category: "ground",
description: "",
slots: ["weekdayMorning", "weekdayAfternoon", "weekendMorning", "weekendAfternoon"],
actors: ["candidate", "team"],
target: "town",
cost: { money: 30_000, stamina: 12 },
effects: [
{ stat: "awareness", base: 0.05, scope: "target" },
{ stat: "favor", base: 0.01, scope: "target" },
],
},
{
...base,
id: "rally",
name: "造勢",
category: "ground",
description: "",
slots: ["weekdayEvening", "weekendEvening"],
duration: 2,
actors: ["candidate"],
target: "town",
cost: { money: 0, stamina: 20 },
amount: { label: "規模", unit: "元", min: 1_000_000, max: 10_000_000, step: 500_000, default: 3_000_000, moneyPerUnit: 1 },
special: "rally",
effects: [{ stat: "heat", base: 0.15, scope: "target", supportersOnly: true }],
},
{
...base,
id: "announce_policy",
name: "政見",
category: "policy",
description: "",
slots: ["weekdayMorning", "weekendMorning"],
actors: ["candidate"],
target: "city",
cost: { money: 100_000, stamina: 8 },
special: "policy",
effects: [],
},
{
...base,
id: "internal_poll",
name: "內參",
category: "logistics",
description: "",
slots: ["weekdayMorning", "weekdayAfternoon", "weekdayEvening", "weekendMorning", "weekendAfternoon", "weekendEvening"],
actors: ["team"],
target: "city",
visibility: "secret",
cost: { money: 600_000, stamina: 0 },
special: "internalPoll",
effects: [],
},
{
...base,
id: "investigate",
name: "打探",
category: "offense",
description: "",
slots: ["weekdayMorning", "weekdayAfternoon", "weekdayEvening", "weekendMorning", "weekendAfternoon", "weekendEvening"],
actors: ["team"],
target: "opponent",
visibility: "secret",
cost: { money: 500_000, stamina: 0 },
special: "intel",
effects: [],
},
{
...base,
id: "vote_buying",
name: "買票",
category: "dark",
description: "",
slots: ["midnight"],
actors: ["team"],
target: "town",
visibility: "secret",
cost: { money: 0, stamina: 0 },
amount: { label: "票數", unit: "票", min: 100, max: 20_000, step: 100, default: 1_000, moneyPerUnit: 1_000 },
special: "voteBuying",
effects: [],
},
{
...base,
id: "hire_staff",
name: "找幕僚",
category: "logistics",
description: "",
slots: ["weekdayMorning", "weekdayAfternoon"],
actors: ["candidate", "team"],
target: "city",
visibility: "local",
cost: { money: 100_000, stamina: 4 },
special: "hireStaff",
effects: [],
},
{
...base,
id: "eve_rally",
name: "選前之夜",
category: "ground",
description: "",
slots: ["weekendEvening"],
actors: ["candidate"],
target: "town",
phase: "eve",
cost: { money: 0, stamina: 0 },
amount: { label: "規模", unit: "元", min: 1_000_000, max: 15_000_000, step: 500_000, default: 5_000_000, moneyPerUnit: 1 },
special: "rally",
effects: [{ stat: "heat", base: 0.12, scope: "city", supportersOnly: true }],
},
];
export const TEST_CONTENT: Content = {
actions: TEST_ACTIONS,
issues: [
{ id: "transport", name: "交通", description: "", appeal: { "20-29": 0.6, "30-39": 0.7, "40-49": 0.6, "50-64": 0.5, "65+": 0.4 } },
{ id: "housing", name: "居住", description: "", appeal: { "20-29": 0.9, "30-39": 0.8, "40-49": 0.5, "50-64": 0.3, "65+": 0.2 } },
],
};
export const TEST_SCENARIO: Scenario = {
id: "tiny-mayor",
name: "測試市長",
description: "",
packId: "tiny",
weeks: 4,
electionDate: "2022-11-26",
region: { countyCode: "68000", countyName: "測試市", office: "市長" },
blackoutFromWeek: 4,
publicPollWeeks: [2],
spendingCap: 50_000_000,
mood: { a: 0, b: 0, c: 0, other: 0 },
publicHistoryElection: "prior",
bountyMultiplier: 1,
turnoutScale: 1,
notes: [],
sources: [],
actual: { electionId: "prior", partyToCandidate: { 甲黨: "alice", 乙黨: "bob" } },
candidates: [
{ id: "alice", name: "甲", personId: null, party: "甲黨", slot: "a", number: 1, description: "", awareness: 0.6, eloquence: 60, strategy: 60, startingMoney: 20_000_000, wealth: 5_000_000, machine: 0.2, staff: 2, fundraising: 2_000_000, realFinance: null, aiStyle: "balanced" },
{ id: "bob", name: "乙", personId: null, party: "乙黨", slot: "b", number: 2, description: "", awareness: 0.6, eloquence: 50, strategy: 50, startingMoney: 20_000_000, wealth: 5_000_000, machine: 0.2, staff: 2, fundraising: 2_000_000, realFinance: null, aiStyle: "ground" },
],
};
export function tinyWorld(): World {
return { scenario: TEST_SCENARIO, pack: tinyPack(), content: TEST_CONTENT, params: DEFAULT_PARAMS };
}