Something went wrong. Try again.
A Social Deduction / Deception Game
Something went wrong. Try again.
2.6 kB · 56 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import { describe, expect, it } from 'vitest'import { balance, resourceIds, sabotageFailureChance, timerFor } from './config.js'
describe('balance', () => { it('derives a full config from players / duration / resource count', () => { const b = balance({ playerCount: 6, roundDurationMs: 600_000, resourceCount: 4 }) expect(b.config.resources).toEqual(['wood', 'stone', 'wheat', 'ore']) expect(b.config.roundDurationMs).toBe(600_000) expect(b.slotsPerStation).toBeGreaterThanOrEqual(1) expect(b.resourceTarget).toBeGreaterThanOrEqual(1) // every resource shares the same target for (const r of b.config.resources) expect(b.config.targets[r]).toBe(b.resourceTarget) })
it('keeps slots-per-station below the player count to force splitting up', () => { const b = balance({ playerCount: 10, roundDurationMs: 600_000, resourceCount: 4 }) expect(b.slotsPerStation).toBeLessThan(10) })
it('scales the target with player count and round length', () => { const few = balance({ playerCount: 4, roundDurationMs: 600_000, resourceCount: 4 }) const many = balance({ playerCount: 10, roundDurationMs: 600_000, resourceCount: 4 }) const longer = balance({ playerCount: 4, roundDurationMs: 1_200_000, resourceCount: 4 }) expect(many.resourceTarget).toBeGreaterThan(few.resourceTarget) expect(longer.resourceTarget).toBeGreaterThan(few.resourceTarget) })
it('generates resource ids, falling back past the palette', () => { expect(resourceIds(2)).toEqual(['wood', 'stone']) expect(resourceIds(9)[8]).toBe('res-9') })})
describe('sabotageFailureChance', () => { it('rises with both usages and elapsed time, and clamps to [0,1]', () => { expect(sabotageFailureChance(0, 0)).toBe(0) expect(sabotageFailureChance(2, 0)).toBeCloseTo(0.4) expect(sabotageFailureChance(0, 60_000)).toBeCloseTo(0.3) expect(sabotageFailureChance(2, 60_000)).toBeCloseTo(0.7) expect(sabotageFailureChance(100, 100_000)).toBe(1) // clamped })
it('treats the fakeRepair grace window (negative usages) as no chance', () => { expect(sabotageFailureChance(-2, 0)).toBe(0) })})
describe('timerFor', () => { it('maps activities to their timer tier', () => { const { config } = balance({ playerCount: 4, roundDurationMs: 600_000, resourceCount: 4 }) expect(timerFor('collect', config)).toBe(config.timer1Ms) expect(timerFor('repair', config)).toBe(config.timer2Ms) expect(timerFor('inspect', config)).toBe(config.timer3Ms) expect(timerFor('sabotage', config)).toBe(config.timer3Ms) })})