aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-04-18 21:33:02 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2025-04-18 21:33:02 +1200
commitc6067ef93f81b9b43626cd6115c66a4d47b32fc3 (patch)
treeb60876e16f00b6db435c03cb5ee1e0291e047fac
parent525b5641fee7154d5be1a66420ca15d54bb6f6ce (diff)
Fixed Include/Insert mixup in A* algorithmHEADmaster
-rw-r--r--src/pathfinding.adb12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/pathfinding.adb b/src/pathfinding.adb
index 267b0a3..7f683ce 100644
--- a/src/pathfinding.adb
+++ b/src/pathfinding.adb
@@ -147,7 +147,6 @@ package body Pathfinding is
Came_From : Node_To_Node_Maps.Map := Node_To_Node_Maps.Empty_Map;
New_G_Score : G_Score;
- New_F_Score : F_Score;
begin
G_Scores := G_Score_Maps.Empty_Map;
G_Scores.Insert (Start, 0);
@@ -164,17 +163,14 @@ package body Pathfinding is
Closed_Set.Insert (Current);
for N of Neighbours (My_Grid, Current) loop
if not Closed_Set.Contains (N) then
- if not Open_Set.Contains (N) then
- Open_Set.Insert (N);
- end if;
New_G_Score := G_Scores.Element (Current) + 1;
- New_F_Score := New_G_Score + Heuristic (N, Goal);
if not G_Scores.Contains (N) or else
New_G_Score < G_Scores.Element (N)
then
- Came_From.Insert (N, Current);
- G_Scores.Insert (N, New_G_Score);
- F_Scores.Insert (N, New_F_Score);
+ Came_From.Include (N, Current);
+ G_Scores.Include (N, New_G_Score);
+ F_Scores.Include (N, New_G_Score + Heuristic (N, Goal));
+ Open_Set.Include (N);
end if;
end if;
end loop;