From 5c1535da327ff130302aba3d9543bc8f518e098c Mon Sep 17 00:00:00 2001 From: Maximilian Fajnberg Date: Mon, 17 Jan 2022 17:58:30 +0100 Subject: [PATCH] removed alternative implemenation of A* for now --- AdventureMap.cpp | 81 +----------------------------------------------- 1 file changed, 1 insertion(+), 80 deletions(-) diff --git a/AdventureMap.cpp b/AdventureMap.cpp index f0732dc..4cf7d19 100644 --- a/AdventureMap.cpp +++ b/AdventureMap.cpp @@ -178,83 +178,4 @@ TArray AAdventureMap::FindPathAStar(AHexTile* Start, AHexTile* Goal) } Algo::Reverse(Path); return Path; -} - -/* -// alternative implementation using faster built in priority queue data structure -TArray AAdventureMap::FindPathAStarPQ(AHexTile* Start, AHexTile* Goal) -{ - // TArray PQ; - std::priority_queue> PQ; // currently missing a custom comparator as third template arg (designating effective priority of pq elements) - std::unordered_map CameFrom; // if in doubt: switch to templates instead of predefined hex types - // PQ.Init(Start, 1); - PQ.push(Start); - CameFrom[Start] = Start; - - // while (!PQ.IsEmpty()) - while (!PQ.empty()) - { - AHexTile* Current = PQ.top(); - // PQ.RemoveAt(0); - PQ.pop(); - if (Current == Goal) - { - UE_LOG(LogTemp, Warning, TEXT("Goal found!")); // debug - break; - } - - // Expanding the Frontier - for (AHexTile* Next : Neighbors(Current)) - { - int32 NewCost = Current->CostSoFar + Next->MoveCost; - // UE_LOG(LogTemp, Warning, TEXT("Cost calculated.")); // debug - - if (!PQ.Contains(Next) || NewCost < Next->CostSoFar) - { - // UE_LOG(LogTemp, Warning, TEXT("New candidate found.")); // debug - Next->CostSoFar = NewCost; - int32 NewPrio = NewCost + Next->Distance(Goal); - - // Adjust the Priority Queue - if (PQ.Contains(Next)) { PQ.Remove(Next); } - for (AHexTile* Hex : PQ) // at this point PQ is empty, need to make sure it's not. - { - int32 OldPrio = Hex->CostSoFar + Hex->Distance(Goal); - int32 Index; - PQ.Find(Hex, Index); - // UE_LOG(LogTemp, Warning, TEXT("Comparing priorities...")); // debug - - if (OldPrio > NewPrio) - { - PQ.Insert(Next, Index); - Next->CameFrom = Current; - // UE_LOG(LogTemp, Warning, TEXT("Looks promising!")); // debug - break; - } - - if (Index == PQ.Num() - 1 && OldPrio <= NewPrio) - { - PQ.Emplace(Next); - Next->CameFrom = Current; - // UE_LOG(LogTemp, Warning, TEXT("Low prio added")); // debug - break; - } - } - - if (PQ.IsEmpty()) { PQ.Emplace(Next); } - } - } - } - - TArray Path; - AHexTile* Hex = Goal; - while (Hex != Start) - { - Path.Emplace(Hex); - Hex = Hex->CameFrom; - } - - Algo::Reverse(Path); - return Path; -} -*/ \ No newline at end of file +} \ No newline at end of file