feat(minigames): make the Ammo Depot an L-shaped block with four-way rotation
The Ammo Depot is now a 3-cell L (a 2x2 box minus one corner) instead of a 2-cell line. Emplacement orientation becomes quarter-turns (0-3) so the L can turn through all four; lines still use 0/1, the square ignores it. The editor seeds an emplacement's rotation by matching its stored cells against each orientation, the rotate toggle shows "Rotate 90°" for the L, and the engine/rotation tests cover the four L orientations.
This commit is contained in:
parent
8afbf00805
commit
c8f625b12c
5 changed files with 171 additions and 60 deletions
|
|
@ -15,8 +15,9 @@ import { gridDesignation, METERS_PER_CELL, type GridPoint } from "@/lib/minigame
|
||||||
import {
|
import {
|
||||||
FOB_FLEET,
|
FOB_FLEET,
|
||||||
VERSUS_WAITING_USER_ID,
|
VERSUS_WAITING_USER_ID,
|
||||||
type FobOrientation,
|
|
||||||
type FobPlacement,
|
type FobPlacement,
|
||||||
|
type FobRotation,
|
||||||
|
type FobShape,
|
||||||
} from "@/lib/minigames/call-for-fire-versus/constants";
|
} from "@/lib/minigames/call-for-fire-versus/constants";
|
||||||
import { cellsForFob } from "@/lib/minigames/call-for-fire-versus/engine";
|
import { cellsForFob } from "@/lib/minigames/call-for-fire-versus/engine";
|
||||||
import type { VersusFobView, VersusShotView } from "@/lib/minigames/call-for-fire-versus/types";
|
import type { VersusFobView, VersusShotView } from "@/lib/minigames/call-for-fire-versus/types";
|
||||||
|
|
@ -61,6 +62,25 @@ function fobStyle(id: string) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Distinct orientations a shape supports (the square has one, the L has four). */
|
||||||
|
function turnsForShape(shape: FobShape): number {
|
||||||
|
if (shape === "square") return 1;
|
||||||
|
if (shape === "l") return 4;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Toggle-button label for the selected emplacement's current orientation. */
|
||||||
|
function rotationLabel(shape: FobShape, orientation: FobRotation): string {
|
||||||
|
if (shape === "square") return "Fixed";
|
||||||
|
if (shape === "l") return "Rotate 90°";
|
||||||
|
return orientation % 2 === 0 ? "Horizontal" : "Vertical";
|
||||||
|
}
|
||||||
|
|
||||||
|
function sameCellSet(a: readonly GridPoint[], b: readonly GridPoint[]): boolean {
|
||||||
|
if (a.length !== b.length) return false;
|
||||||
|
return a.every((cell) => b.some((other) => other.x === cell.x && other.y === cell.y));
|
||||||
|
}
|
||||||
|
|
||||||
function key(point: GridPoint): string {
|
function key(point: GridPoint): string {
|
||||||
return `${point.x},${point.y}`;
|
return `${point.x},${point.y}`;
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +105,9 @@ function randomFleet(): Record<string, FobPlacement> {
|
||||||
const occupied = new Set<string>();
|
const occupied = new Set<string>();
|
||||||
for (const definition of FOB_FLEET) {
|
for (const definition of FOB_FLEET) {
|
||||||
for (let attempt = 0; attempt < 800; attempt += 1) {
|
for (let attempt = 0; attempt < 800; attempt += 1) {
|
||||||
const orientation: FobOrientation = Math.random() < 0.5 ? "h" : "v";
|
const orientation = Math.floor(
|
||||||
|
Math.random() * turnsForShape(definition.shape),
|
||||||
|
) as FobRotation;
|
||||||
const origin = {
|
const origin = {
|
||||||
x: Math.floor(Math.random() * BOARD),
|
x: Math.floor(Math.random() * BOARD),
|
||||||
y: Math.floor(Math.random() * BOARD),
|
y: Math.floor(Math.random() * BOARD),
|
||||||
|
|
@ -115,16 +137,27 @@ function PlacementPhase({
|
||||||
const [placements, setPlacements] = useState<Record<string, FobPlacement>>(() => {
|
const [placements, setPlacements] = useState<Record<string, FobPlacement>>(() => {
|
||||||
const initial: Record<string, FobPlacement> = {};
|
const initial: Record<string, FobPlacement> = {};
|
||||||
for (const fob of match.you.fleet) {
|
for (const fob of match.you.fleet) {
|
||||||
const origin = fob.cells[0];
|
const definition = FOB_FLEET.find((d) => d.id === fob.id);
|
||||||
if (!origin) continue;
|
if (!definition || fob.cells.length === 0) continue;
|
||||||
const orientation: FobOrientation =
|
const origin = {
|
||||||
fob.size > 1 && fob.cells[1] && fob.cells[1].x !== origin.x ? "h" : "v";
|
x: Math.min(...fob.cells.map((cell) => cell.x)),
|
||||||
|
y: Math.min(...fob.cells.map((cell) => cell.y)),
|
||||||
|
};
|
||||||
|
const turns = turnsForShape(definition.shape);
|
||||||
|
let orientation: FobRotation = 0;
|
||||||
|
for (let t = 0; t < turns; t += 1) {
|
||||||
|
const cells = cellsForFob(definition, origin, t as FobRotation, BOARD);
|
||||||
|
if (cells && sameCellSet(cells, fob.cells)) {
|
||||||
|
orientation = t as FobRotation;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
initial[fob.id] = { assetId: fob.id, origin, orientation };
|
initial[fob.id] = { assetId: fob.id, origin, orientation };
|
||||||
}
|
}
|
||||||
return initial;
|
return initial;
|
||||||
});
|
});
|
||||||
const [selectedId, setSelectedId] = useState<string>(FOB_FLEET[0].id);
|
const [selectedId, setSelectedId] = useState<string>(FOB_FLEET[0].id);
|
||||||
const [orientation, setOrientation] = useState<FobOrientation>("h");
|
const [orientation, setOrientation] = useState<FobRotation>(0);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
|
@ -204,8 +237,10 @@ function PlacementPhase({
|
||||||
(assetId: string) => {
|
(assetId: string) => {
|
||||||
const definition = FOB_FLEET.find((f) => f.id === assetId);
|
const definition = FOB_FLEET.find((f) => f.id === assetId);
|
||||||
const placement = placements[assetId];
|
const placement = placements[assetId];
|
||||||
if (!definition || !placement || definition.shape === "square") return;
|
if (!definition || !placement) return;
|
||||||
const nextOrientation: FobOrientation = placement.orientation === "h" ? "v" : "h";
|
const turns = turnsForShape(definition.shape);
|
||||||
|
if (turns <= 1) return; // squares do not rotate
|
||||||
|
const nextOrientation = ((placement.orientation + 1) % turns) as FobRotation;
|
||||||
const cells = cellsForFob(definition, placement.origin, nextOrientation, BOARD);
|
const cells = cellsForFob(definition, placement.origin, nextOrientation, BOARD);
|
||||||
if (!cells) {
|
if (!cells) {
|
||||||
setError(`${definition.label} does not fit rotated there.`);
|
setError(`${definition.label} does not fit rotated there.`);
|
||||||
|
|
@ -263,8 +298,9 @@ function PlacementPhase({
|
||||||
rotateAsset(selectedId);
|
rotateAsset(selectedId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setOrientation((value) => (value === "h" ? "v" : "h"));
|
const turns = turnsForShape(selectedDefinition.shape);
|
||||||
}, [rotateAsset, selectedId, selectedIsSquare, selectedPlacement]);
|
setOrientation((value) => ((value + 1) % turns) as FobRotation);
|
||||||
|
}, [rotateAsset, selectedDefinition.shape, selectedId, selectedIsSquare, selectedPlacement]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
|
|
@ -350,7 +386,7 @@ function PlacementPhase({
|
||||||
title={selectedIsSquare ? "The Command Post is a fixed 2x2 block." : undefined}
|
title={selectedIsSquare ? "The Command Post is a fixed 2x2 block." : undefined}
|
||||||
onClick={toggleOrientation}
|
onClick={toggleOrientation}
|
||||||
>
|
>
|
||||||
<RotateCcw /> {effectiveOrientation === "h" ? "Horizontal" : "Vertical"}
|
<RotateCcw /> {rotationLabel(selectedDefinition.shape, effectiveOrientation)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -390,8 +426,9 @@ function PlacementPhase({
|
||||||
<li>Select an emplacement above, then click a cell to anchor it there.</li>
|
<li>Select an emplacement above, then click a cell to anchor it there.</li>
|
||||||
<li>Click a placed emplacement to pick it up, then click a new cell to move it.</li>
|
<li>Click a placed emplacement to pick it up, then click a new cell to move it.</li>
|
||||||
<li>
|
<li>
|
||||||
Double-click a placed emplacement, or press the Horizontal/Vertical toggle, to rotate
|
Double-click a placed emplacement, or press the rotate toggle, to rotate it in place.
|
||||||
it in place. The Command Post is a fixed 2x2 block and does not rotate.
|
The Command Post is a fixed 2x2 block and does not rotate; the Ammo Depot is an L and
|
||||||
|
turns through four orientations.
|
||||||
</li>
|
</li>
|
||||||
<li>The toggle also sets the orientation used for your next placement.</li>
|
<li>The toggle also sets the orientation used for your next placement.</li>
|
||||||
<li>Emplacements cannot overlap, and your opponent never sees your layout.</li>
|
<li>Emplacements cannot overlap, and your opponent never sees your layout.</li>
|
||||||
|
|
|
||||||
|
|
@ -26,34 +26,38 @@ export const VERSUS_MAX_NAME_LENGTH = 40;
|
||||||
/** Sentinel userId for the empty seat in a waiting match (never a real user). */
|
/** Sentinel userId for the empty seat in a waiting match (never a real user). */
|
||||||
export const VERSUS_WAITING_USER_ID = 0;
|
export const VERSUS_WAITING_USER_ID = 0;
|
||||||
|
|
||||||
export type FobShape = "line" | "square";
|
export type FobShape = "line" | "square" | "l";
|
||||||
|
|
||||||
export interface FobDefinition {
|
export interface FobDefinition {
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly label: string;
|
readonly label: string;
|
||||||
/** Occupied cells when placed. */
|
/** Occupied cells when placed. */
|
||||||
readonly size: number;
|
readonly size: number;
|
||||||
/** "line" lays the cells straight (orientation applies); "square" is an NxN block. */
|
/** "line" is straight, "square" is an NxN block, "l" is a 3-cell corner. */
|
||||||
readonly shape: FobShape;
|
readonly shape: FobShape;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The emplacement fleet each player hides. A shorter list keeps a duel brisk;
|
* The emplacement fleet each player hides. Total occupied cells are 10 of 100,
|
||||||
* total occupied cells are 9 of 100, so rounds matter without dragging.
|
* so rounds matter without dragging.
|
||||||
*/
|
*/
|
||||||
export const FOB_FLEET: readonly FobDefinition[] = [
|
export const FOB_FLEET: readonly FobDefinition[] = [
|
||||||
{ id: "command-post", label: "Command Post", size: 4, shape: "square" },
|
{ id: "command-post", label: "Command Post", size: 4, shape: "square" },
|
||||||
{ id: "ammo-depot", label: "Ammo Depot", size: 2, shape: "line" },
|
{ id: "ammo-depot", label: "Ammo Depot", size: 3, shape: "l" },
|
||||||
{ id: "radar-site", label: "Radar Site", size: 2, shape: "line" },
|
{ id: "radar-site", label: "Radar Site", size: 2, shape: "line" },
|
||||||
{ id: "fob", label: "Forward Operating Base", size: 1, shape: "line" },
|
{ id: "fob", label: "Forward Operating Base", size: 1, shape: "line" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export type FobOrientation = "h" | "v";
|
/**
|
||||||
|
* Quarter-turns clockwise. Lines use 0 (horizontal) and 1 (vertical); the
|
||||||
|
* square ignores it; the L uses all four.
|
||||||
|
*/
|
||||||
|
export type FobRotation = 0 | 1 | 2 | 3;
|
||||||
|
|
||||||
export interface FobPlacement {
|
export interface FobPlacement {
|
||||||
readonly assetId: string;
|
readonly assetId: string;
|
||||||
readonly origin: GridPoint;
|
readonly origin: GridPoint;
|
||||||
readonly orientation: FobOrientation;
|
readonly orientation: FobRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Scoring: emplacements destroyed dominate; cells struck break ties. */
|
/** Scoring: emplacements destroyed dominate; cells struck break ties. */
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ import {
|
||||||
VERSUS_SCORE_PER_CELL,
|
VERSUS_SCORE_PER_CELL,
|
||||||
VERSUS_SCORE_PER_FOB,
|
VERSUS_SCORE_PER_FOB,
|
||||||
type FobDefinition,
|
type FobDefinition,
|
||||||
type FobOrientation,
|
|
||||||
type FobPlacement,
|
type FobPlacement,
|
||||||
|
type FobRotation,
|
||||||
type FobShape,
|
type FobShape,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
import type {
|
import type {
|
||||||
|
|
@ -62,33 +62,70 @@ export function createVersusState(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Cells a straight-line or square emplacement covers, or null when it runs off the board. */
|
/** Base cells of the 3-cell L within its 2x2 box, at rotation 0. */
|
||||||
export function cellsForPlacement(
|
const L_BASE: readonly GridPoint[] = [
|
||||||
origin: GridPoint,
|
{ x: 0, y: 0 },
|
||||||
orientation: FobOrientation,
|
{ x: 0, y: 1 },
|
||||||
|
{ x: 1, y: 1 },
|
||||||
|
];
|
||||||
|
|
||||||
|
/** Rotate a cell by `turns` quarter-turns clockwise within a square box. */
|
||||||
|
function rotateQuarterTurn(cell: GridPoint, turns: number, box: number): GridPoint {
|
||||||
|
let x = cell.x;
|
||||||
|
let y = cell.y;
|
||||||
|
const normalized = ((turns % 4) + 4) % 4;
|
||||||
|
for (let t = 0; t < normalized; t += 1) {
|
||||||
|
const nextX = box - 1 - y;
|
||||||
|
const nextY = x;
|
||||||
|
x = nextX;
|
||||||
|
y = nextY;
|
||||||
|
}
|
||||||
|
return { x, y };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Relative cells for a shape at a given orientation. */
|
||||||
|
function relativeCells(
|
||||||
|
shape: FobShape,
|
||||||
|
orientation: FobRotation,
|
||||||
size: number,
|
size: number,
|
||||||
boardSize: number,
|
|
||||||
shape: FobShape = "line",
|
|
||||||
): GridPoint[] | null {
|
): GridPoint[] | null {
|
||||||
if (shape === "square") {
|
if (shape === "square") {
|
||||||
const side = Math.round(Math.sqrt(size));
|
const side = Math.round(Math.sqrt(size));
|
||||||
if (side * side !== size) return null;
|
if (side * side !== size) return null;
|
||||||
const cells: GridPoint[] = [];
|
const cells: GridPoint[] = [];
|
||||||
for (let dy = 0; dy < side; dy += 1) {
|
for (let dy = 0; dy < side; dy += 1) {
|
||||||
for (let dx = 0; dx < side; dx += 1) {
|
for (let dx = 0; dx < side; dx += 1) cells.push({ x: dx, y: dy });
|
||||||
const x = origin.x + dx;
|
|
||||||
const y = origin.y + dy;
|
|
||||||
if (x < 0 || y < 0 || x >= boardSize || y >= boardSize) return null;
|
|
||||||
cells.push({ x, y });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return cells;
|
return cells;
|
||||||
}
|
}
|
||||||
|
if (shape === "l") {
|
||||||
|
return L_BASE.map((cell) => rotateQuarterTurn(cell, orientation, 2));
|
||||||
|
}
|
||||||
|
const horizontal = orientation % 2 === 0;
|
||||||
const cells: GridPoint[] = [];
|
const cells: GridPoint[] = [];
|
||||||
for (let i = 0; i < size; i += 1) {
|
for (let i = 0; i < size; i += 1) {
|
||||||
const x = orientation === "h" ? origin.x + i : origin.x;
|
cells.push(horizontal ? { x: i, y: 0 } : { x: 0, y: i });
|
||||||
const y = orientation === "v" ? origin.y + i : origin.y;
|
}
|
||||||
|
return cells;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cells a placed emplacement covers, or null when it runs off the board. The
|
||||||
|
* shape drives the footprint; orientation is quarter-turns clockwise.
|
||||||
|
*/
|
||||||
|
export function cellsForPlacement(
|
||||||
|
origin: GridPoint,
|
||||||
|
orientation: FobRotation,
|
||||||
|
size: number,
|
||||||
|
boardSize: number,
|
||||||
|
shape: FobShape = "line",
|
||||||
|
): GridPoint[] | null {
|
||||||
|
const relative = relativeCells(shape, orientation, size);
|
||||||
|
if (!relative) return null;
|
||||||
|
const cells: GridPoint[] = [];
|
||||||
|
for (const cell of relative) {
|
||||||
|
const x = origin.x + cell.x;
|
||||||
|
const y = origin.y + cell.y;
|
||||||
if (x < 0 || y < 0 || x >= boardSize || y >= boardSize) return null;
|
if (x < 0 || y < 0 || x >= boardSize || y >= boardSize) return null;
|
||||||
cells.push({ x, y });
|
cells.push({ x, y });
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +136,7 @@ export function cellsForPlacement(
|
||||||
export function cellsForFob(
|
export function cellsForFob(
|
||||||
definition: FobDefinition,
|
definition: FobDefinition,
|
||||||
origin: GridPoint,
|
origin: GridPoint,
|
||||||
orientation: FobOrientation,
|
orientation: FobRotation,
|
||||||
boardSize: number,
|
boardSize: number,
|
||||||
): GridPoint[] | null {
|
): GridPoint[] | null {
|
||||||
return cellsForPlacement(origin, orientation, definition.size, boardSize, definition.shape);
|
return cellsForPlacement(origin, orientation, definition.size, boardSize, definition.shape);
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ import { computeVersusStatsDelta, readVersusStats, xpForVersus } from "@/lib/min
|
||||||
|
|
||||||
function fleetAt(x: number, y: number): FobPlacement[] {
|
function fleetAt(x: number, y: number): FobPlacement[] {
|
||||||
return [
|
return [
|
||||||
{ assetId: "command-post", origin: { x, y }, orientation: "h" },
|
{ assetId: "command-post", origin: { x, y }, orientation: 0 },
|
||||||
{ assetId: "ammo-depot", origin: { x, y: y + 2 }, orientation: "h" },
|
{ assetId: "ammo-depot", origin: { x, y: y + 2 }, orientation: 0 },
|
||||||
{ assetId: "radar-site", origin: { x, y: y + 3 }, orientation: "h" },
|
{ assetId: "radar-site", origin: { x, y: y + 4 }, orientation: 0 },
|
||||||
{ assetId: "fob", origin: { x, y: y + 4 }, orientation: "h" },
|
{ assetId: "fob", origin: { x, y: y + 5 }, orientation: 0 },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,17 @@ import {
|
||||||
type VersusState,
|
type VersusState,
|
||||||
} from "@/lib/minigames/call-for-fire-versus";
|
} from "@/lib/minigames/call-for-fire-versus";
|
||||||
|
|
||||||
/** A deterministic, non-overlapping fleet layout anchored at (x, y). */
|
/**
|
||||||
|
* A deterministic, non-overlapping fleet layout anchored at (x, y):
|
||||||
|
* a 2x2 Command Post (rows y..y+1), an L Ammo Depot (box rows y+2..y+3),
|
||||||
|
* a Radar Site line (row y+4) and a 1-cell FOB (row y+5).
|
||||||
|
*/
|
||||||
function fleetAt(x: number, y: number): FobPlacement[] {
|
function fleetAt(x: number, y: number): FobPlacement[] {
|
||||||
return [
|
return [
|
||||||
{ assetId: "command-post", origin: { x, y }, orientation: "h" },
|
{ assetId: "command-post", origin: { x, y }, orientation: 0 },
|
||||||
{ assetId: "ammo-depot", origin: { x, y: y + 2 }, orientation: "h" },
|
{ assetId: "ammo-depot", origin: { x, y: y + 2 }, orientation: 0 },
|
||||||
{ assetId: "radar-site", origin: { x, y: y + 3 }, orientation: "h" },
|
{ assetId: "radar-site", origin: { x, y: y + 4 }, orientation: 0 },
|
||||||
{ assetId: "fob", origin: { x, y: y + 4 }, orientation: "h" },
|
{ assetId: "fob", origin: { x, y: y + 5 }, orientation: 0 },
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,8 +42,8 @@ function expectState(result: { state: VersusState } | { error: string }): Versus
|
||||||
|
|
||||||
describe("call for fire versus: fleet placement", () => {
|
describe("call for fire versus: fleet placement", () => {
|
||||||
it("lays out straight-line emplacements and rejects off-board ones", () => {
|
it("lays out straight-line emplacements and rejects off-board ones", () => {
|
||||||
expect(cellsForPlacement({ x: 8, y: 0 }, "h", 3, 10)).toBeNull();
|
expect(cellsForPlacement({ x: 8, y: 0 }, 0, 3, 10)).toBeNull();
|
||||||
expect(cellsForPlacement({ x: 0, y: 0 }, "v", 3, 10)).toEqual([
|
expect(cellsForPlacement({ x: 0, y: 0 }, 1, 3, 10)).toEqual([
|
||||||
{ x: 0, y: 0 },
|
{ x: 0, y: 0 },
|
||||||
{ x: 0, y: 1 },
|
{ x: 0, y: 1 },
|
||||||
{ x: 0, y: 2 },
|
{ x: 0, y: 2 },
|
||||||
|
|
@ -53,23 +57,50 @@ describe("call for fire versus: fleet placement", () => {
|
||||||
{ x: 0, y: 1 },
|
{ x: 0, y: 1 },
|
||||||
{ x: 1, y: 1 },
|
{ x: 1, y: 1 },
|
||||||
];
|
];
|
||||||
expect(cellsForPlacement({ x: 0, y: 0 }, "h", 4, 10, "square")).toEqual(square);
|
expect(cellsForPlacement({ x: 0, y: 0 }, 0, 4, 10, "square")).toEqual(square);
|
||||||
expect(cellsForPlacement({ x: 0, y: 0 }, "v", 4, 10, "square")).toEqual(square);
|
expect(cellsForPlacement({ x: 0, y: 0 }, 1, 4, 10, "square")).toEqual(square);
|
||||||
expect(cellsForPlacement({ x: 9, y: 0 }, "h", 4, 10, "square")).toBeNull();
|
expect(cellsForPlacement({ x: 9, y: 0 }, 0, 4, 10, "square")).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rotates the 3-cell L through four distinct orientations", () => {
|
||||||
|
expect(cellsForPlacement({ x: 0, y: 0 }, 0, 3, 10, "l")).toEqual([
|
||||||
|
{ x: 0, y: 0 },
|
||||||
|
{ x: 0, y: 1 },
|
||||||
|
{ x: 1, y: 1 },
|
||||||
|
]);
|
||||||
|
expect(cellsForPlacement({ x: 0, y: 0 }, 1, 3, 10, "l")).toEqual([
|
||||||
|
{ x: 1, y: 0 },
|
||||||
|
{ x: 0, y: 0 },
|
||||||
|
{ x: 0, y: 1 },
|
||||||
|
]);
|
||||||
|
expect(cellsForPlacement({ x: 0, y: 0 }, 2, 3, 10, "l")).toEqual([
|
||||||
|
{ x: 1, y: 1 },
|
||||||
|
{ x: 1, y: 0 },
|
||||||
|
{ x: 0, y: 0 },
|
||||||
|
]);
|
||||||
|
expect(cellsForPlacement({ x: 0, y: 0 }, 3, 3, 10, "l")).toEqual([
|
||||||
|
{ x: 0, y: 1 },
|
||||||
|
{ x: 1, y: 1 },
|
||||||
|
{ x: 1, y: 0 },
|
||||||
|
]);
|
||||||
|
expect(cellsForPlacement({ x: 9, y: 0 }, 0, 3, 10, "l")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects missing, overlapping, and unknown emplacements", () => {
|
it("rejects missing, overlapping, and unknown emplacements", () => {
|
||||||
expect(buildFleet([fleetAt(0, 0)[0]], 10)).toEqual({ error: "Missing emplacement: Ammo Depot." });
|
expect(buildFleet([fleetAt(0, 0)[0]], 10)).toEqual({ error: "Missing emplacement: Ammo Depot." });
|
||||||
|
|
||||||
const overlapping: FobPlacement[] = [
|
const overlapping: FobPlacement[] = [
|
||||||
{ assetId: "command-post", origin: { x: 0, y: 0 }, orientation: "h" },
|
{ assetId: "command-post", origin: { x: 0, y: 0 }, orientation: 0 },
|
||||||
{ assetId: "ammo-depot", origin: { x: 1, y: 0 }, orientation: "h" },
|
{ assetId: "ammo-depot", origin: { x: 1, y: 0 }, orientation: 0 },
|
||||||
{ assetId: "radar-site", origin: { x: 0, y: 3 }, orientation: "h" },
|
{ assetId: "radar-site", origin: { x: 0, y: 4 }, orientation: 0 },
|
||||||
{ assetId: "fob", origin: { x: 0, y: 4 }, orientation: "h" },
|
{ assetId: "fob", origin: { x: 0, y: 5 }, orientation: 0 },
|
||||||
];
|
];
|
||||||
expect(buildFleet(overlapping, 10)).toEqual({ error: "Emplacements cannot overlap." });
|
expect(buildFleet(overlapping, 10)).toEqual({ error: "Emplacements cannot overlap." });
|
||||||
|
|
||||||
const unknown = [...fleetAt(0, 0), { assetId: "nuke", origin: { x: 9, y: 9 }, orientation: "h" as const }];
|
const unknown: FobPlacement[] = [
|
||||||
|
...fleetAt(0, 0),
|
||||||
|
{ assetId: "nuke", origin: { x: 9, y: 9 }, orientation: 0 },
|
||||||
|
];
|
||||||
expect("error" in buildFleet(unknown, 10)).toBe(true);
|
expect("error" in buildFleet(unknown, 10)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -77,7 +108,7 @@ describe("call for fire versus: fleet placement", () => {
|
||||||
let state = createVersusState({ userId: 1, name: "A" }, { userId: 2, name: "B" });
|
let state = createVersusState({ userId: 1, name: "A" }, { userId: 2, name: "B" });
|
||||||
state = expectState(placeFleet(state, 0, fleetAt(0, 0)));
|
state = expectState(placeFleet(state, 0, fleetAt(0, 0)));
|
||||||
expect(state.phase).toBe("placing");
|
expect(state.phase).toBe("placing");
|
||||||
state = expectState(placeFleet(state, 1, fleetAt(0, 5)));
|
state = expectState(placeFleet(state, 1, fleetAt(0, 4)));
|
||||||
expect(state.phase).toBe("battle");
|
expect(state.phase).toBe("battle");
|
||||||
expect(state.turn).toBe(0);
|
expect(state.turn).toBe(0);
|
||||||
expect(state.startedAt).not.toBeNull();
|
expect(state.startedAt).not.toBeNull();
|
||||||
|
|
@ -134,6 +165,8 @@ describe("call for fire versus: firing", () => {
|
||||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||||
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
||||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||||
|
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: 0 } },
|
||||||
|
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||||
{ i: 0, input: { kind: "correction", rangeM: 0, deflectionM: 50 } },
|
{ i: 0, input: { kind: "correction", rangeM: 0, deflectionM: 50 } },
|
||||||
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
{ i: 1, input: { kind: "correction", rangeM: 0, deflectionM: 0 } },
|
||||||
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
{ i: 0, input: { kind: "correction", rangeM: -50, deflectionM: -50 } },
|
||||||
|
|
@ -165,8 +198,8 @@ describe("call for fire versus: views", () => {
|
||||||
const state = startedState();
|
const state = startedState();
|
||||||
const view = buildVersusView(state, 0);
|
const view = buildVersusView(state, 0);
|
||||||
const serialized = JSON.stringify(view);
|
const serialized = JSON.stringify(view);
|
||||||
// Player 1's fleet sits at (0,0)..(0,3); player 0 has fired nothing, so
|
// Player 1's fleet includes (0,0) and (1,0); player 0 has fired nothing,
|
||||||
// none of those cells may appear in player 0's view.
|
// so none of those cells may appear in player 0's view.
|
||||||
expect(serialized).not.toContain('{"x":0,"y":0}');
|
expect(serialized).not.toContain('{"x":0,"y":0}');
|
||||||
expect(serialized).not.toContain('{"x":1,"y":0}');
|
expect(serialized).not.toContain('{"x":1,"y":0}');
|
||||||
expect(serialized).not.toContain('"fobsDestroyed":4');
|
expect(serialized).not.toContain('"fobsDestroyed":4');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue