test: cover multi-turn nation strategy commands

This commit is contained in:
2026-07-26 02:07:26 +00:00
parent 708ee80595
commit 58abd60cbf
6 changed files with 143 additions and 9 deletions
@@ -48,14 +48,23 @@ const DEFAULT_GLOBAL_DELAY = 9;
const PRE_REQ_TURN = 1;
const EXP_DED_GAIN = 5 * (PRE_REQ_TURN + 1);
type InclusiveRandomGenerator = GeneralActionResolveContext['rng'] & {
nextIntInclusive?: (maxInclusive: number) => number;
};
const legacyChoiceIndex = (rng: GeneralActionResolveContext['rng'], length: number): number => {
const inclusive = rng as InclusiveRandomGenerator;
return inclusive.nextIntInclusive ? inclusive.nextIntInclusive(length - 1) : rng.nextInt(0, length);
};
const pickMoveCityId = (rng: GeneralActionResolveContext['rng'], destCityId: number, candidates: City[]): number => {
if (candidates.length === 0) {
return destCityId;
}
let idx = rng.nextInt(0, candidates.length);
let idx = legacyChoiceIndex(rng, candidates.length);
let cityId = candidates[idx]?.id ?? destCityId;
if (cityId === destCityId && candidates.length > 1) {
idx = rng.nextInt(0, candidates.length);
if (cityId === destCityId) {
idx = legacyChoiceIndex(rng, candidates.length);
cityId = candidates[idx]?.id ?? destCityId;
}
return cityId;
+44 -1
View File
@@ -93,8 +93,51 @@ export const disallowDiplomacyBetweenStatus = (disallowList: Record<number, stri
});
export const disallowDiplomacyStatus = (disallowList: Record<number, string>): Constraint => ({
...disallowDiplomacyBetweenStatus(disallowList),
name: 'disallowDiplomacyStatus',
requires: (ctx) => [
...(ctx.nationId !== undefined ? ([{ kind: 'nation', id: ctx.nationId }] as RequirementKey[]) : []),
{ kind: 'diplomacyList' },
],
test: (ctx, view) => {
const general = readGeneral(ctx, view);
const baseNationId = ctx.nationId ?? general?.nationId;
if (baseNationId === undefined) {
return unknownOrDeny(ctx, [], '국가 정보가 없습니다.');
}
const req: RequirementKey = { kind: 'diplomacyList' };
if (!view.has(req)) {
return unknownOrDeny(ctx, [req], '외교 정보가 없습니다.');
}
const entries = view.get(req);
if (!Array.isArray(entries)) {
return unknownOrDeny(ctx, [req], '외교 정보가 없습니다.');
}
for (const value of entries) {
if (!value || typeof value !== 'object') {
continue;
}
const entry = value as {
fromNationId?: number;
srcNationId?: number;
me?: number;
state?: number;
stateCode?: number;
};
const fromNationId = entry.fromNationId ?? entry.srcNationId ?? entry.me;
if (fromNationId !== baseNationId) {
continue;
}
const state = entry.state ?? entry.stateCode;
if (state === undefined) {
continue;
}
const reason = disallowList[state];
if (reason !== undefined) {
return { kind: 'deny', reason };
}
}
return allow();
},
});
export const allowDiplomacyBetweenStatus = (allowList: number[], reason: string): Constraint => ({