deadhead-space-freight-tycoon/packages/sim/test/courier-mars.test.ts

36 lines
1.5 KiB
TypeScript

import { content, upgradePercentPerLevel, type ShipModel } from "@deadhead/content";
import { describe, expect, it } from "vitest";
import { checkRoute, realToGame } from "../src/index";
const courier = content.shipModel("courier")!;
const tanks = content.upgrade("fuel-tanks")!;
const earth = content.location("earth")!;
const mars = content.location("mars")!;
/** A Courier with fuel tanks at `level` (decision 0.5.63: linear % of base range). */
const withTanks = (level: number): ShipModel => ({
...courier,
fuelRangeMillionKm:
courier.fuelRangeMillionKm * (1 + (upgradePercentPerLevel(tanks, "courier") * level) / 100),
});
/** Monthly samples over 16 game years (CR-012). */
const MONTH = 30.44 * 24 * 3_600_000;
const start = realToGame(Date.parse(content.config.epoch.realStart), content.config);
const samples = Array.from({ length: 16 * 12 + 1 }, (_, i) => start + i * MONTH);
const inRange = (ship: ShipModel) =>
samples.map((t) => checkRoute(ship, earth, mars, t)).map((r) => r.ok);
// Measured from Earth (decision 0.5.68 as amended by CR-012).
describe("Courier to Mars from Earth (decision 0.5.68)", () => {
it("reaches Mars with maxed fuel tanks near closest approach, but not at its farthest", () => {
const reach = inRange(withTanks(3));
expect(reach.some(Boolean)).toBe(true);
expect(reach.some((ok) => !ok)).toBe(true);
});
it("never reaches Mars with fuel tanks at level 2 or less", () => {
for (const level of [0, 1, 2]) expect(inRange(withTanks(level)).some(Boolean)).toBe(false);
});
});