{"id":15697059,"url":"https://github.com/shekohex/a-star-algorithm-js","last_synced_at":"2025-05-08T23:31:39.940Z","repository":{"id":89445040,"uuid":"108500331","full_name":"shekohex/a-star-algorithm-js","owner":"shekohex","description":"a simple implementation of A* algorithm in javascript","archived":false,"fork":false,"pushed_at":"2023-04-19T09:01:52.000Z","size":57,"stargazers_count":7,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T19:21:19.111Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/shekohex.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":"2017-10-27T04:46:31.000Z","updated_at":"2024-03-30T18:07:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"1fbdef13-e1a2-4848-bfbf-d51211517d34","html_url":"https://github.com/shekohex/a-star-algorithm-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shekohex%2Fa-star-algorithm-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shekohex%2Fa-star-algorithm-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shekohex%2Fa-star-algorithm-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shekohex%2Fa-star-algorithm-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shekohex","download_url":"https://codeload.github.com/shekohex/a-star-algorithm-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253163839,"owners_count":21864144,"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":[],"created_at":"2024-10-03T19:11:22.845Z","updated_at":"2025-05-08T23:31:39.918Z","avatar_url":"https://github.com/shekohex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/shekohex/a-star-algorithm-js.svg)](https://greenkeeper.io/)\n\n[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.png?v=103)](https://github.com/ellerbrock/open-source-badges/)\n\n# A* Search Algorithm in Javascript\n a simple implementation of A* algorithm in javascript\n\n## Example\nAn example of an A* algorithm in action where nodes are cities connected with roads and h(x) is the straight-line distance to target point:\nAn example of A* algorithm in action (nodes are cities connected with roads, h(x) is the straight-line distance to target point) Green: Start, Blue: Target, Orange: Visited\n\n[![GIF](https://upload.wikimedia.org/wikipedia/commons/9/98/AstarExampleEn.gif)](https://en.wikipedia.org/wiki/A*_search_algorithm)\n\n\nKey: green: start; blue: goal; orange: visited\n\n* [Demo](https://shekohex.github.io/a-star-algorithm-js/public/)\n\n  \n### The following pseudocode describes the algorithm\n\n```r\nfunction A*(start, goal)\n    // The set of nodes already evaluated\n    closedSet := {}\n\n    // The set of currently discovered nodes that are not evaluated yet.\n    // Initially, only the start node is known.\n    openSet := {start}\n\n    // For each node, which node it can most efficiently be reached from.\n    // If a node can be reached from many nodes, cameFrom will eventually contain the\n    // most efficient previous step.\n    cameFrom := an empty map\n\n    // For each node, the cost of getting from the start node to that node.\n    gScore := map with default value of Infinity\n\n    // The cost of going from start to start is zero.\n    gScore[start] := 0\n\n    // For each node, the total cost of getting from the start node to the goal\n    // by passing by that node. That value is partly known, partly heuristic.\n    fScore := map with default value of Infinity\n\n    // For the first node, that value is completely heuristic.\n    fScore[start] := heuristic_cost_estimate(start, goal)\n\n    while openSet is not empty\n        current := the node in openSet having the lowest fScore[] value\n        if current = goal\n            return reconstruct_path(cameFrom, current)\n\n        openSet.Remove(current)\n        closedSet.Add(current)\n\n        for each neighbor of current\n            if neighbor in closedSet\n                continue\t\t// Ignore the neighbor which is already evaluated.\n\n            if neighbor not in openSet\t// Discover a new node\n                openSet.Add(neighbor)\n            \n            // The distance from start to a neighbor\n            tentative_gScore := gScore[current] + dist_between(current, neighbor)\n            if tentative_gScore \u003e= gScore[neighbor]\n                continue\t\t// This is not a better path.\n\n            // This path is the best until now. Record it!\n            cameFrom[neighbor] := current\n            gScore[neighbor] := tentative_gScore\n            fScore[neighbor] := gScore[neighbor] + heuristic_cost_estimate(neighbor, goal) \n\n    return failure\n\nfunction reconstruct_path(cameFrom, current)\n    total_path := [current]\n    while current in cameFrom.Keys:\n        current := cameFrom[current]\n        total_path.append(current)\n    return total_path\n```\n## Wikipedia\nyou can get a lot of information about this algorithm [Here](https://en.wikipedia.org/wiki/A*_search_algorithm)\n\n## Built With\n\n* [NodeJS](https://nodejs.org) - for making a simple http server [optinal to use it]\n* [p5.js](https://p5js.org) - p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.\n\n## Authors\n\n* **Shady Khalifa** - *Initial work*\n\nSee also the list of [contributors](https://github.com/your/project/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshekohex%2Fa-star-algorithm-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshekohex%2Fa-star-algorithm-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshekohex%2Fa-star-algorithm-js/lists"}