import test from "node:test"; import assert from "node:assert/strict"; import { findPathToNearestGoal } from "../../shared/navigation/bfs.js"; test("BFS picks the nearest stand tile toward the target, not the top-left ring tile", () => { // Open field. Player south of target — closest adjacent tile is directly north of player (south of target). const playerX = 20; const playerY = 30; const targetX = 20; const targetY = 20; const path = findPathToNearestGoal( playerX, playerY, (x, y) => Math.max(Math.abs(x - targetX), Math.abs(y - targetY)) === 1, () => true, 0, 0, 40, 40 ); assert.ok(path.length); const goal = path[path.length - 1]; assert.deepEqual(goal, { x: 20, y: 21 }); }); test("BFS returns empty when already at a goal", () => { const path = findPathToNearestGoal( 5, 5, (x, y) => x === 5 && y === 5, () => true, 0, 0, 10, 10 ); assert.deepEqual(path, []); });