{"id":26964466,"url":"https://github.com/nicklayb/labyrelm","last_synced_at":"2025-04-03T06:32:29.023Z","repository":{"id":86259075,"uuid":"181388509","full_name":"nicklayb/labyrelm","owner":"nicklayb","description":"Elm implementation of Prim algorithm to generate labyrinth.","archived":false,"fork":false,"pushed_at":"2024-02-18T04:01:37.000Z","size":286,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-15T03:51:54.046Z","etag":null,"topics":["elm","labyrinth","learning","maze","prim-algorithm"],"latest_commit_sha":null,"homepage":"https://nicklayb.github.io/labyrelm","language":"Elm","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/nicklayb.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}},"created_at":"2019-04-15T01:00:32.000Z","updated_at":"2024-02-19T05:43:00.000Z","dependencies_parsed_at":"2023-03-13T09:17:52.999Z","dependency_job_id":null,"html_url":"https://github.com/nicklayb/labyrelm","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/nicklayb%2Flabyrelm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicklayb%2Flabyrelm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicklayb%2Flabyrelm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nicklayb%2Flabyrelm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nicklayb","download_url":"https://codeload.github.com/nicklayb/labyrelm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246948061,"owners_count":20859370,"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":["elm","labyrinth","learning","maze","prim-algorithm"],"created_at":"2025-04-03T06:31:39.167Z","updated_at":"2025-04-03T06:32:29.011Z","avatar_url":"https://github.com/nicklayb.png","language":"Elm","readme":"# Labyrelm\n\n[Demo](https://nicklayb.github.io/labyrelm)\n\nElm implementation of Prim algorithm to generate labyrinth. Only used to learning.\n\n## Why?\n\nI did the Prim Algorithm using C# at University and was wondering how this would be done in functional programming. It has his challenges but, I think, makes a more maintenable program.\n\n### How it works\n\nThe Prim Algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph [https://en.wikipedia.org/wiki/Prim%27s_algorithm](https://en.wikipedia.org/wiki/Prim%27s_algorithm)\n\nIt basically works this way. Suppose a matrix of nodes with east and south bridges like the following\n\n```\n# 3 # 6 # 9 #\n2   5   2   1\n# 1 # 3 # 2 #\n4   7   9   3\n# 7 # 5 # 3 #\n```\n\n- `#` are nodes\n- `+` are visited nodes\n- `[0-10]` are bridges. The number is their weight.\n\nStarting with any border node (let's say (0, 0)), you browse the visited node the find the lowest edge **that is not connected to an already visited node**. From (0, 0), the lowest is `2` on the south. You mark this bridge as selected and add the node connected to it in the visited node. (It now contains `[(0, 0), (1, 0)]`).\n\n```\n+ 3 # 6 # 9 #\n|   5   2   1\n+ 1 # 3 # 2 #\n4   7   9   3\n# 7 # 5 # 3 #\n```\n\nThen again we browse the visited node the find the lowest bridge. The lowest is the one connected with the (1, 0) node. We mark the bridge as selected and then we add the node connected to it as vissted.\n\n\n```\n+ 3 # 6 # 9 #\n|   5   2   1\n+ - + 3 # 2 #\n4   7   9   3\n# 7 # 5 # 3 #\n```\n\nRepeat the process until the visited node count matches the total node count. In the end the maze would look like this\n\n\n```\n+ - +   +   +\n|       |   |\n+ - + - + - +\n|           |\n+   + - + - +\n```\n\n\n## Start the game\n\nRun the following commands to start the development server\n\n```\nnpm install\nnpm run start\n```\n\n### Home screen\n\nOn the home screen you can enter the size of the grid you want and the seed to use. Once you click the `Create a x by y labyrinth` you'll be redirected to `/game/seed/x/y` where you have a viewport of 3 by 3 on your labyrinth. (The redirection has forced me to learn and use Elm's routing).\n\n### Grid view\n\nClick the Up/Right/Down/Left case to move in the labyrinth to that direction. Once you'll find the end, your emoji will be happy. Gray block are walls and white ones are floor.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicklayb%2Flabyrelm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicklayb%2Flabyrelm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicklayb%2Flabyrelm/lists"}