/
docNemo
/
tactic-hack-core
Обзор
Документация
Войти
/
docNemo
/
tactic-hack-core
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/projection.ts
42 строки
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 { MatchState } from "./match.js"; import { Cell, OpenedCell, opponentOf, PlayerId } from "./types.js"; /** * Проекция состояния боя для одного игрока. Не содержит позиций * неуничтоженных кораблей противника — единственное, что уходит клиенту. */ export interface PlayerProjection { you: PlayerId; turn: PlayerId; winner: PlayerId | null; own: { ships: Cell[]; destroyed: Cell[]; opened: OpenedCell[]; }; opponent: { opened: OpenedCell[]; destroyedShips: Cell[]; }; } export function projectFor( state: MatchState, player: PlayerId, ): PlayerProjection { const opponent = opponentOf(player); return { you: player, turn: state.turn, winner: state.winner, own: { ships: [...state.setup.placements[player]], destroyed: [...state.destroyed[player]], opened: [...state.opened[player]], }, opponent: { opened: [...state.opened[opponent]], destroyedShips: [...state.destroyed[opponent]], }, }; }