{"id":48591772,"url":"https://github.com/nsmryan/zig_astar","last_synced_at":"2026-04-08T20:02:09.668Z","repository":{"id":151912293,"uuid":"532618546","full_name":"nsmryan/zig_astar","owner":"nsmryan","description":"Simple implementation of the A-Star algorithm in Zig ","archived":false,"fork":false,"pushed_at":"2025-06-29T12:56:55.000Z","size":4,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-29T13:44:25.426Z","etag":null,"topics":["astar","library","zig","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsmryan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2022-09-04T18:07:37.000Z","updated_at":"2025-06-29T12:56:58.000Z","dependencies_parsed_at":"2023-05-15T16:30:39.534Z","dependency_job_id":null,"html_url":"https://github.com/nsmryan/zig_astar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nsmryan/zig_astar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_astar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_astar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_astar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_astar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsmryan","download_url":"https://codeload.github.com/nsmryan/zig_astar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsmryan%2Fzig_astar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31571601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","library","zig","ziglang"],"created_at":"2026-04-08T20:02:08.990Z","updated_at":"2026-04-08T20:02:09.652Z","avatar_url":"https://github.com/nsmryan.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"I don't recommend using this repository!\nThere is an updated, less buggy version in my Rust Game on https://codeberg.org/tuplestruct/rrl\nI haven't been using GitLab, and I haven't back ported the updated version of this code back to this repo, so please do not trust it!\n\n\n# Zig AStar\n\nThis repository contains a simple implementation of the A-Star algorithm in Zig.\n\nThis is not intended to be fancy. However, it does take a user-defined\nposition type and distance function, and does not assume anything about the\nspace that the pathfinding takes place in.\n\nInstead the algorithm expects the user to drive it, tracking paths and asking the user\nfor the neighbors of a particular location. When the algorithm finds a path to the end\nlocation it will report that it is done. This is similar to an iterator, and avoids\nrequiring any kind of user defined map type or \"neighbors\" function to be provided.\n\nThe implementation uses the std.ArrayList and std.PriorityQueue, and takes an allocator\nfrom the user.\n\n\nSee below for an example use. Notice that the user code drives the search by\ncalling 'step', and feeding back the requested slice of neighbor positions.\n```zig\n\nconst SimplePos = struct {\n    x: isize,\n    y: isize,\n\n    pub fn init(x: isize, y: isize) SimplePos {\n        return SimplePos{ .x = x, .y = y };\n    }\n};\n\nfn simple_distance(start: SimplePos, end: SimplePos) usize {\n    const x_dist = std.math.absInt(start.x - end.x) catch unreachable;\n    const y_dist = std.math.absInt(start.y - end.y) catch unreachable;\n    return @intCast(usize, std.math.min(x_dist, y_dist));\n}\n\npub main() void {\n    const allocator = std.heap.page_allocator;\n\n    const PathFinder = Astar(SimplePos, simple_distance);\n\n    var neighbors = ArrayList(SimplePos).init(allocator);\n    defer neighbors.deinit();\n    \n    const start = SimplePos.init(0, 0);\n    const end = SimplePos.init(4, 4);\n    \n    var result = try finder.pathFind(start, end);\n    while (result == .neighbors) {\n        const pos = result.neighbors;\n\n        neighbors.clearRetainingCapacity();\n\n        const offsets: [3]isize = .{ -1, 0, 1 };\n        for (offsets) |offset_x| {\n            for (offsets) |offset_y| {\n                const new_x = pos.x + offset_x;\n                const new_y = pos.y + offset_y;\n                \n                // User defined validity function 'IsValid' not shown.\n                if (!IsValid(new_x, new_y)) {\n                    continue;\n                }\n                const next_pos = SimplePos.init(new_x, new_y);\n                try neighbors.append(next_pos);\n            }\n        }\n\n        result = try finder.step(neighbors.items);\n    }\n    \n    // The 'result' variable is now either .done, with the Path structure containing the\n    // path from start to end, or .no_path indicating that there is no valid path.\n    switch (result) {\n        .no_path =\u003e {\n            // Error\n        },\n        \n        .done =\u003e |path| {\n            // Path from start to end of type Path(SimplePos).\n        },\n        \n        .neighbors =\u003e {\n            unreachable\n        },\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsmryan%2Fzig_astar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsmryan%2Fzig_astar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsmryan%2Fzig_astar/lists"}