{"id":17125368,"url":"https://github.com/ruby0x1/wren-astar","last_synced_at":"2025-04-10T02:01:49.184Z","repository":{"id":140038969,"uuid":"304129299","full_name":"ruby0x1/wren-astar","owner":"ruby0x1","description":"A generic implementation of A* pathfinding in Wren - https://wren.io","archived":false,"fork":false,"pushed_at":"2020-10-14T21:55:04.000Z","size":327,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T03:35:18.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/ruby0x1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2020-10-14T20:34:50.000Z","updated_at":"2023-07-25T14:40:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"a80b60c3-06ff-403b-b3c8-8d3045214c47","html_url":"https://github.com/ruby0x1/wren-astar","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/ruby0x1%2Fwren-astar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0x1%2Fwren-astar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0x1%2Fwren-astar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby0x1%2Fwren-astar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby0x1","download_url":"https://codeload.github.com/ruby0x1/wren-astar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142976,"owners_count":21054671,"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-14T18:44:46.344Z","updated_at":"2025-04-10T02:01:49.030Z","avatar_url":"https://github.com/ruby0x1.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# wren-astar\n\nA generic implementation of A* pathfinding in the Wren programming language - https://wren.io\n\nShown below: different heuristics + neighbors + costs\n\n![](images/image.jpg)\n\n## Usage\n\nThe basic usage is `import \"astar\" for Astar`, and call `Astar.path2D`.\nFor details about the pathfinding and things like costs, heuristics and implementation\ndetails, please see https://www.redblobgames.com/pathfinding/a-star/introduction.html\n\n### Requirements\nFor now, it's required that the nodes you pass to this respond to `.x` and `.y` for the `path2D` function.\nThat's true for `start`, `end`, and values returned from `neighbors_get_fn`.\nBasically, any class is valid, provided it has these getters. An example class is shown below.\n\nCoordinates must be within 16 bit range (negative or positive), as in `−32,768  =\u003e 32,767` or `0 =\u003e 65,535`.\n\n```js\nclass Node {\n  x { _x }\n  y { _y }\n  construct new(x, y) {\n    _x = x\n    _y = y\n  }\n}\n```\n\n### Astar.path2D\n\nReturns a path between `start` and `end` if one was found, or `null` otherwise.\nThe path is a `List` of nodes received from `start`, `end` or `neighbors_get_fn` and are unmodified.\n\n**Note**: Check if `start`/`end` are walkable before calling this function.\n\n```js\nget_path(start, end) {\n  if(!is_walkable(start)) return null\n  if(!is_walkable(end)) return null\n  return AStar.path2D(start, end, _cost_get_fn, _neighbors_get_fn, _heuristic_fn)\n}\n```\n\n\u003e `start`   \n\nA node with an `.x` and `.y` getter that is the beginning of the path.\n\n\u003e `end`   \n\nA node with an `.x` and `.y` getter that is the goal for the path.\n\n\u003e `cost_get_fn`   \n\nA function you provide that returns the traversal cost for a node given to the function.\nThis function passes a `from` node and a `to` node. if you don't have a cost, return 1.\n```js\n//no cost?\n_cost_get_fn = Fn.new {|from, to| 1 }\n//cost from a tilemap, simple (fake) example\n_cost_get_fn = Fn.new {|from, to| tiles.get_cost(to.x, to.y) }\n```\n\n\u003e `neighbors_get_fn`   \n\nA function you provide that returns a list of the neighbors for a given node, as a node with an `.x` and `.y` getter.\nThis function can decide whether diagonals are included or not.\n```js\n_neighbors_get_fn = Fn.new {|node|\n  var list = []\n  //check above, below, left and right.\n  if(is_walkable(node.x, node.y+1)) list.add(Node.new(node.x, node.y+1))\n  if(is_walkable(node.x, node.y-1)) list.add(Node.new(node.x, node.y-1))\n  if(is_walkable(node.x+1, node.y)) list.add(Node.new(node.x+1, node.y))\n  if(is_walkable(node.x-1, node.y)) list.add(Node.new(node.x-1, node.y))\n  return list\n}\n```\n\n\u003e `heuristic_fn`   \n\nA function you provide that returns a heuristic value for a given point (in relation to the goal/end of the path).\n```js\n_heuristic_fn = Fn.new {|end, point|\n  var manhattan = ((end.x - point.x).abs + (end.y - point.y).abs)\n  return manhattan * 1.001 //fudge factor, see the linked articles on pathfinding\n}\n```\n\n### Astar.MAX\n\nA value that defaults to `250`, for the max number of iterations that will be considered valid. If the max is reached no path is returned.\nTo update it, use `Astar.MAX = 400`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby0x1%2Fwren-astar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby0x1%2Fwren-astar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby0x1%2Fwren-astar/lists"}