{"id":22022158,"url":"https://github.com/michaelkim/15puzzle","last_synced_at":"2025-10-14T02:19:34.576Z","repository":{"id":45194539,"uuid":"107132969","full_name":"MichaelKim/15puzzle","owner":"MichaelKim","description":"A C++ solver for the generalized 15-Puzzle","archived":false,"fork":false,"pushed_at":"2022-01-01T23:17:29.000Z","size":271,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T22:23:28.689Z","etag":null,"topics":["15-puzzle","cpp","ida-star-algorithm"],"latest_commit_sha":null,"homepage":"","language":"C++","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/MichaelKim.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}},"created_at":"2017-10-16T13:43:04.000Z","updated_at":"2023-09-16T05:45:16.000Z","dependencies_parsed_at":"2022-09-05T17:50:53.492Z","dependency_job_id":null,"html_url":"https://github.com/MichaelKim/15puzzle","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/MichaelKim%2F15puzzle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelKim%2F15puzzle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelKim%2F15puzzle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelKim%2F15puzzle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MichaelKim","download_url":"https://codeload.github.com/MichaelKim/15puzzle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246507400,"owners_count":20788817,"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":["15-puzzle","cpp","ida-star-algorithm"],"created_at":"2024-11-30T06:18:30.348Z","updated_at":"2025-10-14T02:19:29.530Z","avatar_url":"https://github.com/MichaelKim.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 15puzzle\n\nThis is a solver for the generalized 15-puzzle written in C++. It can optimally solve any p x q sized board, although it becomes very slow for boards larger than 4 x 4, and some 4 x 4 boards with long solutions.\n\nTo solve a puzzle, it uses the IDA\\* algorithm with an [additive disjoint pattern database](https://www.sciencedirect.com/science/article/pii/S0004370201000923).\n\nThis solver has also been ported to WebAssembly using Emscripten [here](https://github.com/LenKagamine/15puzzle.js).\n\n## Executable\n\n### Build\n\n```sh\nmake\n\n# or\n\nmkdir build\ncd build\ncmake ..\n\n# or\n\ng++ -std=c++17 src/*.cpp -o bin/puzzle\n```\n\n### Usage\n\n```\nSyntax:\n  puzzle [OPTIONS]\n\nOptions:\n  -b \u003cfile\u003e\n    Board files\n  -d \u003cfile\u003e\n    Use database file\n  -h, --help\n    Print this help message\n  -i, --interactive\n    Show a playback of each solution\n```\n\nAlternatively, the database and board files can be read in through standard input. The following three commands will do the same solves:\n\n```sh\ncat databases/8-reg | ./puzzle -b boards/8-reg\ncat boards/8-reg | ./puzzle -d databases/8-reg\ncat databases/8-reg boards/8-reg | ./puzzle\n```\n\n## File Formats\n\nThis program comes with several preset board sizes and database patterns. However, it is very simple to create custom boards and databases to solve any sized boards.\n\n- `databases/8-reg` uses only one pattern for the entire 3x3 grid, as it is small enough to quickly generate the database.\n- `databases/443-reg` is for solving the 11-puzzle.\n- `databases/555-reg` and `databases/663-reg` both solve the 15-puzzle. The 663 pattern takes longer to generate (as larger patterns take exponentially longer), but solve it slightly faster than the 555 pattern.\n- `databases/555-rev` is for the reversed 15-puzzle board.\n\nThere are two versions of the solved state of the 15-puzzle: one has the empty tile in the top-left, and the other has it in the bottom-right. These two states have different parity, so one cannot be turned into the other. Hence, `555-rev` solves the reversed board with the empty tile in the top-left, while `555-reg` has the empty tile in the bottom-right.\n\n### Databases\n\nA database file consists of three parts:\n\n- `p` and `q`: The width and height of the boards that this database solves\n- `n`: The number of patterns in the databases\n- The `n` patterns follow:\n  - Each pattern is a `p` x `q` board filled with numbers. Each tile that is part of the pattern has its number in its position, and the remaining irrelevant tiles have a 0.\n\n### Boards\n\nA board file consists of three parts:\n\n- `p` and `q`: The width and height of the following boards to be solved\n- `n`: The number of boards to solve\n- The `n` boards follow:\n  - Each board is a permutation of `p x q` numbers from 0 to `p x q - 1`. These numbers correspond to the tiles of the board, left-to-right and top-to-down. The blank is represented with a 0.\n\n## Results\n\nAll 8-puzzle boards can be solve in a fraction of a second. The hardest 8-puzzle boards take 31 moves to solve, and even those are solved instantly.\n\n11-puzzle (4x3) boards can be solved relatively quickly, but I haven't tested all of them thoroughly.\n\nMost 15-puzzle can be solved within 5 seconds. Solutions longer than ~55 moves will take significantly longer.\n\nAny larger boards (5x4, 5x5, etc.) with non-trivial solutions will take extremely long to solve.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelkim%2F15puzzle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelkim%2F15puzzle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelkim%2F15puzzle/lists"}