This commit is contained in:
Boki 2026-03-03 12:54:30 -05:00
parent a8341e8232
commit a8c43ba7e2
43 changed files with 2618 additions and 48 deletions

View file

@ -11,8 +11,11 @@ public static class PathFinder
/// <summary>
/// A* pathfinding on WalkabilitySnapshot. Returns world-coord waypoints or null if no path.
/// When exploredGrid is provided, explored cells cost 3x more — biasing paths through unexplored territory.
/// </summary>
public static List<Vector2>? FindPath(WalkabilitySnapshot terrain, Vector2 start, Vector2 goal, float worldToGrid)
public static List<Vector2>? FindPath(
WalkabilitySnapshot terrain, Vector2 start, Vector2 goal, float worldToGrid,
bool[]? exploredGrid = null, int exploredWidth = 0, int exploredHeight = 0)
{
var w = terrain.Width;
var h = terrain.Height;
@ -69,7 +72,10 @@ public static class PathFinder
}
var neighbor = (nx, ny);
var tentativeG = currentG + Cost[i];
var stepCost = Cost[i];
if (exploredGrid is not null && nx < exploredWidth && ny < exploredHeight && exploredGrid[ny * exploredWidth + nx])
stepCost *= 3f;
var tentativeG = currentG + stepCost;
if (tentativeG < gScore.GetValueOrDefault(neighbor, float.MaxValue))
{