Gorilla.Utils.Pathfinding.AStar
Unit Gorilla.Utils.Pathfinding.AStar.pasClasses
- TGorillaPathfindingAStar = class ( TGorillaPathfindingAlgorithm )
Records
- record TAStarRec
- record TAStarOffset
TGorillaPathfindingAStar
Custom A* pathfing algorithm implementation. This component is not threadsafe because of direct Control3D usage. Do not attempt to compute paths asynchronously in a thread!
Remarks
In computer science, A* (pronounced as "A star") is a computer algorithm that is widely used in pathfinding and graph traversal, which is the process of finding a path between multiple points, called "nodes". It enjoys widespread use due to its performance and accuracy. However, in practical travel-routing systems, it is generally outperformed by algorithms which can pre-process the graph to attain better performance, [1] although other work has found A* to be superior to other approaches. [2] Peter Hart, Nils Nilsson and Bertram Raphael of Stanford Research Institute (now SRI International) first published the algorithm in 1968. [3] It can be seen an extension of Edsger Dijkstra's 1959 algorithm. A* achieves better performance by using heuristics to guide its search. https://en.wikipedia.org/wiki/A*_search_algorithmAncestors
Members
Fields
- protected FStartPosition :
TPoint3D
- protected FEndPosition :
TPoint3D
- protected FAgentWidth :
Integer
- protected FSearching :
Boolean
- protected FFound :
Boolean
- protected FAStack :
:TGorillaPathfindingAStar.:1
- protected FSource :
TPoint
- protected FGoal :
TPoint
- protected FFreedom :
Integer
- protected FDiagonals :
Boolean
- protected FFallback :
Boolean
- protected FOnInspectBlock :
TOnInspectBlock
- protected FDoOnInspectBlock :
TOnInspectBlock
- protected FOnGetPosition :
TOnGetPosition
- protected FSize3D :
TPointF
- protected FObstacleMap :
TArray<System.TArray<System.Boolean>>
- protected FGrid :
TArray<System.TArray<System.Integer>>
- protected FGridDimensions :
TPoint
- protected FAdjustedGridSize :
TPoint
- protected FMaxVal :
Integer
- protected FPathError :
Boolean
- protected FPath :
TArray<System.Types.TPoint>
- protected FClosestPoint :
TAStarRec
- protected FIsClosest :
Boolean
- protected FOffsets :
- protected FCurrentList :
TList<Gorilla.Utils.Pathfinding.TGorillaPathfindingObstacle>
- protected FStep :
Integer
Methods
- public constructor Create ( AOwner : TComponent ) ;
- public destructor Destroy ( ) ;
- protected procedure SetupOffsets ( ) ; virtual;
- protected procedure InspectBlock ( X : Integer; Y : Integer ) ; virtual;
- protected procedure Step ( ) ; virtual;
- protected procedure CalcBestPath ( ) ; virtual;
- protected procedure LookForPath ( ) ; virtual;
- protected procedure ClearPath ( ) ;
- protected procedure VerifyCoordinates ( const APoint : TPoint ) ; overload;
- protected procedure VerifyCoordinates ( const APoint : TPoint3D ) ; overload;
- protected function GetPath3D ( ) : TArray<System.Math.Vectors.TPoint3D> ; virtual;
- protected procedure AddToObstacleMap ( AObstacle : TGorillaPathfindingObstacle ) ; virtual;
- protected function DoCheckCoordinates
(
const
AObstacles :
TList<Gorilla.Utils.Pathfinding.TGorillaPathfindingObstacle>; const
X :
Integer; const
Y :
Integer; const
Fx :
Integer; const
Fy :
Integer
)
: Integer
;
virtual;
This function is called when path finder asks you weither it can process coordinate X,Y. Fx, Fy are the coordinates from where the pathfinder is coming, you can use that to make some blocks only passable thru some sides and not all 4.
Parameters
- const AObstacles : TList<Gorilla.Utils.Pathfinding.TGorillaPathfindingObstacle> - List of obstacles to be checked if blocking. Column of A* grid. Row of A* grid.
- const X : Integer - List of obstacles to be checked if blocking. Column of A* grid. Row of A* grid.
- const Y : Integer - List of obstacles to be checked if blocking. Column of A* grid. Row of A* grid.
- const Fx : Integer - List of obstacles to be checked if blocking. Column of A* grid. Row of A* grid.
- const Fy : Integer - List of obstacles to be checked if blocking. Column of A* grid. Row of A* grid.
- protected procedure DoFindPath
(
const
ASrc :
TPoint; const
ADest :
TPoint
)
;
virtual;
Computes the path from source to destination coordinates.
- public procedure AssignFrom
(
ASrc :
TGorillaPathfindingAStar
)
;
virtual;
Copy all fields from one algorithm component to another. The method takes care of copying object references and individual data.
- public procedure FindPath
(
const
ASrc :
TPoint3D; const
ADest :
TPoint3D
)
;
overload virtual;
Computes the path from 3D source and destination coordinates.
Parameters
- const ASrc : TPoint3D - The 3d starting coordinates. The 3d destination coordinates.
- const ADest : TPoint3D - The 3d starting coordinates. The 3d destination coordinates.
- public procedure FindPath
(
const
ADest :
TPoint3D
)
;
overload virtual;
Computes the path from 3D source and destination coordinates.
Parameters
- const ADest : TPoint3D - This function only needs the destination coordinates. If you have assigned an agent control, its coordinates will automatically be read. Otherwise the starting point is [0, 0, 0].
- public function GetGridCoordinate
(
const
APoint :
TPoint3D; const
ADimension :
TPoint; const
ASize3D :
TPointF
)
: TPoint
;
class virtual;
Convertes 3D coordinates to grid coordinates depending on a supplied grid dimension and 3D space size.
- public function ToNewPath3D
(
const
AOwner :
TComponent; const
AAddEndPosition :
Boolean
=
False
)
: TGorillaPath3D
;
virtual;
Returns a new path3d component with the created path coordinates.
Parameters
- const AOwner : TComponent - Owner component of newly created path3d component. If AAddEndPosition is set to true it will add another end vertex at the end of the path to close it.
- const AAddEndPosition : Boolean = False - Owner component of newly created path3d component. If AAddEndPosition is set to true it will add another end vertex at the end of the path to close it.
- public procedure ApplyToPath3D
(
const
APath :
TGorillaPath3D; const
AAddEndPosition :
Boolean
=
False
)
;
virtual;
Applies the compute path to an existing path3d instance.
- public procedure Draw
(
const
ABitmap :
TBitmap
)
;
overload;
Draws the pathfinder grid with a path into a bitmap
Properties
- public Path : TArray<System.Types.TPoint>
- public Path3D : TArray<System.Math.Vectors.TPoint3D>
- public StartPosition : TPoint3D
- public EndPosition : TPoint3D
- public AdjustedGridSize : TPoint
The adjusted grid size is a combination of configured gridsize and half of agent width.
read FAdjustedGridSize - published GridDimensions : TPoint
- published Size3D : TPointF
- published Diagonals : Boolean
- published Fallback : Boolean