feat(engine): ghost derivation from cross-board piece comparison
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { DuplicateGame } from './game';
|
||||
import { playSymmetric } from './test-helpers';
|
||||
import { ghosts } from './ghosts';
|
||||
|
||||
describe('ghosts', () => {
|
||||
it('reports no ghosts at the start', () => {
|
||||
expect(ghosts(new DuplicateGame())).toEqual([]);
|
||||
});
|
||||
|
||||
it('forms a ghost when a piece is captured on one board but not its twin', () => {
|
||||
const g = new DuplicateGame();
|
||||
// Symmetric opening so all four boards stay identical...
|
||||
playSymmetric(g, [
|
||||
[{ from: 'e2', to: 'e4' }, { from: 'e7', to: 'e5' }],
|
||||
[{ from: 'g1', to: 'f3' }, { from: 'b8', to: 'c6' }],
|
||||
]);
|
||||
// ...then North & South each play Nxe5 (capturing the e5 pawn),
|
||||
// and East captures that knight only on its boards (NE, SE).
|
||||
g.applyMove({ from: 'f3', to: 'e5' }); // N: Nf3xe5 on NW, NE
|
||||
g.applyMove({ from: 'f3', to: 'e5' }); // S: Nf3xe5 on SW, SE
|
||||
g.applyMove({ from: 'c6', to: 'e5' }); // E: Nc6xe5 on NE, SE — captures the white knight
|
||||
// North's knight on e5 survives on NW but was captured on NE -> NW/e5 is a ghost.
|
||||
// South's knight on e5 survives on SW but was captured on SE -> SW/e5 is a ghost.
|
||||
const result = ghosts(g).sort((x, y) => (x.board < y.board ? -1 : 1));
|
||||
expect(result).toEqual([
|
||||
{ board: 'NW', square: 'e5' },
|
||||
{ board: 'SW', square: 'e5' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user