feat(chess): wire PRESET_REGISTRY into ChessEngine.getAllLegalMoves
This commit is contained in:
parent
dbf3b4551d
commit
51afd9a6f5
4 changed files with 278 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue