liukaren / slider-puzzle

15-puzzle solver algorithm

Home Page:https://liukaren.github.io/slider-puzzle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

15-Puzzle Solver

Inspired by and modeled after the 8-puzzle assignment from the (free!) Princeton Algorithms Coursera course. This is an exercise in implementing the concepts, and adding some goofy backgrounds. :)

A 3x3 or 4x4 slider puzzle can be shuffled and solved. The solver can be paused any time by hitting "Stop" during playback. You can also just play the game normally.

The solver uses the A* algorithm to explore possible moves. It uses manhattan distance plus linear conflicts to prioritize moves. Note this implementation is not efficient enough for 5x5 boards.

The shuffler uses the Fisher-Yates shuffle to permute the tiles, then checks whether the board is solvable by counting the number of inversions (using mergesort). If the generated board is not solvable, it swaps two adjacent non-zero tiles to place it in the solvable equivalence class.

Attribution

Development

Production

  • yarn run build
  • yarn run deploy

About

15-puzzle solver algorithm

https://liukaren.github.io/slider-puzzle


Languages

Language:JavaScript 83.9%Language:CSS 13.8%Language:HTML 2.3%