PHPackages                             stratadox/puzzle-solver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. stratadox/puzzle-solver

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stratadox/puzzle-solver
=======================

A generic puzzle solving package, capable of solving a wide variety of puzzles.

v0.1.1(5y ago)382MITPHPPHP &gt;=7.2

Since Jan 26Pushed 5y ago2 watchersCompare

[ Source](https://github.com/Stratadox/PuzzleSolver)[ Packagist](https://packagist.org/packages/stratadox/puzzle-solver)[ RSS](/packages/stratadox-puzzle-solver/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Puzzle Solver
=============

[](#puzzle-solver)

[![Github Action](https://github.com/Stratadox/PuzzleSolver/workflows/Github%20Action/badge.svg)](https://github.com/Stratadox/PuzzleSolver/actions)[![codecov](https://camo.githubusercontent.com/a3065254f32935486d9a61151dbe5a8dac2370a83ac217527ccac4fa0ed4ccc5/68747470733a2f2f636f6465636f762e696f2f67682f537472617461646f782f50757a7a6c65536f6c7665722f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/Stratadox/PuzzleSolver)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ec8ab790bba4b9b80168c3a1e37026317db1e63f289a7e1c4c89929513e6534b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f537472617461646f782f50757a7a6c65536f6c7665722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/Stratadox/PuzzleSolver/?branch=main)[![Maintainability](https://camo.githubusercontent.com/969a94fb65301211e122436d28883d5ba006fa76a9d8d453b928149210628b42/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64343364323161323635393166623134636463332f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Stratadox/PuzzleSolver/maintainability)[![Latest Stable Version](https://camo.githubusercontent.com/0af22d905ff2f3c38e5fb8842c083c3d405635c74ae74b20e4444fde6fc0fab1/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70757a7a6c652d736f6c7665722f762f737461626c65)](https://packagist.org/packages/stratadox/puzzle-solver)[![License](https://camo.githubusercontent.com/327f1d0a9936ac8b224087cb03d52e516fc3ca4ee1d859ccb3ad71ac229ad752/68747470733a2f2f706f7365722e707567782e6f72672f737472617461646f782f70757a7a6c652d736f6c7665722f6c6963656e7365)](https://packagist.org/packages/stratadox/puzzle-solver)

A generic puzzle solving package, capable of solving a wide variety of puzzles.

Examples
--------

[](#examples)

Some examples of puzzles it can solve:

- [Mazes](puzzles/Maze.md)
    - [Eagerly solving a maze](tests/Eagerly_solving_a_maze.php)
    - [Eagerly solving a maze, depth first](tests/Eagerly_solving_a_maze_depth_first.php)
    - [Lazily solving a maze, seeking all paths](tests/Lazily_solving_a_maze_seeking_all_paths.php)
- [The Wolf-Goat-Cabbage problem](puzzles/WolfGoatCabbage.md)
    - [Solving a wolf-goat-cabbage puzzle, automatically](tests/Solving_a_wolf_goat_cabbage_puzzle_automatically.php)
    - [Solving a wolf-goat-cabbage puzzle, universally](tests/Solving_a_wolf_goat_cabbage_puzzle_universally.php)
- [Network navigation puzzles](puzzles/NetworkNavigation.md)
    - [Solving network navigation, best first](tests/Solving_network_navigation_best_first.php)
    - [Visually solving network navigation](tests/Visually_solving_network_navigation.php)
- [N-Queens problem](puzzles/NQueens.md)
    - [Solving n-queens puzzles, depth first](tests/Solving_n_queens_puzzles_depth_first.php)
    - [Visualising the n-queens solutions](tests/Visualising_the_n_queens_solutions.php)
- [Sliding Crates puzzle](puzzles/SlidingCrates.md)
    - [Solving sliding crates puzzles, best first](tests/Solving_sliding_crates_puzzles_best_first.php)
- [Sliding Puzzles](puzzles/SlidingPuzzle.md)
    - [Solving "regular" sliding puzzles, best first](tests/Solving_regular_sliding_puzzles_best_first.php)
- [Sudoku puzzles](puzzles/Sudoku.md)
    - [Solving sudoku puzzles, depth first](tests/Solving_sudoku_puzzles_depth_first.php)

Motivation
----------

[](#motivation)

People kept asking me to implement a solver for this puzzle or that puzzle. This time, instead of just solving one puzzle, I figured I'd make a universal puzzle solver that would simply solve **all** of those puzzles and all puzzles to come, in one swift strike. Plus, this way, the algorithms can be re-used for different purposes, such as AI for video games or a solver for some real-life problem. Who knows what the future brings!

Basic usage
-----------

[](#basic-usage)

There are two "ways" to use this package: the Universal Solver, an informed "swiss army knife" approach, or the Brute Solver... what's in a name.

### Universal Solver

[](#universal-solver)

The Universal Solver is like a swiss army knife for puzzle solvers.

Feed it with some information on what you're looking for, and receive a solver for your puzzle. All the puzzles that are implemented as examples, as well as many puzzles that don't have an example implementation, can be given efficient solvers using this approach.

#### 5-queens problem with universal solver

[](#5-queens-problem-with-universal-solver)

Solving a 5-queens problem:

```
