Breadth First Search; considering use of diagonals for A*PF
This commit is contained in:
@ -3,8 +3,6 @@
|
||||
|
||||
#include "AdventureMap.h"
|
||||
#include "HexTile.h"
|
||||
#include "AdventureCameraPawn.h"
|
||||
#include "AdventureCharacter.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Algo/Reverse.h"
|
||||
|
||||
@ -94,10 +92,38 @@ TArray<AHexTile*> AAdventureMap::Neighbors(AHexTile* OfHex)
|
||||
return Neighbors;
|
||||
}
|
||||
|
||||
TArray<AHexTile*> AAdventureMap::BreadthFirstSearch(AHexTile* Start, int32 Radius)
|
||||
{
|
||||
TArray<AHexTile*> Results;
|
||||
TArray<AHexTile*> ToExamine;
|
||||
TSet<AHexTile*> Processed;
|
||||
|
||||
ToExamine.Add(Start);
|
||||
|
||||
while (!ToExamine.IsEmpty()) {
|
||||
AHexTile* Candidate = ToExamine[0];
|
||||
|
||||
Processed.Add(Candidate);
|
||||
ToExamine.Remove(Candidate);
|
||||
|
||||
for (AHexTile* Neighbor : Neighbors(Candidate)) {
|
||||
if (Neighbor->Distance(Candidate) > 1) { continue; }
|
||||
if (Processed.Contains(Neighbor)) { continue; }
|
||||
|
||||
if (Neighbor->Distance(Start) <= Radius) {
|
||||
ToExamine.Add(Neighbor);
|
||||
Results.Add(Neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Results.Add(Start);
|
||||
return Results;
|
||||
}
|
||||
TArray<AHexTile*> AAdventureMap::AStar(AHexTile* Start, AHexTile* Goal)
|
||||
{
|
||||
TArray<AHexTile*> ToExamine;
|
||||
TArray<AHexTile*> Processed;
|
||||
TSet<AHexTile*> Processed;
|
||||
ToExamine.Add(Start);
|
||||
|
||||
while (!ToExamine.IsEmpty()) {
|
||||
|
Reference in New Issue
Block a user