Compose source-clear Basic even-force Ecaz Occupy

This commit is contained in:
Quintine committed 2026-10-03 20:34:22 +10:00
1 parent 63e57bd894
commit 5f082696a6
18 files changed
+861 -52

No files matched your search

+170 -17
View File
@@ -10,30 +10,183 @@ import {
type EcazOccupyBattleInput,
} from '../game/ecaz-occupy-battle';
const ordinary = (normal: number): CombatForces => ({
normal, elite: 0, eliteStrength: 2, freeSupport: false,
const ordinary = (normal: number, advanced: boolean): CombatForces => ({
normal, elite: 0, eliteStrength: advanced ? 2 : 1, freeSupport: !advanced,
});
function battle(
advanced: boolean,
ecazCount: number,
lead = 'ecaz-seat',
canceled = false,
allyForces = ordinary(4),
allyForces = ordinary(4, advanced),
): EcazOccupyBattleInput {
return {
advanced,
battleOrderActor: 'enemy-seat',
ecaz: { id: 'ecaz-seat', faction: 'ecaz', ally: 'ally-seat', forces: ordinary(ecazCount) },
ecaz: { id: 'ecaz-seat', faction: 'ecaz', ally: 'ally-seat', forces: ordinary(ecazCount, advanced) },
ally: { id: 'ally-seat', faction: 'atreides', ally: 'ecaz-seat', forces: allyForces },
lead,
canceled,
};
}
void test('Basic E2/E4 normal wins split Ecaz equally and settle the real ally pool with either lead', () => {
for (const ecazCount of [2, 4]) {
for (const lead of ['ecaz-seat', 'ally-seat']) {
const profile = quoteEcazOccupyBattle(battle(false, ecazCount, lead));
const fixed = ecazCount / 2;
for (const variableDial of [0, 2]) {
const dial = quoteEcazOccupyDial(profile, fixed + variableDial, 0);
assert.equal(dial.payer, lead);
assert.equal(dial.forceOwner, 'ally-seat');
const win = quoteEcazOccupyOutcome(profile, {
result: 'normal', won: true, dial: fixed + variableDial, support: 0,
});
assert.deepEqual(win.fixedLosses, [{ owner: 'ecaz-seat', normal: fixed, elite: 0 }]);
assert.equal(ecazCount - win.fixedLosses[0].normal, fixed);
assert.equal(win.casualties?.owner, 'ally-seat');
assert.deepEqual(win.casualties?.options, [
{ normal: variableDial, elite: 0, paidNormal: 0, paidElite: 0 },
]);
assert.equal(4 - win.casualties!.options[0].normal, 4 - variableDial);
assert.deepEqual(win.destroyedArmies, []);
assert.deepEqual(quoteEcazOccupyOutcome(profile, {
result: 'normal', won: false, dial: fixed + variableDial, support: 0,
}), {
destroyedArmies: ['ecaz-seat', 'ally-seat'], fixedLosses: [], casualties: null,
});
}
assert.deepEqual(ecazOccupyDialOptions(profile, 0), [
{ dial: fixed, support: 0, variableDial: 0 },
{ dial: fixed + 1, support: 0, variableDial: 1 },
{ dial: fixed + 2, support: 0, variableDial: 2 },
{ dial: fixed + 3, support: 0, variableDial: 3 },
{ dial: fixed + 4, support: 0, variableDial: 4 },
]);
assert.throws(() => quoteEcazOccupyDial(profile, fixed - 1, 0), EcazOccupyBattleError);
assert.throws(() => quoteEcazOccupyDial(profile, fixed + 0.5, 0), EcazOccupyBattleError);
assert.throws(() => quoteEcazOccupyDial(profile, fixed + 1, 1), EcazOccupyBattleError);
}
}
});
void test('Basic Fedaykin and Sardaukar stay typed, full strength one, free, and physically allied under either lead', () => {
const forces: CombatForces = { normal: 2, elite: 2, eliteStrength: 1, freeSupport: true };
for (const faction of ['fremen', 'emperor'] as const) {
for (const ecazCount of [2, 4]) {
for (const lead of ['ecaz-seat', 'ally-seat']) {
const input = battle(false, ecazCount, lead, false, forces);
const profile = quoteEcazOccupyBattle({ ...input, ally: { ...input.ally, faction } });
const fixed = ecazCount / 2;
const win = quoteEcazOccupyOutcome(profile, {
result: 'normal', won: true, dial: fixed + 2, support: 0,
});
assert.deepEqual(win.fixedLosses, [{ owner: 'ecaz-seat', normal: fixed, elite: 0 }]);
assert.equal(win.casualties?.owner, 'ally-seat');
assert.deepEqual(win.casualties?.options, [
{ normal: 2, elite: 0, paidNormal: 0, paidElite: 0 },
{ normal: 1, elite: 1, paidNormal: 0, paidElite: 0 },
{ normal: 0, elite: 2, paidNormal: 0, paidElite: 0 },
]);
assert.deepEqual(quoteEcazOccupyDial(profile, fixed + 4, 0).options, [
{ normal: 2, elite: 2, paidNormal: 0, paidElite: 0 },
]);
assert.throws(() => quoteEcazOccupyDial(profile, fixed + 5, 0), EcazOccupyBattleError);
assert.throws(() => quoteEcazOccupyDial(profile, fixed + 2, 1), EcazOccupyBattleError);
}
}
}
});
void test('Basic cancellation uses the selected own pool even for odd Ecaz and preserves the other army on a normal win', () => {
const forces: CombatForces = { normal: 0, elite: 2, eliteStrength: 1, freeSupport: true };
for (const ecazCount of [2, 4, 5]) {
for (const lead of ['ecaz-seat', 'ally-seat']) {
const input = battle(false, ecazCount, lead, true, forces);
const profile = quoteEcazOccupyBattle({
...input, ally: { ...input.ally, faction: 'emperor' },
});
const dial = quoteEcazOccupyDial(profile, 1, 0);
assert.equal(dial.forceOwner, lead);
assert.equal(dial.payer, lead);
assert.equal(dial.fixedEcazDial, 0);
assert.deepEqual(dial.options, [{
normal: lead === 'ecaz-seat' ? 1 : 0,
elite: lead === 'ally-seat' ? 1 : 0,
paidNormal: 0, paidElite: 0,
}]);
const win = quoteEcazOccupyOutcome(profile, {
result: 'normal', won: true, dial: 1, support: 0,
});
assert.equal(win.casualties?.owner, lead);
assert.deepEqual(win.fixedLosses, []);
assert.deepEqual(win.destroyedArmies, []);
assert.deepEqual(quoteEcazOccupyOutcome(profile, {
result: 'normal', won: false, dial: 1, support: 0,
}), {
destroyedArmies: ['ecaz-seat', 'ally-seat'], fixedLosses: [], casualties: null,
});
}
}
const input = battle(false, 5, 'ecaz-seat', true);
assert.throws(() => quoteEcazOccupyBattle({
...input, ally: { ...input.ally, forces: ordinary(0, false) },
}), EcazOccupyBattleError);
assert.throws(() => quoteEcazOccupyBattle({
...input, ecaz: { ...input.ecaz, forces: ordinary(0, false) },
}), EcazOccupyBattleError);
});
void test('Basic sole traitor victory spares both armies; defeat, mutual traitors and explosion spare neither', () => {
for (const ecazCount of [2, 4]) {
for (const lead of ['ecaz-seat', 'ally-seat']) {
for (const canceled of [false, true]) {
const profile = quoteEcazOccupyBattle(battle(false, ecazCount, lead, canceled));
const dial = canceled ? 1 : ecazCount / 2 + 1;
assert.deepEqual(quoteEcazOccupyOutcome(profile, {
result: 'traitor', won: true, dial, support: 0,
}), { destroyedArmies: [], fixedLosses: [], casualties: null });
for (const result of ['traitor', 'mutualTraitors', 'explosion'] as const)
assert.deepEqual(quoteEcazOccupyOutcome(profile, {
result, won: false, dial, support: 0,
}), {
destroyedArmies: ['ecaz-seat', 'ally-seat'], fixedLosses: [], casualties: null,
});
for (const result of ['mutualTraitors', 'explosion'] as const)
assert.throws(() => quoteEcazOccupyOutcome(profile, {
result, won: true, dial, support: 0,
}), EcazOccupyBattleError);
}
}
}
});
void test('uncanceled Basic odd Ecaz is source-blocked before commitment, while Advanced keeps ceil losses and floor survivors', () => {
for (const ecazCount of [1, 3, 5, 19]) {
for (const lead of ['ecaz-seat', 'ally-seat']) {
assert.throws(() => quoteEcazOccupyBattle(battle(false, ecazCount, lead)), EcazOccupyBattleError);
const profile = quoteEcazOccupyBattle(battle(true, ecazCount, lead));
const win = quoteEcazOccupyOutcome(profile, {
result: 'normal', won: true, dial: Math.ceil(ecazCount / 2), support: 0,
});
assert.equal(ecazCount - win.fixedLosses[0].normal, Math.floor(ecazCount / 2));
}
}
});
void test('the Occupy rules band is required rather than defaulting malformed or missing input to Advanced', () => {
for (const advanced of [undefined, null, 0, 1, 'false', 'true']) {
const input = { ...battle(true, 4), advanced } as unknown as EcazOccupyBattleInput;
assert.throws(() => quoteEcazOccupyBattle(input), EcazOccupyBattleError);
}
});
void test('Advanced E1–5 ordinary wins lose ceil Ecaz separately and retain floor, with either lead', () => {
for (const [ecazCount, fixed, survivors] of [
[1, 1, 0], [2, 1, 1], [3, 2, 1], [4, 2, 2], [5, 3, 2],
]) {
for (const lead of ['ecaz-seat', 'ally-seat']) {
const profile = quoteEcazOccupyBattle(battle(ecazCount, lead));
const profile = quoteEcazOccupyBattle(battle(true, ecazCount, lead));
const dial = quoteEcazOccupyDial(profile, fixed + 1.5, 1);
assert.equal(dial.variableDial, 1.5);
assert.equal(dial.payer, lead);
@@ -56,7 +209,7 @@ void test('Advanced E1–5 ordinary wins lose ceil Ecaz separately and retain fl
void test('Advanced E1–5 normal defeat destroys both real armies regardless of the selected lead', () => {
for (const ecazCount of [1, 2, 3, 4, 5]) {
for (const lead of ['ecaz-seat', 'ally-seat']) {
const profile = quoteEcazOccupyBattle(battle(ecazCount, lead));
const profile = quoteEcazOccupyBattle(battle(true, ecazCount, lead));
const loss = quoteEcazOccupyOutcome(profile, {
result: 'normal', won: false, dial: Math.ceil(ecazCount / 2), support: 0,
});
@@ -68,7 +221,7 @@ void test('Advanced E1–5 normal defeat destroys both real armies regardless of
});
void test('Ecaz cannot be dialed below its mandatory increment or charged extra support for it', () => {
const profile = quoteEcazOccupyBattle(battle(5));
const profile = quoteEcazOccupyBattle(battle(true, 5));
assert.throws(() => quoteEcazOccupyDial(profile, 2.5, 0), /include 3 fixed Ecaz/);
assert.throws(() => quoteEcazOccupyDial(profile, 3, 1), /legal physical commitment/);
assert.deepEqual(quoteEcazOccupyDial(profile, 3, 0).options, [
@@ -80,7 +233,7 @@ void test('Ecaz cannot be dialed below its mandatory increment or charged extra
});
void test('Fremen and Fedaykin remain free and physically Fremen even when Ecaz supplies the plan', () => {
const input = battle(3, 'ecaz-seat', false, {
const input = battle(true, 3, 'ecaz-seat', false, {
normal: 2, elite: 2, eliteStrength: 2, freeSupport: true,
});
const profile = quoteEcazOccupyBattle({ ...input, ally: { ...input.ally, faction: 'fremen' } });
@@ -106,7 +259,7 @@ void test('Fremen and Fedaykin remain free and physically Fremen even when Ecaz
});
void test('Sardaukar keep typed supported casualties and their native opponent-dependent strength', () => {
const input = battle(3, 'ecaz-seat', false, {
const input = battle(true, 3, 'ecaz-seat', false, {
normal: 3, elite: 2, eliteStrength: 2, freeSupport: false,
});
const emperor = { ...input.ally, faction: 'emperor' as const };
@@ -141,7 +294,7 @@ void test('Sardaukar keep typed supported casualties and their native opponent-d
void test('cancellation retains either selected lead, recomputes its own dial, and leaves the other army undialed on a win', () => {
const fremen: CombatForces = { normal: 2, elite: 2, eliteStrength: 2, freeSupport: true };
for (const lead of ['ecaz-seat', 'ally-seat']) {
const input = battle(5, lead, false, fremen);
const input = battle(true, 5, lead, false, fremen);
const active = quoteEcazOccupyBattle({ ...input, ally: { ...input.ally, faction: 'fremen' } });
assert.equal(quoteEcazOccupyDial(active, 4, 0).forceOwner, 'ally-seat');
const canceled = quoteEcazOccupyBattle({ ...input, canceled: true, ally: { ...input.ally, faction: 'fremen' } });
@@ -172,7 +325,7 @@ void test('cancellation retains either selected lead, recomputes its own dial, a
void test('sole traitor victory waives both pools losses; sole defeat, mutual traitors and explosion destroy the actual side', () => {
for (const lead of ['ecaz-seat', 'ally-seat']) {
for (const canceled of [false, true]) {
const profile = quoteEcazOccupyBattle(battle(5, lead, canceled));
const profile = quoteEcazOccupyBattle(battle(true, 5, lead, canceled));
const dial = canceled ? 0 : 3;
assert.deepEqual(quoteEcazOccupyOutcome(profile, {
result: 'traitor', won: true, dial, support: 0,
@@ -190,7 +343,7 @@ void test('sole traitor victory waives both pools losses; sole defeat, mutual tr
});
void test('funding-limited legal options retain unsupported half dials without spending the fixed contribution', () => {
const profile = quoteEcazOccupyBattle(battle(1, 'ecaz-seat', false, ordinary(2)));
const profile = quoteEcazOccupyBattle(battle(true, 1, 'ecaz-seat', false, ordinary(2, true)));
assert.deepEqual(ecazOccupyDialOptions(profile, 0), [
{ dial: 1, support: 0, variableDial: 0 },
{ dial: 1.5, support: 0, variableDial: 0.5 },
@@ -207,25 +360,25 @@ void test('funding-limited legal options retain unsupported half dials without s
});
void test('nonreciprocal allies, advisors-only or disconnected pools, and foreign lead actors cannot create a combined army', () => {
const input = battle(3);
const input = battle(true, 3);
assert.throws(() => quoteEcazOccupyBattle({
...input, ally: { ...input.ally, ally: null },
}), /reciprocal ally/);
assert.throws(() => quoteEcazOccupyBattle({
...input, ally: { ...input.ally, faction: 'beneGesserit', forces: ordinary(0) },
...input, ally: { ...input.ally, faction: 'beneGesserit', forces: ordinary(0, true) },
}), /storm-connected fighters/);
assert.throws(() => quoteEcazOccupyBattle({
...input, ecaz: { ...input.ecaz, forces: ordinary(0) },
...input, ecaz: { ...input.ecaz, forces: ordinary(0, true) },
}), /storm-connected fighters/);
assert.throws(() => quoteEcazOccupyBattle({ ...input, lead: 'enemy-seat' }), /lead must be Ecaz/);
assert.throws(() => quoteEcazOccupyBattle({ ...input, battleOrderActor: '' }), /battle-order actor/);
assert.throws(() => quoteEcazOccupyBattle({
...input, ally: { ...input.ally, forces: ordinary(21) },
...input, ally: { ...input.ally, forces: ordinary(21, true) },
}), EcazOccupyBattleError);
});
void test('two twenty-counter armies are legal separate pools, not an over-cap merged CombatForces', () => {
const profile = quoteEcazOccupyBattle(battle(20, 'ecaz-seat', false, ordinary(20)));
const profile = quoteEcazOccupyBattle(battle(true, 20, 'ecaz-seat', false, ordinary(20, true)));
const outcome = quoteEcazOccupyOutcome(profile, {
result: 'normal', won: true, dial: 30, support: 20,
});