election-game/backend/packages/rogue/test/schools.test.ts

154 lines
7.1 KiB
TypeScript
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 { describe, expect, it } from "vitest";
import { REWARD_CARDS } from "../src/data.ts";
import { executeIntent } from "../src/rival.ts";
import { createRun, endWeek, playCard } from "../src/rules.ts";
import { FLAG_LEAD, type Intent, type RunState, type TownState } from "../src/state.ts";
import { catalog } from "../src/view.ts";
import { SETUP, must } from "./fixtures.ts";
/** 流派核心牌與改規則的幕僚(docs/25 第 2 節) */
const town = (s: RunState, code: string): TownState => s.towns.find((t) => t.code === code)!;
/** 乾淨的局面:指定手牌、幕僚、能力,清掉意圖、樁腳、本命區、對手規則 */
function bare(hand: string[], opts: { advisors?: string[]; powers?: string[]; intents?: Intent[] } = {}): RunState {
const s = structuredClone(createRun(SETUP, "r", 1));
return {
...s,
phase: "plan",
scene: null,
rivalRules: [],
towns: s.towns.map((t) => ({ ...t, shield: 0, rivalShield: 0, home: null })),
hand: hand.map((id, i) => ({ uid: `t${i}`, id })),
intents: opts.intents ?? [],
advisors: opts.advisors ?? [],
powers: opts.powers ?? [],
energy: 9,
money: 1000,
momentum: 0,
};
}
const ok = (r: ReturnType<typeof playCard>): RunState => {
if ("error" in r) throw new Error(r.error);
return r.state;
};
const gained = (a: RunState, b: RunState) => b.towns.reduce((x, t, i) => x + t.you - a.towns[i]!.you, 0);
describe("流派核心牌", () => {
it("十張新牌都在獎勵池、圖鑑裡", () => {
const ids = ["legwork", "doorstep", "network", "buzz", "explainer", "turntable", "wargame", "carpetads", "microdonate"];
for (const id of ids) expect(REWARD_CARDS.some((c) => c.id === id)).toBe(true);
const listed = new Set(catalog().cards.map((c) => c.id));
for (const id of ids) expect(listed.has(id)).toBe(true);
for (const a of ["iron_legs", "faction_broker", "meme_editor", "crisis_flip", "actuary"]) expect(catalog().advisors.some((x) => x.id === a)).toBe(true);
});
it("走透透:這週每打過一張地面牌,之後的地面牌 +8%", () => {
const s = bare(["canvass", "canvass", "canvass"], { powers: ["legwork"] });
const plain = bare(["canvass"]);
const one = ok(playCard(s, "t0", "D"));
const two = ok(playCard(one, "t1", "C"));
const three = ok(playCard(two, "t2", "D"));
const base = gained(plain, ok(playCard(plain, "t0", "D")));
// 第三張打在丁區:前面打過 2 張地面牌 ×1.16,同一區第二種牌不算組合拳(都是掃街)
expect(gained(two, three)).toBeCloseTo(base * 1.16, 0);
});
it("挨家挨戶:這週出過牌的區越多越強(最多 5 區)", () => {
const s = bare(["canvass", "canvass", "doorstep"]);
const after2 = ok(playCard(ok(playCard(s, "t0", "A")), "t1", "B"));
const first = bare(["doorstep"]);
const alone = gained(first, ok(playCard(first, "t0", "D")));
expect(gained(after2, ok(playCard(after2, "t2", "D")))).toBeCloseTo(alone * 3, 0);
});
it("樁腳網:週末還沒被用掉的樁腳,兩成變成你在那區的票", () => {
const s = bare([], { powers: ["network"] });
town(s, "A").shield = 1000;
const after = must(endWeek(s));
expect(after.log.some((l) => l.text === "樁腳網・甲區" && l.votes === 200)).toBe(true);
});
it("聲量滾雪球:空戰牌累積聲量,每點 +3%;懶人包每點再 +5%", () => {
const s = bare(["tv", "tv"], { powers: ["buzz"] });
const one = ok(playCard(s, "t0", null));
expect(one.buzz).toBe(1);
const plain = bare(["tv"]);
const base = gained(plain, ok(playCard(plain, "t0", null)));
expect(gained(one, ok(playCard(one, "t1", null)))).toBeCloseTo(base * 1.03, -1);
const ex = { ...bare(["explainer"]), buzz: 4 };
const exPlain = bare(["explainer"]);
expect(gained(ex, ok(playCard(ex, "t0", null)))).toBeCloseTo(gained(exPlain, ok(playCard(exPlain, "t0", null))) * 1.2, -1);
});
it("反將一軍:批評剩一半,擋下的一半變成你的全市票", () => {
const attack: Intent = { id: "a", kind: "attack", town: null, amount: 1000, cut: 1 };
const s = ok(playCard(bare(["turntable"], { intents: [attack] }), "t0", null));
expect(s.intents[0]!.cut).toBe(0.5);
const before = s.towns.reduce((a, t) => a + t.you, 0);
executeIntent(s, s.intents[0]!);
const back = s.log.find((l) => l.text === "反將一軍:擋下的批評變成你的票")!;
expect(back.votes).toBe(250);
expect(before).toBeGreaterThan(0);
});
it("沙盤推演:每週第一張擋對手的牌不花體力", () => {
const attack: Intent = { id: "a", kind: "attack", town: null, amount: 1000, cut: 1 };
const s = bare(["clarify", "clarify"], { powers: ["wargame"], intents: [attack] });
const one = ok(playCard(s, "t0", null));
expect(one.energy).toBe(9);
expect(ok(playCard(one, "t1", null)).energy).toBe(8);
});
it("地毯式廣告:花光資金,每 100 萬全市 +票;小額募款:每面旗多 60 萬", () => {
const s = bare(["carpetads"]);
const after = ok(playCard(s, "t0", null));
expect(after.money).toBe(0);
expect(gained(s, after)).toBeGreaterThan(0);
const m = bare(["microdonate"]);
for (const code of ["A", "B"]) {
const t = town(m, code);
t.you = t.rival + (t.you + t.rival + t.others) * (FLAG_LEAD + 0.05) * 2;
t.flag = "you";
}
expect(ok(playCard(m, "t0", null)).money - m.money).toBe(120 + 60 * 2);
});
});
describe("流派幕僚", () => {
it("鐵腿:一週跑 3 區以上,週末聲勢 +2", () => {
let s = bare(["canvass", "canvass", "canvass"], { advisors: ["iron_legs"] });
for (const [uid, code] of [["t0", "A"], ["t1", "B"], ["t2", "C"]] as const) s = ok(playCard(s, uid, code));
const before = s.momentum;
expect(must(endWeek(s)).log.some((l) => l.text.startsWith("鐵腿"))).toBe(true);
expect(before).toBeGreaterThanOrEqual(0);
});
it("派系協調人:樁腳擋下的票,一半變成你的", () => {
const s = bare([], { advisors: ["faction_broker"] });
town(s, "A").shield = 1000;
executeIntent(s, { id: "c", kind: "canvass", town: "A", amount: 800, cut: 1 });
expect(s.log.find((l) => l.text === "派系協調人・甲區")!.votes).toBe(400);
});
it("懶人包小編:爆紅之後那張牌回到手上(每週一次)", () => {
// 找一個會爆紅的亂數狀態
for (let rng = 1; rng < 200; rng++) {
const s = { ...bare(["live"], { advisors: ["meme_editor"] }), rng };
const after = ok(playCard(s, "t0", null));
if (!after.memeUsed) continue;
expect(after.hand.map((c) => c.id)).toEqual(["live"]);
return;
}
throw new Error("找不到爆紅的亂數");
});
it("危機變轉機:擋下幾次批評,週末聲勢就 +幾;精算師:存款利息最多 50 萬", () => {
const s = bare(["clarify"], { advisors: ["crisis_flip", "actuary"], intents: [{ id: "a", kind: "attack", town: null, amount: 1000, cut: 1 }] });
const after = must(endWeek(ok(playCard(s, "t0", null))));
expect(after.log.some((l) => l.text.startsWith("危機變轉機"))).toBe(true);
expect(after.log.find((l) => l.text.startsWith("精算師"))!.text).toContain("50 萬");
});
});