← Back to project summary

Hashi Puzzle Solver

A closer look at what it is, what is in it, and what I built.

What it does

  • Reads a puzzle as a grid of numbers, where 0 is open water and anything higher is an island that needs that many bridges.
  • Finds each island's possible partners in the four directions, then searches for a set of single and double bridges that satisfies every island.
  • Before each move it rejects any bridge that would push an island past its number or cross an existing bridge.
  • Times every puzzle and counts moves, where a move is one bridge placed, single or double.

Measured results

  • Solved every solvable test puzzle: 3x3 in 2 moves, 5x5 in 9, the two 7x7s in 21 and 45, 9x9 in 14, the two 10x10s in 47 and 2,451, 15x15 with 45 islands in 168, and 25x25 with 70 islands in 7,334.
  • Correctly reported no solution for a deliberately unsolvable 10x10, after exhausting the search in 2,111 moves.
  • Every puzzle except the 25x25 finishes in under half a second; the 25x25 takes several seconds.
  • These numbers come from re-running the repo's code with a fresh solver for each puzzle, since the included experiment runner reuses one solver and prints running totals.

What I built

  • The backtracking solver, following the textbook BACKTRACK pseudocode line for line, with the fewest-options-first island choice.
  • The puzzle logic it depends on: finding possible connections, checking that no bridges cross, checking whether a board is solved, and adding and removing bridges on the grid.
  • The eleven test grids, the experiment runner, a test script, and a verbose step-through for tracing the search by hand on a 5x5 example.
  • Ben Smith set up the puzzle and island classes and the abstract solver, and wrote the unfinished constraint-learning solvers.

Known limitations

  • The conflict-driven clause learning solver was never completed, so only one of the two planned algorithms works.
  • The solved check does not enforce Hashi's rule that all islands form one connected group, so it can accept a board that a strict Hashi checker would reject.
  • The experiment runner reuses one solver across puzzles without resetting its move counter, so the move counts it prints are cumulative.