Support Basic Kull and Leader Skills with Ecaz
Verify and publish checkpoint container / container (push) Successful in 10m49s
Verify and publish checkpoint container / container (push) Successful in 10m49s
This commit is contained in:
1 parent
4270b36be7
commit
4fba4860e1
11 files changed
+415
-13
No files matched your search
@@ -0,0 +1,170 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
applyAction, createGame, joinGame, newPlayer, normalizeAutomaticGame, viewGame,
|
||||
type Action, type Game,
|
||||
} from '../game/engine';
|
||||
import { LEADER_SKILL_CARDS } from '../game/leader-skill-cards';
|
||||
import { validateLeaderSkills } from '../game/leader-skills';
|
||||
import { botActions } from '../game/bots';
|
||||
import { DIFFICULTIES } from '../game/bot-profiles';
|
||||
import { SEMUTA_DRUG_ID } from '../game/semuta-drug';
|
||||
import { RECRUITS_CARD_ID } from '../game/recruits';
|
||||
import { takeKullCard } from './fixture-choam-kull';
|
||||
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
||||
import { advanceSemutaNexusTrade, type SemutaNexusTradeStep } from './fixture-semuta-nexus-trade';
|
||||
|
||||
const act = (game: Game, actor: string, action: Action) => applyAction(game, actor, action);
|
||||
function seat(game: Game, id: string) {
|
||||
const player = game.players.find(candidate => candidate.id === id);
|
||||
assert.ok(player); return player;
|
||||
}
|
||||
function inventory(game: Game) {
|
||||
const ids = [ ...game.deck, ...game.discard, ...(game.auction?.cards.slice(game.auction.index) ?? []),
|
||||
...(game.ixAuction?.cards ?? []), ...(game.richeseCache ?? []), ...(game.richeseRemoved ?? []),
|
||||
...game.players.flatMap(player => player.hand) ].map(card => card.id).sort();
|
||||
assert.equal(new Set(ids).size, ids.length); return ids;
|
||||
}
|
||||
function skills(game: Game) {
|
||||
assert.ok(game.leaderSkills);
|
||||
validateLeaderSkills(game.leaderSkills, game.players);
|
||||
assert.deepEqual([...game.leaderSkills.deck,
|
||||
...Object.values(game.leaderSkills.offers).flatMap(offer => offer.cards),
|
||||
...game.leaderSkills.assignments.map(row => row.skill)].sort(),
|
||||
LEADER_SKILL_CARDS.map(card => card.id).sort());
|
||||
}
|
||||
const clean = (game: Game) => !game.phaseOpening && !game.response && !game.decision && !game.truthtrance;
|
||||
|
||||
/** Public Basic lobby and actual skill training. Only unopened Spice ordering
|
||||
* and conserved held Treachery positions are staged before the Karama attempt. */
|
||||
function fixture(independent: boolean, richese = false) {
|
||||
let game = createGame('KULLSKILLS', newPlayer('c', 'CHOAM', 'choam'), false, ['ix', 'choam', 'ecaz']);
|
||||
for (const [id, faction] of [['a', 'atreides'], ['g', 'guild'], ['h', 'harkonnen']] as const)
|
||||
joinGame(game, newPlayer(id, faction, faction));
|
||||
if (richese) joinGame(game, newPlayer('r', 'Richese', 'richese'));
|
||||
for (const moduleName of [...(independent ? ['ecazTreachery'] : []), 'leaderSkills', 'kullPreview'])
|
||||
game = act(game, 'c', { type: 'moduleOption', module: moduleName, enabled: true });
|
||||
const selected = viewGame(game, 'c').lobbyModules!;
|
||||
assert.equal(selected.nexusCards, false); assert.equal(selected.leaderSkills, true);
|
||||
assert.equal(selected.kullPreview, true);
|
||||
if (independent) assert.equal(selected.ecazTreachery, true);
|
||||
for (const player of game.players) game = act(game, player.id, { type: 'ready' });
|
||||
game = act(game, 'c', { type: 'start' });
|
||||
assert.equal(game.kullPreview, true); assert.ok(!game.nexusKullPreview && !game.nexusCards);
|
||||
assert.equal(game.ecazTreachery === true, independent);
|
||||
if (richese) { assert.equal(game.semutaPreview, true); assert.ok(game.richeseCache?.length); }
|
||||
const setup: SemutaNexusTradeStep[] = [];
|
||||
game = advanceSemutaNexusTrade(game, state => state.status === 'playing', setup);
|
||||
assert.equal(setup.filter(row => row.action.type === 'leaderSkill').length, game.players.length);
|
||||
assert.equal(game.leaderSkills!.assignments.length, game.players.length);
|
||||
skills(game);
|
||||
const originalSkills = structuredClone(game.leaderSkills), originalCards = inventory(game);
|
||||
game = advanceSemutaNexusTrade(game, beforeIxSpiceDraw);
|
||||
orderIxSpiceCards(game, ['land', 'land']);
|
||||
game = advanceSemutaNexusTrade(game, state => state.phase === 5 && state.active === 'g' && clean(state));
|
||||
for (const player of game.players) game.deck.push(...player.hand.splice(0));
|
||||
const printed = takeKullCard(game, 'ix-kull-wahad'); seat(game, 'c').hand.push(printed);
|
||||
const original = takeKullCard(game, 'karama'); seat(game, 'g').hand.push(original);
|
||||
if (richese) seat(game, 'r').hand.push(takeKullCard(game, SEMUTA_DRUG_ID));
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
assert.deepEqual(game.leaderSkills, originalSkills);
|
||||
game = act(game, 'g', { type: 'card', mode: 'shipment', card: original.id, target: 'g' });
|
||||
assert.ok(game.pendingKull);
|
||||
return { game, printed: printed.id, original: original.id, event: game.pendingKull.event, originalCards, originalSkills };
|
||||
}
|
||||
|
||||
function usePrinted(f: ReturnType<typeof fixture>) {
|
||||
assert.ok(viewGame(f.game, 'c').kullReaction?.plays.some(play => play.source === 'printed' && play.card.id === f.printed));
|
||||
let game = act(f.game, 'c', { type: 'kullDecision', event: f.event, source: 'printed', card: f.printed });
|
||||
for (let n = 0; game.pendingKull && n < 20; n++) {
|
||||
const responder = game.players.find(player => {
|
||||
const controls = viewGame(game, player.id).responseControls;
|
||||
return controls && !controls.hasPassed && controls.cancelCards.length > 0;
|
||||
});
|
||||
game = responder ? act(game, responder.id, { type: 'passResponse' }) : normalizeAutomaticGame(game);
|
||||
}
|
||||
assert.equal(game.pendingKull, null);
|
||||
assert.equal(seat(game, 'g').hand.some(card => card.id === f.original), true);
|
||||
return game;
|
||||
}
|
||||
|
||||
for (const independent of [false, true]) void test(
|
||||
`Basic public printed Kull retains trained Skills${independent ? ' and independent Ecaz cards' : ''}`, () => {
|
||||
const f = fixture(independent);
|
||||
for (const difficulty of DIFFICULTIES) {
|
||||
const view = viewGame(f.game, 'c'); view.players.find(player => player.id === 'c')!.bot = difficulty;
|
||||
const choice = botActions(view).find(action => action.type === 'kullDecision');
|
||||
assert.ok(choice); assert.doesNotThrow(() => act(f.game, 'c', choice));
|
||||
}
|
||||
const game = usePrinted(f);
|
||||
assert.equal(game.discard.filter(card => card.id === f.printed).length, 1);
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
assert.deepEqual(game.leaderSkills, f.originalSkills); skills(game);
|
||||
},
|
||||
);
|
||||
|
||||
void test('Richese can claim printed Kull with Semuta and retain original Skills and cache', () => {
|
||||
const f = fixture(true, true);
|
||||
let game = usePrinted(f);
|
||||
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
|
||||
assert.deepEqual(pending.batch.entries.map(entry => entry.card.id), [f.printed]);
|
||||
assert.equal(viewGame(game, 'r').semutaReaction?.canCommit, true);
|
||||
game = act(game, 'r', { type: 'semutaCommit', event: pending.batch.event });
|
||||
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
|
||||
game = act(game, 'r', { type: 'semutaSelect', event: pending.batch.event, card: f.printed });
|
||||
assert.equal(game.pendingTreacheryDiscard, null);
|
||||
assert.ok(seat(game, 'r').hand.some(card => card.id === f.printed));
|
||||
assert.ok(game.discard.some(card => card.id === SEMUTA_DRUG_ID));
|
||||
assert.deepEqual(inventory(game), f.originalCards);
|
||||
assert.deepEqual(game.leaderSkills, f.originalSkills); skills(game);
|
||||
});
|
||||
|
||||
for (const claim of [false, true]) void test(
|
||||
`Basic printed Kull and Skills retain Recruits while Richese ${claim ? 'claims' : 'passes'} with Semuta`, () => {
|
||||
let game = createGame('KULLSKILLSRECRUITS', newPlayer('c', 'CHOAM', 'choam'), false, ['ix', 'choam']);
|
||||
for (const [id, faction] of [['r', 'richese'], ['a', 'atreides'], ['g', 'guild']] as const)
|
||||
joinGame(game, newPlayer(id, faction, faction));
|
||||
for (const moduleName of ['ecazTreachery', 'leaderSkills', 'kullPreview'])
|
||||
game = act(game, 'c', { type: 'moduleOption', module: moduleName, enabled: true });
|
||||
for (const player of game.players) game = act(game, player.id, { type: 'ready' });
|
||||
game = act(game, 'c', { type: 'start' });
|
||||
assert.equal(game.ecazTreachery, true);
|
||||
assert.equal(game.kullPreview, true);
|
||||
assert.equal(game.semutaPreview, true);
|
||||
assert.ok(game.leaderSkills && !game.nexusCards && !game.nexusKullPreview);
|
||||
const setup: SemutaNexusTradeStep[] = [];
|
||||
game = advanceSemutaNexusTrade(game, state => state.status === 'playing', setup);
|
||||
assert.equal(setup.filter(row => row.action.type === 'leaderSkill').length, game.players.length);
|
||||
game = advanceSemutaNexusTrade(game, beforeIxSpiceDraw);
|
||||
orderIxSpiceCards(game, ['land', 'land']);
|
||||
game = advanceSemutaNexusTrade(game, state => state.phase === 4 && clean(state) && !state.pendingTreacheryDiscard);
|
||||
const originalCards = inventory(game), originalSkills = structuredClone(game.leaderSkills);
|
||||
for (const id of ['a', 'r']) game.deck.push(...seat(game, id).hand.splice(0));
|
||||
seat(game, 'a').hand.push(takeKullCard(game, RECRUITS_CARD_ID));
|
||||
seat(game, 'r').hand.push(takeKullCard(game, SEMUTA_DRUG_ID));
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
const preview = viewGame(game, 'a').recruitsPreview?.play;
|
||||
assert.ok(preview && !preview.blocked);
|
||||
game = act(game, 'a', { type: 'card', card: RECRUITS_CARD_ID });
|
||||
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
|
||||
assert.equal(pending.continuation.kind, 'ordinaryCardDiscard');
|
||||
assert.deepEqual(pending.batch.entries.map(entry => entry.card.id), [RECRUITS_CARD_ID]);
|
||||
assert.equal(game.recruits?.turn, game.turn);
|
||||
if (claim) {
|
||||
assert.equal(viewGame(game, 'r').semutaReaction?.canCommit, true);
|
||||
game = act(game, 'r', { type: 'semutaCommit', event: pending.batch.event });
|
||||
if (game.pendingTreacheryDiscard?.reaction?.stage === 'select')
|
||||
game = act(game, 'r', { type: 'semutaSelect', event: pending.batch.event, card: RECRUITS_CARD_ID });
|
||||
} else {
|
||||
for (const player of game.players) game = act(game, player.id, { type: 'semutaPass', event: pending.batch.event });
|
||||
}
|
||||
assert.equal(game.pendingTreacheryDiscard, null);
|
||||
assert.equal(viewGame(game, 'a').revival.freeRemaining, 4);
|
||||
assert.equal(viewGame(game, 'a').revival.limit, 7);
|
||||
assert.equal(seat(game, 'r').hand.some(card => card.id === RECRUITS_CARD_ID), claim);
|
||||
assert.equal(game.discard.some(card => card.id === RECRUITS_CARD_ID), !claim);
|
||||
assert.equal(game.discard.some(card => card.id === SEMUTA_DRUG_ID), claim);
|
||||
assert.deepEqual(inventory(game), originalCards);
|
||||
assert.deepEqual(game.leaderSkills, originalSkills); skills(game);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,62 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { basicKullLeaderSkillsProfile, type FactionModuleProfile } from '../game/faction-module-profile';
|
||||
import { independentTreacheryLeaderSkillsProfile, ordinaryLeaderSkillModeSupported } from '../game/leader-skill-profile';
|
||||
import { bureaucratPaymentModeSupported, quoteBureaucratPayment } from '../game/bureaucrat-payment';
|
||||
import { mentatQuestionModeSupported } from '../game/mentat-question';
|
||||
import { spiceBankerModeSupported } from '../game/spice-banker';
|
||||
|
||||
const original: FactionModuleProfile = {
|
||||
advanced: false,
|
||||
expansions: ['ix', 'choam', 'ecaz'],
|
||||
players: [{ faction: 'choam' }, { faction: 'richese' }, { faction: 'ecaz' }],
|
||||
leaderSkills: {},
|
||||
};
|
||||
|
||||
void test('Basic Kull and Skills retain public skill authority through setup and the live Kull stamp', () => {
|
||||
for (const independent of [false, true]) for (const semuta of [false, true]) for (const stamped of [false, true]) {
|
||||
const game = { ...original, ecazTreachery: independent,
|
||||
...(semuta ? { semutaPreview: true } : {}),
|
||||
...(stamped ? { kullPreview: true } : {}) };
|
||||
const label = `independent=${independent}, semuta=${semuta}, stamped=${stamped}`;
|
||||
assert.equal(basicKullLeaderSkillsProfile(game), true, label);
|
||||
assert.equal(independentTreacheryLeaderSkillsProfile(game), independent, label);
|
||||
assert.equal(ordinaryLeaderSkillModeSupported(game), true, label);
|
||||
assert.equal(mentatQuestionModeSupported(game), true, label);
|
||||
assert.equal(spiceBankerModeSupported(game), true, label);
|
||||
assert.equal(bureaucratPaymentModeSupported(game), true, label);
|
||||
}
|
||||
});
|
||||
|
||||
void test('Bureaucrat retains the ordinary amount threshold and phase limit', () => {
|
||||
const game = { ...original, ecazTreachery: true, semutaPreview: true, kullPreview: true };
|
||||
assert.equal(bureaucratPaymentModeSupported(game), true);
|
||||
const payment = { owner: 'ecaz', payer: 'choam', payee: 'richese', amount: 7,
|
||||
turn: 2, phase: 3, used: [] };
|
||||
assert.deepEqual(quoteBureaucratPayment(payment), { redirect: 2, income: 5 });
|
||||
assert.equal(quoteBureaucratPayment({ ...payment, amount: 4 }), null);
|
||||
assert.equal(quoteBureaucratPayment({ ...payment,
|
||||
used: [{ event: 'used', owner: 'ecaz', turn: 2, phase: 3, signature: '' }] }), null);
|
||||
});
|
||||
|
||||
void test('standalone Kull and Skills reject unrelated modules and unregistered rosters', () => {
|
||||
const invalid: Array<[string, Partial<FactionModuleProfile>]> = [
|
||||
['Advanced', { advanced: true }],
|
||||
['missing Skills', { leaderSkills: null }],
|
||||
['Nexus', { nexusCards: {} }],
|
||||
['Nexus Kull stamp', { nexusKullPreview: true }],
|
||||
['no CHOAM seat', { players: [{ faction: 'richese' }, { faction: 'ecaz' }] }],
|
||||
['duplicate faction', { players: [{ faction: 'choam' }, { faction: 'choam' }] }],
|
||||
['unselected faction', { expansions: ['ix', 'choam'] }],
|
||||
['duplicate deck', { expansions: ['ix', 'choam', 'ix'] }],
|
||||
['missing Ix deck', { expansions: ['choam', 'ecaz'] }],
|
||||
['Homeworlds', { homeworlds: {} }],
|
||||
['Discovery', { discoveryEnabled: true }],
|
||||
['Tech', { techTokens: {} }],
|
||||
['Strongholds', { strongholdCards: {} }],
|
||||
['unrelated betrayal', { richeseBetrayalPreview: true }],
|
||||
['Semuta without Richese', { semutaPreview: true, players: [{ faction: 'choam' }, { faction: 'ecaz' }] }],
|
||||
];
|
||||
for (const [label, changes] of invalid)
|
||||
assert.equal(basicKullLeaderSkillsProfile({ ...original, ...changes }), false, label);
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { applyAction, createGame, joinGame, newPlayer, viewGame, type Action, type Game } from '../game/engine';
|
||||
import { LEADER_SKILL_CARDS } from '../game/leader-skill-cards';
|
||||
import { validateLeaderSkills } from '../game/leader-skills';
|
||||
import { validateNexusCards } from '../game/nexus-cards';
|
||||
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
||||
import { nextSemutaNexusTradeNativeStep } from './fixture-semuta-nexus-trade';
|
||||
|
||||
const act = (g: Game, id: string, action: Action) => applyAction(g, id, action);
|
||||
const seat = (g: Game, id: string) => { const p = g.players.find(row => row.id === id); assert.ok(p); return p; };
|
||||
const clean = (g: Game) => !g.response && !g.phaseOpening && !g.decision && !g.truthtrance && !g.pendingTreacheryDiscard;
|
||||
function reach(g: Game, until: (g: Game) => boolean) {
|
||||
for (let i = 0; i < 2000; i++) {
|
||||
if (until(g)) return g;
|
||||
assert.notEqual(g.status, 'finished', `Game ended at ${g.turn}/${g.phase}: ${JSON.stringify(g.log.slice(-5))}`);
|
||||
if (!g.response && !g.phaseOpening && g.decision?.kind === 'ecazPlacement')
|
||||
g = act(g, g.decision.player, { type: 'decision', decline: true });
|
||||
else {
|
||||
const next = nextSemutaNexusTradeNativeStep(g);
|
||||
g = act(g, next.actor, next.action);
|
||||
}
|
||||
}
|
||||
throw Error('Native Ecaz/Nexus/Kull/Skills progression did not reach its boundary');
|
||||
}
|
||||
function inventory(g: Game) {
|
||||
return [...g.deck, ...g.discard, ...(g.richeseCache ?? []), ...(g.richeseRemoved ?? []),
|
||||
...(g.auction?.cards.slice(g.auction.index) ?? []), ...(g.ixAuction?.cards ?? []),
|
||||
...g.players.flatMap(p => p.hand)].map(card => card.id).sort();
|
||||
}
|
||||
function physicalSkills(g: Game) {
|
||||
assert.ok(g.leaderSkills); validateLeaderSkills(g.leaderSkills, g.players);
|
||||
const state = g.leaderSkills;
|
||||
assert.deepEqual([...state.deck, ...Object.values(state.offers).flatMap(o => o.cards),
|
||||
...state.assignments.map(a => a.skill)].sort(), LEADER_SKILL_CARDS.map(c => c.id).sort());
|
||||
if (g.nexusCards) validateNexusCards(g.nexusCards.cards!, g.players);
|
||||
}
|
||||
|
||||
for (const nexus of [false, true]) for (const independent of [false, true]) void test(
|
||||
`Public Basic Ecaz plays an Occupy battle with ${nexus ? 'Nexus ' : 'printed '}Kull and Skills${independent ? ' and independent Ecaz cards' : ''}`, () => {
|
||||
let g = createGame('NEXUSKULLECAZ', newPlayer('c', 'CHOAM', 'choam'), false, ['ix', 'choam', 'ecaz']);
|
||||
for (const [id, faction] of [['e', 'ecaz'], ['a', 'atreides'], ['g', 'guild']] as const)
|
||||
joinGame(g, newPlayer(id, faction, faction));
|
||||
for (const name of [...(independent ? ['ecazTreachery'] : []), ...(nexus ? ['nexusCards'] : []), 'leaderSkills', 'kullPreview'])
|
||||
g = act(g, 'c', { type: 'moduleOption', module: name, enabled: true });
|
||||
for (const p of g.players) g = act(g, p.id, { type: 'ready' });
|
||||
g = act(g, 'c', { type: 'start' });
|
||||
assert.equal(g.ecazOccupyPreview, true);
|
||||
assert.equal(g.kullPreview, true); assert.equal(g.nexusKullPreview === true, nexus);
|
||||
assert.equal(!!g.nexusCards, nexus);
|
||||
assert.equal(g.ecazTreachery === true, independent);
|
||||
g = reach(g, state => state.status === 'playing');
|
||||
assert.equal(g.leaderSkills!.assignments.length, g.players.length);
|
||||
physicalSkills(g);
|
||||
const cards = inventory(g);
|
||||
// Controlled board staging conserves each faction's pieces; unopened Spice
|
||||
// order produces the ordinary turn-two worm/alliance without assigning it.
|
||||
for (const p of g.players) {
|
||||
p.reserves += Object.values(p.forces).reduce((sum, n) => sum + n, 0);
|
||||
p.forces = {};
|
||||
}
|
||||
g = reach(g, beforeIxSpiceDraw); orderIxSpiceCards(g, ['land', 'land']);
|
||||
g = reach(g, state => state.turn === 2 && beforeIxSpiceDraw(state));
|
||||
orderIxSpiceCards(g, ['worm', 'land', 'land']);
|
||||
g = reach(g, state => !!state.nexus && !state.spiceWindow && clean(state));
|
||||
g = act(g, 'e', { type: 'alliance', target: 'a' });
|
||||
g = act(g, 'a', { type: 'alliance', target: 'e' });
|
||||
g = reach(g, state => state.turn === 2 && state.phase === 5 && clean(state));
|
||||
assert.equal(seat(g, 'e').ally, 'a'); assert.equal(seat(g, 'a').ally, 'e');
|
||||
const territory = g.storm === 11 ? 'arrakeen' : 'carthag';
|
||||
const sector = territory === 'carthag' ? 11 : 10;
|
||||
const location = `${territory}:${sector}`;
|
||||
for (const [id, amount] of [['e', 5], ['a', 4], ['g', 3]] as const) {
|
||||
const p = seat(g, id); assert.ok(p.reserves >= amount);
|
||||
p.reserves -= amount; p.forces[location] = amount;
|
||||
}
|
||||
g = reach(g, state => state.turn === 2 && state.phase === 6 && clean(state));
|
||||
const choice = viewGame(g, g.active!).battleChoices.find(row => row.territory === territory);
|
||||
assert.ok(choice);
|
||||
g = act(g, choice.chooser, { type: 'chooseBattle', territory,
|
||||
target: choice.attacker === choice.chooser ? choice.defender : choice.attacker });
|
||||
g = reach(g, state => !state.response && !state.phaseOpening && state.decision?.kind === 'ecazBattleLead');
|
||||
assert.ok(g.decision?.kind === 'ecazBattleLead');
|
||||
const event = g.decision.event;
|
||||
g = act(g, 'e', { type: 'decision', event, lead: 'e' });
|
||||
g = reach(g, state => !!state.battle && !state.battle.preparation &&
|
||||
state.battle.preLeader?.closed !== false && clean(state));
|
||||
const view = viewGame(g, 'e');
|
||||
assert.ok(view.battle?.ecazOccupy?.profile);
|
||||
assert.equal(view.battle.ecazOccupy.profile.fixedEcazDial, 3);
|
||||
physicalSkills(g); assert.deepEqual(inventory(g), cards);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user