- Implemented the 화계 action in the general turn actions, allowing generals to perform sabotage on enemy cities. - Created CommandResolver and ActionResolver classes to handle the logic and resolution of the action. - Added necessary constraints to ensure valid conditions for executing the action, including checks for city occupation and resource requirements. - Updated the general action index to include the new 화계 action. - Introduced evaluation functions for constraints to manage action prerequisites effectively. - Enhanced logging for successful and failed attempts of the 화계 action, providing detailed feedback on outcomes.
39 lines
989 B
TypeScript
39 lines
989 B
TypeScript
import type {
|
|
Constraint,
|
|
ConstraintContext,
|
|
ConstraintResult,
|
|
RequirementKey,
|
|
StateView,
|
|
} from './types.js';
|
|
|
|
export const evaluateConstraints = (
|
|
constraints: Constraint[],
|
|
ctx: ConstraintContext,
|
|
view: StateView
|
|
): ConstraintResult => {
|
|
for (const constraint of constraints) {
|
|
const missing = constraint
|
|
.requires(ctx)
|
|
.filter((req) => !view.has(req));
|
|
if (missing.length > 0 && ctx.mode === 'precheck') {
|
|
return { kind: 'unknown', missing };
|
|
}
|
|
const result = constraint.test(ctx, view);
|
|
if (result.kind !== 'allow') {
|
|
return result;
|
|
}
|
|
}
|
|
return { kind: 'allow' };
|
|
};
|
|
|
|
export const collectRequirements = (
|
|
constraints: Constraint[],
|
|
ctx: ConstraintContext
|
|
): RequirementKey[] => {
|
|
const keys: RequirementKey[] = [];
|
|
for (const constraint of constraints) {
|
|
keys.push(...constraint.requires(ctx));
|
|
}
|
|
return keys;
|
|
};
|