{"id":18463861,"url":"https://github.com/smartive/rust-sokoban-level-generator","last_synced_at":"2025-04-08T07:32:52.538Z","repository":{"id":211442254,"uuid":"729100345","full_name":"smartive/rust-sokoban-level-generator","owner":"smartive","description":"A procedural level generator for \"sokoban\".","archived":true,"fork":false,"pushed_at":"2024-08-05T20:50:19.000Z","size":35,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-02-16T16:58:03.846Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smartive.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}},"created_at":"2023-12-08T12:14:19.000Z","updated_at":"2024-10-28T09:58:52.000Z","dependencies_parsed_at":"2023-12-08T15:23:40.585Z","dependency_job_id":"fa891b36-2f92-4986-96c3-a2b3fccdd5f4","html_url":"https://github.com/smartive/rust-sokoban-level-generator","commit_stats":null,"previous_names":["smartive/rust-sokoban-level-generator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Frust-sokoban-level-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Frust-sokoban-level-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Frust-sokoban-level-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smartive%2Frust-sokoban-level-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smartive","download_url":"https://codeload.github.com/smartive/rust-sokoban-level-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247796360,"owners_count":20997554,"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-11-06T09:08:11.316Z","updated_at":"2025-04-08T07:32:52.306Z","avatar_url":"https://github.com/smartive.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sokoban Level Generator in Rust\n\nThis is a sokoban level generator algorithm written in rust to procedurally\ngenerate levels for the game [Sokoban](https://en.wikipedia.org/wiki/Sokoban).\n\nThe algorithm is based on the following resources:\n\n- [Procedural Generation of Sokoban Levels](http://ianparberry.com/techreports/LARC-2011-01.pdf);\n  a technical report by Joshua Taylor and Ian Parberry.\n- [Sokoban-Level-Generator](https://github.com/AlliBalliBaba/Sokoban-Level-Generator);\n  a javascript implementation by AlliBalliBaba.\n\n## Usage\n\nIn order to use the generator, add this library (via git) to your project\nwith cargo. Then, import the level generator and use it to generate\na level. The ``level_to_string`` method allows you to print the level\nin the [JSoko Level Format](https://www.sokoban-online.de/sokoban/levell-format/).\n\n```rust\nuse sokoban_level_generator::{generate_level, level_to_string};\n\nfn main() {\n    let level = generate_level(4, 4, 3);\n    println!(\"Print level\");\n    println!(\"{}\", level_to_string(\u0026level));\n}\n```\n\nThe algorithm uses randomness to generate levels and needs\nto create the \"farthest state possible\" for boxes. As such,\ngeneration with more boxes can take a very long time. See the\nbenchmarks section for more information.\n\n**Warning**: Currently, there is no abort limit. So, trying to\ngenerate impossible levels (e.g. 1x1 with 4 boxes) will result\nin an infinite loop.\n\n## Algorithm\n\nThe algorithm performs the following (high-level) steps:\n\n1. Generate an empty level with ``width * 3`` and ``height * 3`` dimensions, since every \"room\" is 3x3.\n2. Generate rooms in the level (by using the described templates in the paper); rooms are randomly selected and rotated\n3. After the level is generated, check the level for:\n    - Enough space\n    - Enough goal possibilities (to place goals)\n    - No large spaces (this does not generate interesting levels)\n    - All floors are connected\n    - No surrounded floors\n4. Generate random goal locations\n5. Calculate the \"farthest state possible\" for each box/player position\n6. Return the farthest possible level\n\n## Benchmarks\n\nBenchmarks show that the algorithm is very fast for small levels, but\ncan take a very long time for larger levels. The biggest impact on\ngeneration time is the number of boxes.\n\nThe result in short: feasible, interesting levels can be generated with\nup to 4 boxes in a reasonable amount of time. The height / width of the\nlevel should be kept below or equal to 3. If 3 or fewer boxes are used,\nthe level can be up to 4x4 in size. Bigger sizes must be experimented with.\n\nThe following tables shows the generation time for different level sizes.\n\n### 1 Box\n| Width | Height | Median Time |\n|-------|--------|-------------|\n| 1     | 1      | 5.7706 µs   |\n| 1     | 2      | 19.403 µs   |\n| 2     | 2      | 84.277 µs   |\n| 2     | 3      | 4.3456 ms   |\n| 3     | 3      | 1.3252 ms   |\n| 3     | 4      | 6.3146 ms   |\n| 4     | 4      | 33.759 ms   |\n\n### 2 Boxes\n| Width | Height | Median Time |\n|-------|--------|-------------|\n| 1     | 2      | 36.320 µs   |\n| 2     | 2      | 241.53 ms   |\n| 3     | 2      | 798.81 µs   |\n| 3     | 3      | 2.9076 ms   |\n| 4     | 3      | 10.201 ms   |\n| 4     | 4      | 42.901 ms   |\n\n### 3 Boxes\n| Width | Height | Median Time |\n|-------|--------|-------------|\n| 2     | 3      | 4.3456 ms   |\n| 3     | 3      | 20.324 ms   |\n| 3     | 4      | 50.916 ms   |\n| 4     | 4      | 227.51 ms   |\n\n### Violin Plot (1-3 Boxes)\n\n![Violin Plot](./res/violin.svg)\n\nAs we can see in the violin plot, the number of boxes has a huge impact on the generation time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartive%2Frust-sokoban-level-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmartive%2Frust-sokoban-level-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmartive%2Frust-sokoban-level-generator/lists"}