Add A* (A-Star) pathfinding algorithm #573
Closed
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Summary
Adds the A (A-Star) pathfinding algorithm* to the Graph algorithms collection. A* is a fundamental pathfinding algorithm that finds the shortest path between nodes using heuristic search, widely used in games, robotics, and navigation systems.
Motivation and Context
A* is a well-established algorithm from reputable academic sources:
This algorithm was missing from the repository and is essential for:
Implementation Details
Core Features
Generic FindPath Method
Grid Pathfinding
FindPathInGridfor 2D grid navigationPath Cost Calculation
CalculatePathCostutility methodAlgorithm Properties
Technical Implementation
✅ Uses
PriorityQueue<T, double>for efficient node selection✅ Maintains
gScore(cost from start) andfScore(estimated total cost)✅ Reconstructs path from goal to start using
cameFromdictionary✅ Proper handling of edge cases (null inputs, out of bounds, obstacles)
✅ Generic type support with
notnullconstraint✅ Comprehensive XML documentation
Testing
30 comprehensive test cases (456 lines):
Generic Graph Tests (6 tests)
Grid Pathfinding Tests (11 tests)
Path Cost Tests (4 tests)
Integer Node Tests (1 test)
Exception Handling (8 tests)
All tests pass successfully ✅
Use Case Examples
Example 1: Simple Graph Pathfinding
Example 2: Grid Pathfinding (Game AI)
Files Changed
Algorithms/Graph/AStar.cs(212 lines)Algorithms.Tests/Graph/AStarTests.cs(456 lines)Total: 668 lines of production-quality code
Checklist
Contribution by Gittensor, learn more at https://gittensor.io/