Files
mrgameeng/tests/MrGameEng.Pathfinding.Tests/TestGrid.cs
T
Leonid PershinandClaude Fable 5 a395e58458
CI / build-test (push) Failing after 1m5s
Add MrGameEng.Pathfinding and MrGameEng.Collisions modules
Pathfinding (depends on Core only): GridPathfinder with A* (octile/
Manhattan heuristic), Dijkstra and BFS over a game-implemented
IPathGrid; 4/8 connectivity, diagonals never cut corners. FlowField +
FlowFieldBuilder (multi-source Dijkstra) give crowds O(1) steering per
agent per frame. All buffers are grid-sized once and invalidated by a
generation stamp - repeated queries allocate nothing and clear nothing.

Collisions (Graphics exception: Transform2D, RectF): Collider component
(circle/AABB, offset, two-way layer masks), CollisionWorld - a uniform
spatial hash on flat arrays rebuilt from scratch each tick (O(n) for
movers, zero alloc after warm-up, deterministic pair order), pair
collection, QueryAabb and closest-hit Raycast. scene.UseCollisions()
registers CollisionSystem after movement systems.

30 new tests (string-map mazes, cost weighting, corner cutting, flow
descent; pair/mask/query/raycast). Sample gains a PathfindingScene
('path' console command): click to set the goal, 250 agents follow the
flow field, the A* path is highlighted, colliding agents flash red.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 13:39:28 +03:00

24 lines
657 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using MrGameEng.Pathfinding;
namespace MrGameEng.Pathfinding.Tests;
/// <summary>Грид из строк: '#' — стена, '.' — клетка с ценой 1, '2'..'9' — клетка с этой ценой.</summary>
public sealed class TestGrid : IPathGrid
{
private readonly string[] _rows;
public TestGrid(params string[] rows) => _rows = rows;
public int Width => _rows[0].Length;
public int Height => _rows.Length;
public bool IsPassable(int x, int y) => _rows[y][x] != '#';
public float Cost(int x, int y)
{
var cell = _rows[y][x];
return cell is >= '2' and <= '9' ? cell - '0' : 1f;
}
}