{"id":16209881,"url":"https://github.com/jdsherbert/a-star-pathfinding","last_synced_at":"2025-10-29T00:31:10.393Z","repository":{"id":215008075,"uuid":"737889760","full_name":"JDSherbert/A-Star-Pathfinding","owner":"JDSherbert","description":"Simple C++ implementation of an A* Pathfinding class.","archived":false,"fork":false,"pushed_at":"2024-01-01T23:10:00.000Z","size":55,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-21T11:25:53.120Z","etag":null,"topics":["cpp","cpp17","pathfinder","pathfinding","pathfinding-algorithm"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JDSherbert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-01T21:28:48.000Z","updated_at":"2024-12-13T08:24:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"e661df80-a853-426c-a007-566c6f78ba46","html_url":"https://github.com/JDSherbert/A-Star-Pathfinding","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"9f1b5690f47e7a214adad11264e8b6ad39d3dffb"},"previous_names":["jdsherbert/a-star-pathfinding"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDSherbert%2FA-Star-Pathfinding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDSherbert%2FA-Star-Pathfinding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDSherbert%2FA-Star-Pathfinding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JDSherbert%2FA-Star-Pathfinding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JDSherbert","download_url":"https://codeload.github.com/JDSherbert/A-Star-Pathfinding/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238746750,"owners_count":19523788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp17","pathfinder","pathfinding","pathfinding-algorithm"],"created_at":"2024-10-10T10:33:44.975Z","updated_at":"2025-10-29T00:31:10.387Z","avatar_url":"https://github.com/JDSherbert.png","language":"C++","readme":"![image](https://upload.wikimedia.org/wikipedia/commons/9/98/AstarExampleEn.gif)\n\n# A* Pathfinding\n\n\u003c!-- Header Start --\u003e\n\u003ca href = \"https://learn.microsoft.com/en-us/cpp/cpp-language\"\u003e \u003cimg height=\"40\" img width=\"40\" src=\"https://cdn.simpleicons.org/c++\"\u003e \u003c/a\u003e\n\u003cimg align=\"right\" alt=\"Stars Badge\" src=\"https://img.shields.io/github/stars/jdsherbert/A-Star-Pathfinding?label=%E2%AD%90\"/\u003e\n\u003cimg align=\"right\" alt=\"Forks Badge\" src=\"https://img.shields.io/github/forks/jdsherbert/A-Star-Pathfinding?label=%F0%9F%8D%B4\"/\u003e\n\u003cimg align=\"right\" alt=\"Watchers Badge\" src=\"https://img.shields.io/github/watchers/jdsherbert/A-Star-Pathfinding?label=%F0%9F%91%81%EF%B8%8F\"/\u003e\n\u003cimg align=\"right\" alt=\"Issues Badge\" src=\"https://img.shields.io/github/issues/jdsherbert/A-Star-Pathfinding?label=%E2%9A%A0%EF%B8%8F\"/\u003e\n\u003cimg align=\"right\" src=\"https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FJDSherbert%2FA-Star-Pathfinding%2Fhit-counter%2FREADME\u0026count_bg=%2379C83D\u0026title_bg=%23555555\u0026labelColor=0E1128\u0026title=🔍\u0026style=for-the-badge\"\u003e\n\u003c!-- Header End --\u003e \n\n-----------------------------------------------------------------------\n\n\u003ca href=\"\"\u003e \n  \u003cimg align=\"left\" alt=\"C++ Template\" src=\"https://img.shields.io/badge/Algorithm%20Implementation-black?style=for-the-badge\u0026logo=cpp\u0026logoColor=white\u0026color=black\u0026labelColor=black\"\u003e \u003c/a\u003e\n  \n\u003ca href=\"https://choosealicense.com/licenses/mit/\"\u003e \n  \u003cimg align=\"right\" alt=\"License\" src=\"https://img.shields.io/badge/License%20:%20MIT-black?style=for-the-badge\u0026logo=mit\u0026logoColor=white\u0026color=black\u0026labelColor=black\"\u003e \u003c/a\u003e\n  \n\u003cbr\u003e\u003c/br\u003e\n\n-----------------------------------------------------------------------\n\n## Overview\n\nThe A* (A-star) algorithm is a popular pathfinding algorithm commonly used in robotics, games, and other applications where finding the shortest path between two points is necessary. A* is an extension of Dijkstra's algorithm with the added benefit of heuristic evaluation, making it more efficient for pathfinding in many cases.\nThe effectiveness of A* heavily relies on the quality of this heuristic function -\nA good heuristic should be admissible (never overestimate the cost) to get the best possible solution.\n\n#### Running The Example Code\nYou should be able to run the example code above with this command:\n```cpp\ng++ main.cpp Pathfinder.cpp -o pathfinder\n./pathfinder\n```\n\n-----------------------------------------------------------------------\n\n## Common Heuristics\n\nCommon heuristics include Manhattan distance, Euclidean distance, and Chebyshev distance, which can be interchanged depending on the nature of the environment.\n\n### 1. Manhattan Distance\nAlso known as the L1 norm or taxicab distance, Manhattan distance is the sum of the absolute differences of the Cartesian coordinates. It measures the distance between two points along the grid lines.\n\n#### Formula \nFor two points, x and y, the distance is given by:\n```latex\n|x_1 - x_2| + |y_1 - y_2|\n```\n\nIt's ideal for grid-based environments where movement is restricted to horizontal, vertical, and diagonal directions with equal cost.\n\n### 2. Euclidean Distance\nAlso known as the L2 norm, Euclidean distance is the straight-line distance between two points in Euclidean space. \nIt represents the length of the shortest path between the points.\n\n#### Formula \nFor two points, x and y, the distance is given by:\n```latex\nsqrt{{(x_1 - x_2)^2 + (y_1 - y_2)^2}}\n```\n\nSuitable for continuous environments where diagonal movement is allowed and the cost of diagonal movement is considered equal to the cost of horizontal or vertical movement.\n\n### 3. Chebyshev Distance\nDefinition: Also known as the L∞ norm or chessboard distance, Chebyshev distance is the maximum of the absolute differences along each coordinate axis.\n\n#### Formula \nFor two points, x and y, the distance is given by:\n```latex\nmax(|x_1 - x_2|, |y_1 - y_2|)\n```\n\nParticularly useful in grid-based environments where diagonal movement is allowed, and the cost of diagonal movement is the same as the cost of horizontal or vertical movement.\n\n-----------------------------------------------------------------------\n\n## Comparisons\n\n### Manhattan vs. Euclidean\nManhattan distance is faster to compute because it involves only absolute differences and additions.\nEuclidean distance provides a more accurate measure when diagonal movement is allowed, as it calculates the true straight-line distance.\n\n### Euclidean vs. Chebyshev\nEuclidean distance considers the actual geometric distance, while Chebyshev distance only considers the maximum coordinate difference.\nChebyshev distance is less computationally intensive than Euclidean distance.\n\n### Manhattan vs. Chebyshev\nIn grid-based environments with only horizontal, vertical, and diagonal movement, Manhattan and Chebyshev distances are often equivalent.\nChebyshev distance is more general and can be applied in scenarios where diagonal movement is allowed.\n\n-----------------------------------------------------------------------\n\n## Choosing a Heuristic\n\nThe choice of heuristic depends on the characteristics of the environment and the allowed types of movement.\nIf diagonal movement is restricted or has a different cost, Manhattan distance is often a good choice.\nFor scenarios with diagonal movement and equal cost, Euclidean or Chebyshev distance can be considered based on computational efficiency.\nIn summary, the selection of the appropriate distance measure depends on the specific characteristics of the environment and the movement constraints. Each distance metric has its strengths and is suitable for different scenarios within the context of pathfinding algorithms like A*.\n\n-----------------------------------------------------------------------\n\n## A* Pathfinder Function\n\nThe objective of the pathfidner is to quite literally find the shortest path from a starting point to a goal point in a graph (or grid).\nA* uses a priority queue to efficiently select the node with the lowest total cost from the start to the current node, considering both the cost to reach the current node (g value) and the estimated cost to reach the goal from the current node (h value).\n\n-----------------------------------------------------------------------\n\n## Key Components\n\n#### Nodes (or Cells)\nThe graph is made up of nodes representing positions in the environment. Each node has coordinates, and in a grid-based scenario, nodes correspond to grid cells.\n\n#### Edges (or Connections)\nDefine the connections between nodes. In a grid, nodes are typically connected to their adjacent neighbors.\n\n#### Costs\n- g (Cost from Start): The cost to reach a node from the start node.\n- h (Heuristic Cost to Goal): An estimate of the cost from the current node to the goal. It is the heuristic function's role to provide this estimate.\n- f (Total Cost): The sum of g and h. This is the value used to prioritize nodes in the priority queue.\n- Priority Queue: Nodes are stored in a priority queue sorted by their f values. This ensures that nodes with lower total costs are explored first.\n\n#### Heuristic Function \nA* uses a heuristic function to estimate the cost from the current node to the goal. This function should be admissible (never overestimates) to guarantee the optimality of the solution.\n\n-----------------------------------------------------------------------\n\n## Algorithm Steps\n\n#### 1. Initialization\nCreate the start node and add it to the open list (priority queue).\nInitialize g and h values of the start node.\nSet g to 0 for the start node.\n\n#### 2. Main Loop\nWhile the open list is not empty:\nPop the node with the lowest f value from the open list.\nIf the current node is the goal, the path is found.\n\n#### 3. Generate Successors\nFor each neighboring node (successor) of the current node:\nCalculate g and h values for the successor.\nIf the successor is not in the open list, calculate f and add it to the open list.\nIf the successor is in the open list and the new g value is lower, update g and f.\n\n#### 4. Termination\nIf the open list is empty, and the goal is not reached, there is no path.\n\n-----------------------------------------------------------------------\n\n## Considerations\n- A* is complete and optimal when using an admissible heuristic.\n- The algorithm may not perform optimally in certain scenarios, such as environments with very high-dimensional state spaces.\n- Choosing an appropriate heuristic is crucial for the efficiency of the algorithm.\n- A* is widely used and has many variations and optimizations, such as weighted A* and incremental search.\n\nIn summary, A* combines the benefits of both uniform cost search and greedy best-first search by using a heuristic function to efficiently explore the search space and find the shortest path.\n\n-----------------------------------------------------------------------\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdsherbert%2Fa-star-pathfinding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdsherbert%2Fa-star-pathfinding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdsherbert%2Fa-star-pathfinding/lists"}