feat(chess): wire PRESET_REGISTRY into ChessEngine.getAllLegalMoves

This commit is contained in:
Joey Yakimowich-Payne 2026-04-17 11:31:07 -06:00
commit 51afd9a6f5
No known key found for this signature in database
4 changed files with 278 additions and 14 deletions

View file

@ -47,6 +47,7 @@ import {
} from "./rules/draws.js";
import { applyCapture } from "./rules/capture.js";
import type { LegalMove } from "./rules/types.js";
import { PRESET_REGISTRY } from "./presets/index.js";
type MoveGetter = (session: Session, pieceId: EntityId) => LegalMove[];
@ -129,6 +130,24 @@ export class ChessEngine {
}
}
// Apply active preset rules: add extra moves, then run filter hooks.
// Order matters — `getExtraMoves` contributes to the set that
// `filterMoves` operates on, so every active preset sees the full
// aggregated set (including prior presets' additions).
for (const preset of PRESET_REGISTRY.getActive()) {
if (preset.getExtraMoves) {
pieceMoves = [
...pieceMoves,
...preset.getExtraMoves(this, piece.id),
];
}
}
for (const preset of PRESET_REGISTRY.getActive()) {
if (preset.filterMoves) {
pieceMoves = preset.filterMoves(pieceMoves, this, piece.id);
}
}
moves.push(...pieceMoves);
}