Taroimo Science Lab日本語

All simulationsMenu

← All simulations

Search Algorithms with the 8-Puzzle

Exaggerated displayPlay

Watch a computer solve the 8-puzzle by searching, examining one board at a time. Compare breadth-first search and A* on the same board and see, in numbers, how a better estimate, called a heuristic, means fewer boards to examine.

Last updated
Update history (1)
  • Improved Switching "Size" back to 3×3 now brings back the 18-move opening board, so you can check the 24,433 versus 154 comparison from the article again.
See all updates →
  • Press "Start search" to run the chosen method one node at a time. Set the speed with the slider; pause and step with the toolbar above.
  • Press "Expand one" to expand a single node, or "Solve at once" to finish the search. When a solution is found, its moves are shown one by one.
  • Tap a tile to slide it toward the blank. Tiles in the same row or column as the blank slide together. Solve it yourself and compare your moves with the shortest solution.
  • "Scramble" makes a board that is always solvable; "Shuffle tiles" makes one that may not be. "Swap two tiles" swaps just two tiles of the current board, which flips whether it can be solved. The inversion count and whether the board is solvable appear under the board.
  • Switching "Size" back to 3×3 brings back the 18-move board you see when the page opens. Switching to 4×4 gives a board scrambled at random from the goal.
  • Press "Compare five methods" to solve the same board with BFS, two kinds of A*, greedy search and A* without a closed set, and line up the nodes expanded, solution length, comparisons and computing time.