/
docNemo
/
tactic-hack-core
Обзор
Документация
Войти
/
docNemo
/
tactic-hack-core
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/deduction.ts
29 строк
1 KB
neo
Implement rules engine: geometry, placement, attack reducer, replay, projection, deduction, protocol types
19 июл 2026, 00:03
19 июл 2026, 00:03
d1403fb
Код
Авторство
О чём код?
import { sharedAxis } from "./geometry.js"; import { AXES, Axis, Cell, OpenedCell } from "./types.js"; export interface DashedLines { cell: Cell; axes: Axis[]; } /** * Пунктирные линии по видимой части поля противника: для каждой открытой * клетки с цифрой, все сплошные линии которой раскрыты (цифра полностью * объяснена уничтоженными кораблями), по остальным осям строятся пунктирные * линии. Чистая дедукция для отображения — на игровую логику не влияет. */ export function computeDashedLines( opened: readonly OpenedCell[], revealedShips: readonly Cell[], ): DashedLines[] { const result: DashedLines[] = []; for (const { cell, digit } of opened) { const revealedAxes = revealedShips .map((ship) => sharedAxis(ship, cell)) .filter((axis): axis is Axis => axis !== null); if (revealedAxes.length !== digit) continue; const axes = AXES.filter((axis) => !revealedAxes.includes(axis)); if (axes.length > 0) result.push({ cell, axes }); } return result; }