slide-puzzle-solver

1.0.2 • Public • Published

slide-puzzle-solver

Useful tool for https://hack.ainfosec.com/

Solver for slide puzzle.

Note that not every NxN puzzle is solvable. But this solver can solve every solvable puzzle with different sizes in limited time.

More stable than DFS or A-star algorithm, instead of efficient.

Usage

const { solve } = require('slide-puzzle-solver')

// 'X' stands for the empty slot
const puzzle = [
  [1, 4, 3],
  [8, 7, 6],
  [2, 'X', 5],
]
// The solution will be saved here
// Valid moves are 'L', 'R', 'U', 'D' to move the 'X' piece Left, Right, Up, and Down respectively
const steps = []

// Returns the solved puzzle, while the origin `puzzle` will not be changed
const solvedPuzzle = solve(puzzle, steps)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    1
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i slide-puzzle-solver

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

23.2 kB

Total Files

9

Last publish

Collaborators

  • chinesedfan