{"id":20010649,"url":"https://github.com/bradhowes/astar","last_synced_at":"2026-05-09T12:34:06.065Z","repository":{"id":63906044,"uuid":"257982346","full_name":"bradhowes/astar","owner":"bradhowes","description":"A* path finding library in Swift","archived":false,"fork":false,"pushed_at":"2023-12-19T17:34:53.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-02T02:56:43.475Z","etag":null,"topics":["algorithm","pathfinding","swift-package-manager","swift5"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/bradhowes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","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},"funding":{"github":"bradhowes"}},"created_at":"2020-04-22T18:11:03.000Z","updated_at":"2022-04-13T07:09:53.000Z","dependencies_parsed_at":"2024-11-13T07:23:24.525Z","dependency_job_id":"8b946a65-ff51-4fee-b142-019ad69a4870","html_url":"https://github.com/bradhowes/astar","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"cf55d641ac4d6c505d196e7dccdcca7b9aa4cb7e"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradhowes%2Fastar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradhowes%2Fastar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradhowes%2Fastar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradhowes%2Fastar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradhowes","download_url":"https://codeload.github.com/bradhowes/astar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241447523,"owners_count":19964314,"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":["algorithm","pathfinding","swift-package-manager","swift5"],"created_at":"2024-11-13T07:21:00.942Z","updated_at":"2026-05-09T12:34:06.057Z","avatar_url":"https://github.com/bradhowes.png","language":"Swift","funding_links":["https://github.com/sponsors/bradhowes"],"categories":[],"sub_categories":[],"readme":"[![CI][status]][ci]\n[![][spiv]][spi]\n[![][spip]][spi]\n[![][mit]][license]\n\n# AStar - an A* Library in Swift\n\nThe AStar library implements the classic A* path-finding algorithm. It uses a min priority queue for managing potential\npaths, ordered by each path's known and estimated cost. The AStar class delegates map-related functionality to a\n[GraphOracle](Sources/AStar/GraphOracle.swift) protocol to determine valid locations as well as the cost of adding a \nlocation to a path candidate. An example of a `GraphOracle` can be found in the \n[AStarTests.swift](Tests/AStarTests/AStarTests.swift) file.\n\nAPI Documentation: [AStar][doc]\n\n## Example\n\nThe AStar API is quite basic: there is just the static \n[find](Sources/AStar/AStar.swift#L47) method which provides the \noracle to use, and the start and end locations for the path.\n\n```swift\nlet oracle = Oracle(data: [\n    [.🌊, .🌲, .🌲, .🌲, .🚩, .🌲, .🌲, .🌲],\n    [.🌊, .🌲, .🌲, .🌲, .🌲, .🌲, .🌲, .🌲],\n    [.🌲, .🌲, .🌲, .🌲, .🗻, .🌲, .🌲, .🌲],\n    [.🌲, .🌲, .🗻, .🗻, .🗻, .🗻, .🗻, .🌲],\n    [.🌲, .🌲, .🗻, .🌲, .🏁, .🗻, .🌊, .🌊],\n    [.🌲, .🌲, .🗻, .🌲, .🗻, .🌲, .🌲, .🌊],\n    [.🌊, .🌲, .🗻, .🌲, .🌲, .🌲, .🗻, .🗻],\n    [.🌊, .🌲, .🌲, .🌲, .🌲, .🌲, .🗻, .🌲]\n])\n\nlet start = Coord2D(x: 4, y: 0) // location of 🚩 above\nlet end = Coord2D(x: 4, y: 4)   // location of 🏁 above\nlet path = AStar.find(\n  oracle: oracle, \n  start: start, \n  end: end\n)\n```\n\nYou supply an `oracle` entity that implements the `GraphOracle` protocol like the `Oracle` above. The oracle provides\ninformation used by the A* algorithm to learn about the routes available from a location and the costs involved in\npicking one. The start and end points indicate where to start the path and the goal to reach with the lowest possible\ncost.\n\nYou get back an optional array of [Position](Sources/AStar/Position.swift) values. If this is `nil` then no path was found. \nOtherwise, the array will have the map coordinates and their associated costs for the path that was found, \nstarting at `start` and ending with `end`.\n\nHere is the visual representation of the map with the found path. The starting position appears as a red flag (🚩) and\nthe end position is a checkered flag (🏁). The path in between these two points contains an adventurer (🏃).\n\n```swift\nlet image = mapData.asString(path: path!)\nprint(image)\n🌊🌲🌲🌲🚩🌲🌲🌲\n🌊🌲🌲🌲🌲🏃🌲🌲\n🌲🌲🌲🌲🗻🌲🏃🌲\n🌲🌲🗻🗻🗻🗻🗻🏃\n🌲🌲🗻🌲🏁🗻🏃🌊\n🌲🌲🗻🌲🗻🏃🌲🌊\n🌊🌲🗻🌲🌲🌲🗻🗻\n🌊🌲🌲🌲🌲🌲🗻🌲\n```\n\nFor this example, the map contains three different terrain elements, each with their own cost for travelling into their square:\n\n* 🌲 tree (1)\n* 🌊 water (2)\n* 🗻 boulder (99)\n\nThe algorithm minimizes the cost of traveling over terrain elements while at the same time trying to keep to the shortest path.\nFor comparison, here is what the algorithm finds when constrained to not use diagonal moves:\n\n```swift\n🌊🌲🌲🌲🚩🌲🌲🌲\n🌊🌲🌲🏃🏃🌲🌲🌲\n🌲🏃🏃🏃🗻🌲🌲🌲\n🌲🏃🗻🗻🗻🗻🗻🌲\n🌲🏃🗻🏃🏁🗻🌊🌊\n🌲🏃🗻🏃🗻🌲🌲🌊\n🌊🏃🗻🏃🌲🌲🗻🗻\n🌊🏃🏃🏃🌲🌲🗻🌲\n\n```\n\nNote that this is not the only path to the flag in 16 moves -- there is another path to goes to the right but it goes over two \n🌊 positions which increases the total cost of the route by 2. Thus the algorithm chose the one shown above due to the overal\nlower cost of the journey.\n\n## Dependencies\n\nThis package relies on the [PriorityQueue](https://github.com/bradhowes/PriorityQueue) package for Swift that provides a\nmin/max ordering of items using a binary heap.\n\n[doc]: https://swiftpackageindex.com/bradhowes/astar/main/documentation/astar\n[ci]: https://github.com/bradhowes/astar/actions/workflows/CI.yml\n[status]: https://github.com/bradhowes/astar/workflows/CI/badge.svg\n[spi]: https://swiftpackageindex.com/bradhowes/astar\n[spiv]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbradhowes%2Fastar%2Fbadge%3Ftype%3Dswift-versions\n[spip]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fbradhowes%2Fastar%2Fbadge%3Ftype%3Dplatforms\n[mit]: https://img.shields.io/badge/License-MIT-A31F34.svg\n[license]: https://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradhowes%2Fastar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradhowes%2Fastar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradhowes%2Fastar/lists"}