84 lines
3.5 KiB
TypeScript
84 lines
3.5 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
|||
|
|
import { cardCost } from "../src/cards.ts";
|
|||
|
|
import { cardDef } from "../src/data.ts";
|
|||
|
|
import { OVERTIME_FATIGUE, isSlip, overtime, overtimeBlocked, overtimeRisk } from "../src/overtime.ts";
|
|||
|
|
import { createRun, playCard } from "../src/rules.ts";
|
|||
|
|
import type { RunState } from "../src/state.ts";
|
|||
|
|
import { tutorialSetup } from "../src/tutorial.ts";
|
|||
|
|
import { toView } from "../src/view.ts";
|
|||
|
|
import { SETUP, advance, must, toPlan } from "./fixtures.ts";
|
|||
|
|
|
|||
|
|
/** docs/27:趕場(推運氣) */
|
|||
|
|
|
|||
|
|
/** 體力用完、牌庫頂是指定的牌 */
|
|||
|
|
function tired(top: string, seed = 3): RunState {
|
|||
|
|
const s = structuredClone(toPlan(createRun(SETUP, "r", seed))) as RunState;
|
|||
|
|
s.energy = 0;
|
|||
|
|
s.draw.unshift({ uid: "top", id: top });
|
|||
|
|
return s;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
describe("趕場", () => {
|
|||
|
|
it("體力用完才能趕場;新手教學不能", () => {
|
|||
|
|
const s = toPlan(createRun(SETUP, "r", 3));
|
|||
|
|
expect(s.energy).toBeGreaterThan(0);
|
|||
|
|
expect(overtimeBlocked(s)).toBe("體力用完才能趕場");
|
|||
|
|
const t = toPlan(createRun(tutorialSetup(), "t", 1, { tutorial: true }));
|
|||
|
|
expect(overtimeBlocked({ ...t, energy: 0 })).toBe("新手教學不能趕場");
|
|||
|
|
expect(toView(t).overtime).toBeNull();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("翻到的牌這週不花體力,牌庫多兩張疲勞", () => {
|
|||
|
|
const s = tired("walk");
|
|||
|
|
const size = s.draw.length;
|
|||
|
|
const r = must(overtime(s));
|
|||
|
|
expect(r.hand.some((c) => c.uid === "top")).toBe(true);
|
|||
|
|
expect(cardCost(r, cardDef("walk")!, "top").energy).toBe(0);
|
|||
|
|
expect(r.draw.length).toBe(size - 1 + OVERTIME_FATIGUE);
|
|||
|
|
expect(r.draw.filter((c) => c.id === "tired")).toHaveLength(OVERTIME_FATIGUE);
|
|||
|
|
expect(toView(r).hand.find((c) => c.uid === "top")).toMatchObject({ cost: 0, overtime: true, blocked: null });
|
|||
|
|
const played = playCard(r, "top", r.towns[0]!.code);
|
|||
|
|
expect("error" in played).toBe(false);
|
|||
|
|
// 只免費這一次:同一週洗回手上要照付體力
|
|||
|
|
if (!("error" in played)) {
|
|||
|
|
expect(played.state.overtime?.free).not.toContain("top");
|
|||
|
|
expect(cardCost(played.state, cardDef("walk")!, "top").energy).toBe(cardDef("walk")!.cost);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("翻到負面狀態牌就翻車:下週體力 −1、聲勢 −1、這週不能再趕", () => {
|
|||
|
|
const s = tired("favor");
|
|||
|
|
s.momentum = 2;
|
|||
|
|
const r = must(overtime(s));
|
|||
|
|
expect(r.momentum).toBe(1);
|
|||
|
|
expect(r.energyNext).toBe(s.energyNext - 1);
|
|||
|
|
expect(r.overtime?.done).toBe(true);
|
|||
|
|
expect(overtimeBlocked(r)).toBe("這週翻車了,明天再趕");
|
|||
|
|
expect(r.stats.busts).toBe(1);
|
|||
|
|
// 下一週重新開始:可以再趕場,體力少 1
|
|||
|
|
const next = advance(r, 2);
|
|||
|
|
expect(next.overtime).toBeNull();
|
|||
|
|
expect(next.energy).toBe(next.energyMax - 1);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("好的狀態牌(黨部動員掃街)不算翻車", () => {
|
|||
|
|
expect(isSlip("walkx")).toBe(false);
|
|||
|
|
expect(isSlip("tired")).toBe(true);
|
|||
|
|
expect(isSlip("reporter")).toBe(true);
|
|||
|
|
const r = must(overtime(tired("walkx")));
|
|||
|
|
expect(r.overtime?.done).toBe(false);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
it("風險=下一疊牌裡的負面狀態牌;抽牌堆空了看棄牌堆", () => {
|
|||
|
|
const s = tired("walk");
|
|||
|
|
s.draw = [{ uid: "a", id: "walk" }, { uid: "b", id: "tired" }];
|
|||
|
|
expect(overtimeRisk(s)).toEqual({ bad: 1, total: 2 });
|
|||
|
|
s.draw = [];
|
|||
|
|
s.discard = [{ uid: "c", id: "favor" }, { uid: "d", id: "walk" }, { uid: "e", id: "tv" }];
|
|||
|
|
expect(overtimeRisk(s)).toEqual({ bad: 1, total: 3 });
|
|||
|
|
const r = must(overtime(s));
|
|||
|
|
expect(r.discard).toHaveLength(0);
|
|||
|
|
expect(r.overtime!.flips).toBe(1);
|
|||
|
|
});
|
|||
|
|
});
|