Add bounded A-star pathfinding for tile-to-tile movement.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -105,9 +105,9 @@ Each entry is a short note on behaviour and where the code lives. Update this fi
105
105
106
106
## Click-to-move and A\* pathfinding
107
107
108
**Status:** not implemented
109
**Spec:** `MOVE_TO` runs A\* over the visible 3×3 using block passability and open-chunk bounds. Server commits integer tiles.
110
**Code:** —
108
**Status:** partial
109
**Spec:** Four-direction A\* with a binary heap over a bounded search (the visible 3×3 once wired to movement). Passability is supplied by the caller.
110
**Code:** `server/src/navigation/astar.js`, tests in `server/tests/astar.test.js`
111
111
112
112
## Global walk/run cadence
113
113
@@ -105,9 +105,9 @@ Each entry is a short note on behaviour and where the code lives. Update this fi105
105
106
## Click-to-move and A\* pathfinding106
## Click-to-move and A\* pathfinding107
107
108
**Status:** not implemented 108
**Status:** partial 109
**Spec:** `MOVE_TO` runs A\* over the visible 3×3 using block passability and open-chunk bounds. Server commits integer tiles. 109
**Spec:** Four-direction A\* with a binary heap over a bounded search (the visible 3×3 once wired to movement). Passability is supplied by the caller. 110
**Code:** —110
**Code:** `server/src/navigation/astar.js`, tests in `server/tests/astar.test.js`111
111
112
## Global walk/run cadence112
## Global walk/run cadence113
113
@@ -0,0 +1,18 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { findPath } from "../src/navigation/astar.js";
4
5
test("A* walks around an impassable tile", () =>
6
{
7
const blocked = new Set(["1,0"]);
8
const path = findPath(0, 0, 2, 0, (x, y) => !blocked.has(`${x},${y}`), -4, -4, 4, 4);
9
assert.ok(path.length > 0);
10
assert.deepEqual(path.at(-1), { x: 2, y: 0 });
11
assert.ok(!path.some((step) => step.x === 1 && step.y === 0));
12
});
13
14
test("A* returns empty when the goal is blocked", () =>
15
{
16
const path = findPath(0, 0, 1, 0, (x, y) => x === 0 && y === 0, -2, -2, 2, 2);
17
assert.deepEqual(path, []);
18
});
@@ -0,0 +1,18 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { findPath } from "../src/navigation/astar.js";4
5
test("A* walks around an impassable tile", () =>6
{7
const blocked = new Set(["1,0"]);8
const path = findPath(0, 0, 2, 0, (x, y) => !blocked.has(`${x},${y}`), -4, -4, 4, 4);9
assert.ok(path.length > 0);10
assert.deepEqual(path.at(-1), { x: 2, y: 0 });11
assert.ok(!path.some((step) => step.x === 1 && step.y === 0));12
});13
14
test("A* returns empty when the goal is blocked", () =>15
{16
const path = findPath(0, 0, 1, 0, (x, y) => x === 0 && y === 0, -2, -2, 2, 2);17
assert.deepEqual(path, []);18
});