{"id":16659910,"url":"https://github.com/venantius/maze","last_synced_at":"2025-04-09T18:42:34.699Z","repository":{"id":68719510,"uuid":"78236109","full_name":"venantius/maze","owner":"venantius","description":"Mazes for Programmers","archived":false,"fork":false,"pushed_at":"2017-02-15T18:30:48.000Z","size":102,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T20:43:39.763Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/venantius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2017-01-06T20:22:32.000Z","updated_at":"2023-08-24T09:55:11.000Z","dependencies_parsed_at":"2023-03-13T20:27:47.509Z","dependency_job_id":null,"html_url":"https://github.com/venantius/maze","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/venantius%2Fmaze","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/venantius%2Fmaze/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/venantius%2Fmaze/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/venantius%2Fmaze/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/venantius","download_url":"https://codeload.github.com/venantius/maze/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248090270,"owners_count":21046051,"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-12T10:27:05.539Z","updated_at":"2025-04-09T18:42:34.654Z","avatar_url":"https://github.com/venantius.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview\n\nThis repository includes code for generating and solving mazes. The algorithms\nincluded are taken from [Mazes for Programmers](https://pragprog.com/book/jbmaze/mazes-for-programmers),\nand have been translated here from their original Ruby to Go.\n\nThis README covers the basics of how to work with this library and what sort of output you can expect from it.\n\n## Grids\n\nGrids are the basic \"objects\" of mazes. The general usage pattern is to\ncreate a grid and then to apply a maze generation algorithm to it. From there, you can run additional algorithms, for instance to determine the shortest or longest path from one point in the maze to another.\n\n### BaseGrid\n\nThe most basic type of grid in this library is a `BaseGrid`. You can see how it works as follows:\n\n```golang\nimport (\n    \"maze.generator\"\n    \"maze.model\"\n)\n\nfunc main() {\n    // first, we create a 5x5 BaseGrid.\n    g := model.NewBaseGrid(5, 5);\n\n    // Next, we apply the Sidewinder maze generation algorithm to it\n    generator.Sidewinder(g);\n\n    // Now, we print it as ASCII\n    fmt.Println(g);\n}\n```\n\nThis will print something like the following to stdout:\n\n```\n+---+---+---+---+---+\n|                   |\n+   +---+   +   +---+\n|       |   |       |\n+   +   +---+   +---+\n|   |       |       |\n+   +   +---+   +---+\n|   |   |           |\n+---+   +   +---+---+\n|       |           |\n+---+---+---+---+---+\n```\n\nYou can also generate a PNG image of the same grid using `ToPNG`:\n\n```golang\nfilename := \"sidewinder.png\";\ng.ToPNG(filename, 10);\n```\n\nThis will generate an image that looks like the following:\n\n![](/doc/images/sidewinder.png)\n\n### DistanceGrid\n\nIf you want to see how far a given point is from another, you can use a\n`DistanceGrid`. In practice, `DistanceGrid` by itself isn't that interesting,\nbut is a good foundation for gradient coloring later on.\n\nThe following example shows how you can use a `DistanceGrid` to determine\nthe shortest path between any two points in a maze, using Djikstra's algorithm:\n\n```go\nfunc main() {\n    g := model.NewDistanceGrid(5, 5)\n\n    // Apply the Binary Tree maze generation algorithm\n    generator.BinaryTree(g)\n\n    // Pick a random starting cell, or any cell you want.\n    start := g.RandomCell();\n\n    // Calculate the shortest path between the starting cell and all other cells.\n    distances := start.Distances();\n    g.SetDistances(distances);\n\n    // Print to stdout.\n    fmt.Println(g)\n}\n```\n\nNote that distances will be measured in base36, meaning the 10th cell away from\nthe starting point will be assigned an 'a', the 11th cell will be a 'b', etc.\n\n```\n+---+---+---+---+---+\n| 3   2   3   4   5 |\n+   +   +   +---+   +\n| 4 | 1 | 4 | 7   6 |\n+   +   +   +   +   +\n| 5 | 0 | 5 | 8 | 7 |\n+   +---+   +   +   +\n| 6 | 7   6 | 9 | 8 |\n+   +   +---+---+   +\n| 7 | 8 | b   a   9 |\n+---+---+---+---+---+\n```\n\nYou can also extend our example to directly print the shortest path between\ntwo points, like so :\n\n```go\n// Print the shortest distance between our random starting cell and the cell\n// in the bottom-left\ng.SetDistances(distances.PathTo(g.GetCell(g.GetRows() - 1, 0)));\nfmt.Println(g);\n```\n\nThis will print something like the following:\n\n```\n+---+---+---+---+---+\n| 3   2             |\n+   +   +   +---+   +\n| 4 | 1 |   |       |\n+   +   +   +   +   +\n| 5 | 0 |   |   |   |\n+   +---+   +   +   +\n| 6 |       |   |   |\n+   +   +---+---+   +\n| 7 |   |           |\n+---+---+---+---+---+\n```\n\n### ColoredGrid\n\nIf you want to generate colored PNG images of your mazes, use the `ColoredGrid` struct instead of `BaseGrid`, like so\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvenantius%2Fmaze","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvenantius%2Fmaze","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvenantius%2Fmaze/lists"}