Files
dualfroz 4bc47d7966 show endgame glyph on another piece when there is no king - closes #21971
Antichess and horde can end with a side that has no king, so the
result glyph had nothing to sit on. Fall back to the queen, rook,
bishop, knight and pawn, in that order.
2026-10-16 09:54:10 +02:00

27 lines
1.1 KiB
TypeScript

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { endgameShapes } from '../src/game/endgame';
import type { StatusName } from '../src/game/status';
const origs = (fen: FEN, winner: Color | undefined, status: StatusName) =>
endgameShapes(fen, winner, status).map(shape => shape.orig);
test('glyph goes on the king when there is one', () => {
assert.deepStrictEqual(origs('4k3/8/8/8/8/8/8/Q3K3 w - - 0 1', 'black', 'resign'), ['e1']);
});
test('glyph falls back to the strongest piece without a king', () => {
assert.deepStrictEqual(origs('8/8/8/8/8/8/8/6N1 b - - 0 28', 'black', 'variantEnd'), ['g1']);
assert.deepStrictEqual(origs('8/8/8/8/8/8/2P5/1NR5 b - - 0 40', 'black', 'variantEnd'), ['c1']);
assert.deepStrictEqual(origs('8/8/8/8/8/8/2P5/1N6 b - - 0 40', 'black', 'variantEnd'), ['b1']);
});
test('draw glyphs show for a side without a king', () => {
assert.deepStrictEqual(origs('4k3/8/8/8/8/8/PPPPPPPP/8 w - - 0 1', undefined, 'stalemate'), ['a2', 'e8']);
});
test('no glyph for a side without pieces', () => {
assert.deepStrictEqual(origs('8/8/8/8/8/8/8/6N1 b - - 0 28', 'white', 'variantEnd'), []);
});