@esengine/pathfinding 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/source.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.vscode/tasks.json +13 -0
- package/.wing/settings.json +3 -0
- package/README.md +245 -0
- package/bin/README.md +245 -0
- package/bin/modules/astar.js +559 -0
- package/bin/modules/astar.min.js +1 -0
- package/bin/modules/breadth-first.js +559 -0
- package/bin/modules/breadth-first.min.js +1 -0
- package/bin/package.json +54 -0
- package/bin/pathfinding.d.ts +167 -0
- package/bin/pathfinding.js +559 -0
- package/bin/pathfinding.min.js +1 -0
- package/gulpfile.js +137 -0
- package/lib/wxgame.d.ts +3945 -0
- package/package.json +52 -0
- package/src/AI/Pathfinding/AStar/AStarPathfinder.ts +244 -0
- package/src/AI/Pathfinding/AStar/AstarGridGraph.ts +183 -0
- package/src/AI/Pathfinding/AStar/IAstarGraph.ts +30 -0
- package/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts +109 -0
- package/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts +14 -0
- package/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts +29 -0
- package/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts +81 -0
- package/src/Types/IVector2.ts +102 -0
- package/src/Utils/PriorityQueue.ts +121 -0
- package/src/index.ts +49 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export { IVector2, IComparableVector2, Vector2Utils } from './Types/IVector2';
|
|
2
|
+
export { PriorityQueue, IPriorityQueueNode } from './Utils/PriorityQueue';
|
|
3
|
+
export { IAstarGraph } from './AI/Pathfinding/AStar/IAstarGraph';
|
|
4
|
+
export { AStarPathfinder } from './AI/Pathfinding/AStar/AStarPathfinder';
|
|
5
|
+
export { AstarGridGraph } from './AI/Pathfinding/AStar/AstarGridGraph';
|
|
6
|
+
export { IUnweightedGraph } from './AI/Pathfinding/BreadthFirst/IUnweightedGraph';
|
|
7
|
+
export { BreadthFirstPathfinder } from './AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder';
|
|
8
|
+
export { UnweightedGraph } from './AI/Pathfinding/BreadthFirst/UnweightedGraph';
|
|
9
|
+
export { UnweightedGridGraph } from './AI/Pathfinding/BreadthFirst/UnweightedGridGraph';
|
|
10
|
+
|
|
11
|
+
export interface IVector2 {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}
|
|
15
|
+
export interface IComparableVector2 extends IVector2 {
|
|
16
|
+
equals?(other: IVector2): boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class Vector2Utils {
|
|
19
|
+
private static readonly HASH_MULTIPLIER;
|
|
20
|
+
private static readonly MAX_COORD;
|
|
21
|
+
static equals(a: IVector2, b: IVector2): boolean;
|
|
22
|
+
static create(x: number, y: number): IVector2;
|
|
23
|
+
static clone(vector: IVector2): IVector2;
|
|
24
|
+
static add(a: IVector2, b: IVector2): IVector2;
|
|
25
|
+
static manhattanDistance(a: IVector2, b: IVector2): number;
|
|
26
|
+
static distance(a: IVector2, b: IVector2): number;
|
|
27
|
+
static toHash(vector: IVector2): number;
|
|
28
|
+
static toKey(vector: IVector2): string;
|
|
29
|
+
static fromHash(hash: number): IVector2;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IPriorityQueueNode {
|
|
33
|
+
priority: number;
|
|
34
|
+
}
|
|
35
|
+
export declare class PriorityQueue<T extends IPriorityQueueNode> {
|
|
36
|
+
private _heap;
|
|
37
|
+
private _size;
|
|
38
|
+
get size(): number;
|
|
39
|
+
get isEmpty(): boolean;
|
|
40
|
+
clear(): void;
|
|
41
|
+
enqueue(item: T): void;
|
|
42
|
+
dequeue(): T | undefined;
|
|
43
|
+
peek(): T | undefined;
|
|
44
|
+
private _bubbleUp;
|
|
45
|
+
private _bubbleDown;
|
|
46
|
+
private _swap;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
import { IVector2 } from '../../../Types/IVector2';
|
|
50
|
+
import { IAstarGraph } from './IAstarGraph';
|
|
51
|
+
import { IPriorityQueueNode } from '../../../Utils/PriorityQueue';
|
|
52
|
+
declare class AStarNode implements IPriorityQueueNode {
|
|
53
|
+
node: IVector2;
|
|
54
|
+
priority: number;
|
|
55
|
+
gCost: number;
|
|
56
|
+
hCost: number;
|
|
57
|
+
parent: AStarNode | null;
|
|
58
|
+
hash: number;
|
|
59
|
+
constructor(node: IVector2, gCost?: number, hCost?: number, parent?: AStarNode | null);
|
|
60
|
+
updateCosts(gCost: number, hCost: number, parent?: AStarNode | null): void;
|
|
61
|
+
updateNode(node: IVector2, gCost?: number, hCost?: number, parent?: AStarNode | null): void;
|
|
62
|
+
reset(): void;
|
|
63
|
+
}
|
|
64
|
+
export declare class AStarPathfinder {
|
|
65
|
+
private static _nodePool;
|
|
66
|
+
private static _tempPath;
|
|
67
|
+
private static _getNode;
|
|
68
|
+
private static _recycleNode;
|
|
69
|
+
static search<T extends IVector2>(graph: IAstarGraph<T>, start: T, goal: T): {
|
|
70
|
+
found: boolean;
|
|
71
|
+
goalNode?: AStarNode;
|
|
72
|
+
};
|
|
73
|
+
static searchPath<T extends IVector2>(graph: IAstarGraph<T>, start: T, goal: T): T[];
|
|
74
|
+
private static reconstructPathFromNode;
|
|
75
|
+
static hasPath<T extends IVector2>(graph: IAstarGraph<T>, start: T, goal: T): boolean;
|
|
76
|
+
static clearPool(): void;
|
|
77
|
+
static getPoolStats(): {
|
|
78
|
+
poolSize: number;
|
|
79
|
+
maxPoolSize: number;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
83
|
+
|
|
84
|
+
import { IVector2 } from '../../../Types/IVector2';
|
|
85
|
+
import { IAstarGraph } from './IAstarGraph';
|
|
86
|
+
export declare class AstarGridGraph implements IAstarGraph<IVector2> {
|
|
87
|
+
dirs: IVector2[];
|
|
88
|
+
walls: IVector2[];
|
|
89
|
+
weightedNodes: IVector2[];
|
|
90
|
+
defaultWeight: number;
|
|
91
|
+
weightedNodeWeight: number;
|
|
92
|
+
private _width;
|
|
93
|
+
private _height;
|
|
94
|
+
private _neighbors;
|
|
95
|
+
private _wallsSet;
|
|
96
|
+
private _weightedNodesSet;
|
|
97
|
+
private _wallsDirty;
|
|
98
|
+
private _weightedNodesDirty;
|
|
99
|
+
constructor(width: number, height: number);
|
|
100
|
+
addWall(wall: IVector2): void;
|
|
101
|
+
addWalls(walls: IVector2[]): void;
|
|
102
|
+
clearWalls(): void;
|
|
103
|
+
addWeightedNode(node: IVector2): void;
|
|
104
|
+
addWeightedNodes(nodes: IVector2[]): void;
|
|
105
|
+
clearWeightedNodes(): void;
|
|
106
|
+
private _updateHashSets;
|
|
107
|
+
isNodeInBounds(node: IVector2): boolean;
|
|
108
|
+
isNodePassable(node: IVector2): boolean;
|
|
109
|
+
search(start: IVector2, goal: IVector2): boolean;
|
|
110
|
+
searchPath(start: IVector2, goal: IVector2): IVector2[];
|
|
111
|
+
getNeighbors(node: IVector2): IVector2[];
|
|
112
|
+
cost(from: IVector2, to: IVector2): number;
|
|
113
|
+
heuristic(node: IVector2, goal: IVector2): number;
|
|
114
|
+
getStats(): {
|
|
115
|
+
walls: number;
|
|
116
|
+
weightedNodes: number;
|
|
117
|
+
gridSize: string;
|
|
118
|
+
wallsSetSize: number;
|
|
119
|
+
weightedNodesSetSize: number;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
import { IVector2 } from '../../../Types/IVector2';
|
|
124
|
+
export interface IAstarGraph<T extends IVector2> {
|
|
125
|
+
getNeighbors(node: T): T[];
|
|
126
|
+
cost(from: T, to: T): number;
|
|
127
|
+
heuristic(node: T, goal: T): number;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
import { IVector2 } from '../../../Types/IVector2';
|
|
131
|
+
import { IUnweightedGraph } from './IUnweightedGraph';
|
|
132
|
+
export declare class BreadthFirstPathfinder {
|
|
133
|
+
static search<T extends IVector2>(graph: IUnweightedGraph<T>, start: T, goal: T, cameFrom?: Map<number, T>): boolean;
|
|
134
|
+
static searchPath<T extends IVector2>(graph: IUnweightedGraph<T>, start: T, goal: T): T[];
|
|
135
|
+
static reconstructPath<T extends IVector2>(cameFrom: Map<number, T>, start: T, goal: T): T[];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
import { IVector2 } from '../../../Types/IVector2';
|
|
139
|
+
export interface IUnweightedGraph<T extends IVector2> {
|
|
140
|
+
getNeighbors(node: T): T[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
import { IVector2 } from '../../../Types/IVector2';
|
|
144
|
+
import { IUnweightedGraph } from './IUnweightedGraph';
|
|
145
|
+
export declare class UnweightedGraph<T extends IVector2> implements IUnweightedGraph<T> {
|
|
146
|
+
edges: Map<T, T[]>;
|
|
147
|
+
addEdgesForNode(node: T, neighbors: T[]): this;
|
|
148
|
+
getNeighbors(node: T): T[];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
import { IVector2 } from '../../../Types/IVector2';
|
|
152
|
+
import { IUnweightedGraph } from './IUnweightedGraph';
|
|
153
|
+
export declare class UnweightedGridGraph implements IUnweightedGraph<IVector2> {
|
|
154
|
+
private static readonly CARDINAL_DIRS;
|
|
155
|
+
private static readonly COMPASS_DIRS;
|
|
156
|
+
walls: IVector2[];
|
|
157
|
+
private _width;
|
|
158
|
+
private _height;
|
|
159
|
+
private _dirs;
|
|
160
|
+
private _neighbors;
|
|
161
|
+
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
|
|
162
|
+
isNodeInBounds(node: IVector2): boolean;
|
|
163
|
+
isNodePassable(node: IVector2): boolean;
|
|
164
|
+
getNeighbors(node: IVector2): IVector2[];
|
|
165
|
+
searchPath(start: IVector2, goal: IVector2): IVector2[];
|
|
166
|
+
hasPath(start: IVector2, goal: IVector2): boolean;
|
|
167
|
+
}
|