subsection contents

Sliding Tile Puzzle

This is an implementation of the classic "15 Puzzle". The object is to arrange the tiles in order by sliding them around. A timer keeps track of how long it takes to solve the puzzle. See below for notes.

While developing this application I was able to verify that not all initial tile orderings can be solved. In fact, a randomly selected ordering has a 50% probability of being solved. To spare the player unnecessary frustration, I've included a check to ensure only solvable tile orderings are presented. The solvability algorithm is described at Wolfram MathWorld: 15 Puzzle.

Tested with Safari, Firefox and Opera on Mac OS X. According to Browsershots, the page loads and appears to work with Firefox, Chrome, Safari, Opera and Internet Explorer (versions 5.5 to 8.0) on Windows.

Time Elapsed:
Moves:
Status:

Notes

  • The timer starts once the first tile is moved.
  • Only tiles next to the empty space can be moved.
  • A counter keeps track of the number of moves.
  • To complete the puzzle, all tiles must be arranged in increasing order, from left to right then top to bottom. Also, the "Free" space must be in the lower right corner.
  • The player can start a new game at any time by clicking on the "Start New Game" button or reload the page.

Future enhancements

  • Provide a series of pre-set puzzles, with a suggested minimum number of moves to solve them.
  • Keep track of best scores so far.
  • Add an option to change the grid size.

Last updated: April 23, 2009