removed alternative implemenation of A* for now
This commit is contained in:
parent
6c1c0579cb
commit
5c1535da32
@ -179,82 +179,3 @@ TArray<AHexTile*> AAdventureMap::FindPathAStar(AHexTile* Start, AHexTile* Goal)
|
|||||||
Algo::Reverse(Path);
|
Algo::Reverse(Path);
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// alternative implementation using faster built in priority queue data structure
|
|
||||||
TArray<AHexTile*> AAdventureMap::FindPathAStarPQ(AHexTile* Start, AHexTile* Goal)
|
|
||||||
{
|
|
||||||
// TArray<AHexTile*> PQ;
|
|
||||||
std::priority_queue<AHexTile*, std::vector<AHexTile*>> PQ; // currently missing a custom comparator as third template arg (designating effective priority of pq elements)
|
|
||||||
std::unordered_map<AHexTile*, AHexTile*> 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<AHexTile*> Path;
|
|
||||||
AHexTile* Hex = Goal;
|
|
||||||
while (Hex != Start)
|
|
||||||
{
|
|
||||||
Path.Emplace(Hex);
|
|
||||||
Hex = Hex->CameFrom;
|
|
||||||
}
|
|
||||||
|
|
||||||
Algo::Reverse(Path);
|
|
||||||
return Path;
|
|
||||||
}
|
|
||||||
*/
|
|
Loading…
Reference in New Issue
Block a user