{"id":15394716,"url":"https://github.com/bensuperpc/astar","last_synced_at":"2025-03-27T23:44:20.869Z","repository":{"id":219584478,"uuid":"749385366","full_name":"bensuperpc/astar","owner":"bensuperpc","description":"Fast and easy to use standalone header only 2D astar algorithm library in C++20","archived":false,"fork":false,"pushed_at":"2024-06-21T19:52:00.000Z","size":197,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T02:11:09.235Z","etag":null,"topics":["astar","astar-algorithm","astar-pathfinding","cpp","cpp20","dijkstra","dijkstra-algorithm","header-only","pathfinder","pathfinding","pathfinding-algorithm","template-class"],"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/bensuperpc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-28T12:40:35.000Z","updated_at":"2024-06-21T19:52:03.000Z","dependencies_parsed_at":"2024-01-28T14:52:01.724Z","dependency_job_id":"dc6e6456-c40a-4235-bf65-9b22f323b98f","html_url":"https://github.com/bensuperpc/astar","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"d3247bbc543b4b7ce25b5e713861b413f0cc3fb7"},"previous_names":["bensuperpc/astar"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensuperpc%2Fastar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensuperpc%2Fastar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensuperpc%2Fastar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bensuperpc%2Fastar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bensuperpc","download_url":"https://codeload.github.com/bensuperpc/astar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245944062,"owners_count":20697948,"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":["astar","astar-algorithm","astar-pathfinding","cpp","cpp20","dijkstra","dijkstra-algorithm","header-only","pathfinder","pathfinding","pathfinding-algorithm","template-class"],"created_at":"2024-10-01T15:24:16.954Z","updated_at":"2025-03-27T23:44:20.848Z","avatar_url":"https://github.com/bensuperpc.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# astar\n\nFast and easy to use standalone header only 2D astar algorithm library in C++20.\n\nI made it for learning how the astar algorithm works, try to make the fastest, tested and configurable as possible for my needs (future games and works).\n\n# How does it work\n\nIt is an [astar algorithm](https://en.wikipedia.org/wiki/A*_search_algorithm), the main idea is to find the shortest path between two points in a grid/map.\n\n# Screenshots\n\n![astar](resources/Screenshot_20240213_205401.png)\n\n![astar](resources/Screenshot_20240213_205329.png)\n\n# Features\n\n* [x] Header-only library C++20\n* [x] Support 2D map\n* [ ] Support 3D map\n* [x] Configurable heuristic function and movement cost\n* [x] Configurable (diagonal and more) movement\n* [x] Debug mode in template argument and lambda function\n* [x] Support direct access and not access to the map\n* [x] Unit tests and benchmarks\n* [ ] Working CI (WIP)\n\n### Heuristic function\n\nYou can set the heuristic function to calculate the distance between two points and return the cost.\n\n| Heuristic | C++ Function | Description |\n|-----------|--------------|-------------|\n| euclidean | AStar::Heuristic::euclidean | Default |\n| manhattan | AStar::Heuristic::manhattan |  |\n| octagonal | AStar::Heuristic::octagonal |  |\n| chebyshev | AStar::Heuristic::chebyshev |  |\n| euclideanNoSQR | AStar::Heuristic::euclideanNoSQR |  |\n| dijkstra | AStar::Heuristic::dijkstra | Always return 0 |\n\n# How to use it\n\nThis project is a header-only library and easy to use, just copy the `include/astar` folder in your project and include the `astar/astar.hpp` header or via CMake FetchContent_Declare.\n\nNow you can use the `Astar::Astar` class to find the shortest path between two points in a grid.\n\n```cpp\n#include \u003castar/astar.hpp\u003e\n#include \u003ciostream\u003e\n\nauto main() -\u003e int {\n    // Create the template class with optional a type (e.g. uint32_t) and a boolean \n    // if you want enable debug mode (AStar::AStar\u003cuint32_t, true\u003e)\n    AStar::AStar pathFinder;\n\n    // Define the map size (width, height)\n    pathFinder.setWorldSize({10, 10});\n\n    // Set the heuristic function (manhattan, euclidean, octagonal etc...), it is optional, default is euclidean\n    pathFinder.setHeuristic(AStar::Heuristic::manhattan);\n\n    // if you want to enable diagonal movement, it is optional, default is false\n    pathFinder.setDiagonalMovement(true);\n\n    // Add a obstacle point (5, 5) and (5, 6)\n    pathFinder.addObstacle({5, 5});\n    pathFinder.addObstacle({5, 6});\n\n    // Find the path from (0, 0) to (9, 9)\n    auto path = pathFinder.findPath({0, 0}, {9, 9});\n\n    // Print the path\n    for (auto\u0026 p : path) {\n        std::cout \u003c\u003c p.x \u003c\u003c \" \" \u003c\u003c p.y \u003c\u003c std::endl;\n    }\n\n    return 0;\n}\n```\n\n### Alternative version (direct access to the map)\n\nYou can use the alternative version of the library if you want astar have direct access to the map, this version is faster than the non-direct access version.\n\n```cpp\n#include \u003castar/astar.hpp\u003e\n#include \u003ciostream\u003e\n\nauto main() -\u003e int {\n    // Create the template class with optional a type (e.g. uint32_t) and a boolean\n    // if you want enable debug mode (AStar::AStar\u003cuint32_t, true\u003e)\n    AStar::AStarFast pathFinder;\n\n    // Set the heuristic function (manhattan, euclidean, octagonal etc...), it is optional, default is euclidean\n    pathFinder.setHeuristic(AStar::Heuristic::manhattan);\n\n    // if you want to enable diagonal movement, it is optional, default is false\n    pathFinder.setDiagonalMovement(true);\n\n    // Create world 9x9 filled with 0\n    std::vector\u003cuint32_t\u003e world(9 * 9, 0);\n\n    // set lambda function to check if is an obstacle (value == 1)\n    auto isObstacle = [](uint32_t value) -\u003e bool { return value == 1; };\n    pathFinder.setObstacle(isObstacle);\n\n    // Add a obstacle point (5, 5) and (5, 6)\n    world[5 + 5 * 9] = 1;\n    world[5 + 6 * 9] = 1;\n\n    // Find the path from (0, 0) to (9, 9), it it equal to 0, then the path is not found\n    // This version of findPath() is faster due direct access to the world\n    auto path = pathFinder.findPath({0, 0}, {9, 9}, world, {9, 9});\n\n    // Print the path\n    for (auto\u0026 p : path) {\n        std::cout \u003c\u003c p.x \u003c\u003c \" \" \u003c\u003c p.y \u003c\u003c std::endl;\n    }\n\n    return 0;\n}\n```\n\n### Debug mode\n\nYou can enable the debug mode to call a lambda function when new node is visiting by the algorithm and when new node is added to the open list.\n\n```cpp\n#include \u003ciostream\u003e\n\n#include \u003castar/astar.hpp\u003e\n\nauto main() -\u003e int {\n    // Enable debug mode with template argument, this helps avoid performance issues on non-debug classes\n    AStar::AStar\u003cuint32_t, true\u003e pathFinder;\n\n    // Set lambda function to debug current node\n    std::function\u003cvoid(const AStar::Node\u003cuint32_t\u003e* node)\u003e debugCurrentNode = [](const AStar::Node\u003cuint32_t\u003e* node) {\n        std::cout \u003c\u003c \"Current node: \" \u003c\u003c node-\u003epos.x \u003c\u003c \", \" \u003c\u003c node-\u003epos.y \u003c\u003c std::endl;\n    };\n    pathFinder.setDebugCurrentNode(debugCurrentNode);\n\n    // Set lambda function to debug open node\n    std::function\u003cvoid(const AStar::Node\u003cuint32_t\u003e* node)\u003e debugOpenNode = [](const AStar::Node\u003cuint32_t\u003e* node) {\n        std::cout \u003c\u003c \"Add to open list: \" \u003c\u003c node-\u003epos.x \u003c\u003c \", \" \u003c\u003c node-\u003epos.y \u003c\u003c std::endl;\n    };\n    pathFinder.setDebugOpenNode(debugOpenNode);\n\n    // Define the map size (width, height)\n    pathFinder.setWorldSize({10, 10});\n\n    // Set the heuristic function (manhattan, euclidean, octagonal etc...), it is optional, default is euclidean\n    pathFinder.setHeuristic(AStar::Heuristic::manhattan);\n\n    // if you want to enable diagonal movement, it is optional, default is false\n    pathFinder.setDiagonalMovement(true);\n\n    // Add a obstacle point (5, 5) and (5, 6)\n    pathFinder.addObstacle({5, 5});\n    pathFinder.addObstacle({5, 6});\n\n    // Find the path from (0, 0) to (9, 9)\n    auto path = pathFinder.findPath({0, 0}, {9, 9});\n\n    // Print the path\n    for (auto\u0026 p : path) {\n        std::cout \u003c\u003c p.x \u003c\u003c \" \" \u003c\u003c p.y \u003c\u003c std::endl;\n    }\n\n    return 0;\n}\n```\n\n# Building and installing\n\nSee the [BUILDING](BUILDING.md) document.\n\n# Contributing\n\nSee the [CONTRIBUTING](CONTRIBUTING.md) document.\n\n# Sources, references and ideas\n\nYou can find here the sources, references, libs and ideas that I have used to make this library.\n\n## Astar\n\nSources and references that I have used to make this library.\n\n* [Wikipedia A* search algorithm](https://en.wikipedia.org/wiki/A*_search_algorithm)\n* [A* Pathfinding](https://www.youtube.com/watch?v=-L-WgKMFuhE)\n* [AStar](https://github.com/yatima1460/AStar)\n* [Introduction to A*](https://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html)\n* [Easy A* (star) Pathfinding](https://medium.com/@nicholas.w.swift/easy-a-star-pathfinding-7e6689c7f7b2)\n* [a-star](https://www.ce.unipr.it/people/medici/a-star.html)$\n* [A* Search Algorithm](https://yuminlee2.medium.com/a-search-algorithm-42c1a13fcf9f)\n\n## Others astar implementations\n\nThe list of others astar implementations that I have benchmarked to compare the performance of my implementation.\n\n* [A* Search Algorithm](https://www.geeksforgeeks.org/a-search-algorithm/)\n* [a-star](https://github.com/daancode/a-star)\n* [A-Star-Search-Algorithm](https://github.com/lychengrex/A-Star-Search-Algorithm)\n* [Pathfinding](https://github.com/Gerard097/Pathfinding)\n\n## Libraries\n\nLibraries used in this project.\n\n* [cmake-init](https://github.com/friendlyanon/cmake-init)\n* [google test](https://github.com/google/googletest)\n* [google benchmark](https://github.com/google/benchmark)\n* [Raylib](https://github.com/raysan5/raylib)\n\n# Others\n\n* [Benchmark visualization](https://int-i.github.io/python/2021-11-07/matplotlib-google-benchmark-visualization/)\n\n# Licensing\n\n[LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbensuperpc%2Fastar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbensuperpc%2Fastar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbensuperpc%2Fastar/lists"}