Nine puzzle solvers, one browser tab, zero servers: a tour of classic search algorithms
I recently finished building a small suite of puzzle and game solvers that all run entirely in the browser — no backend, no API calls, no machine-learning models. You paste in a Sudoku, a chess position, or a crossword pattern, and the answer comes back instantly, computed on your own device. The fun part wasn't the UI. It was that each puzzle turned out to be a textbook excuse to reach for a…
Nine puzzle solvers exist in a single browser tab, running without any servers. These solvers showcase classic algorithms, such as constraint propagation, adversarial search, heuristic search, brute-force scanning, and pattern matching.
The first group consists of constraint propagation algorithms, which include solving Sudoku puzzles. In Sudoku, a single value can force other cells' values, gradually narrowing down the options. This method works for easy and medium boards (naked and hidden singles), but harder puzzles may require a backtracking search. The same engine used to solve the board can also provide hints and verify the uniqueness of a puzzle.
The second group is adversarial search, encompassing minimax, negamax, and alpha–beta pruning techniques. This algorithm is used for two-player games, such as Minesweeper, Connect 4, and Chess. In Minesweeper, each revealed number constrains the hidden mines, allowing the solver to deduce safe and mine cells with exact probabilities.
Connect 4 employs the same algorithm, but representation is crucial due to the larger game tree. By using bitboards and bit shifts, win detection becomes faster. In Chess, negamax with alpha–beta pruning and a hand-written evaluation function allows the solver to reach a club-level performance.
The third group revolves around heuristic and shortest-path search algorithms. For mazes, breadth-first search (BFS) is the ideal shortest-path algorithm. BFS explores the grid in rings outward from the start, ensuring the first time it reaches the goal, it's done through the shortest route.
The final group focuses on the 15-puzzle, where plain BFS would be impractical due to the enormous state space. Iterative-deepening A* (IDA*) with an admissible heuristic, specifically Manhattan distance and linear-conflict, solves the 15-puzzle. Adjusting the heuristic to a weighted IDA* balances optimality and speed, delivering near-optimal solutions for hard scrambles in milliseconds.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.