BHT Sliding PuzzleBHT Sliding Puzzle
This is a plugin for Construct 2 by Scirra. Last updated: Jan 25 2016

This plugin provides the algorithm for solving the Sliding/Fifteen Puzzle game.

Introduction

The plugin takes a comma delimited string of the tile arrangement and processes the data to produce a sequence of moves to solve the standard Fifteen Puzzle game. Zero is the blank tile, and then one to fifteen are the valid tile numbers.

The solution produced will be an array of letters indicating the direction that the blank tile should move. Although the user moves a numbered tile, the solving mechanism actually moves the blank, as it is unique to any game. The text label for directions are: L - left, R - right, U - up, D - down.

The recommended mechanism for generating game layouts is to run a movement algorithm to randomly move the tiles in a valid manner. Doing so guarantees that a solution can be found. Just generating random tile arrangements will not work, as all tile arrangements are not solvable by the fifteen puzzle algorithm. Details can be found in the linked wiki page above.

Other grids (3x3), (4x3), (3x4), etc., are possible, but it isn't recommended to go beyond 4x4 as the solving time grows exponentially with each increase in size.

***Does not support the C2 Save/Load mechanism, since the main data is passed in and not stored.

Installing
Drag the C2ADDON file onto the Construct GUI to install the plugin.
Properties
Throttle Iteration Limit
The number of iterations that are run before that algorithm pauses, to remain responsive to other elements.
Throttle Delay
The delay, in ms, that the throttling will pause before continuing the solving algorithm.
Timeout
The algorithm does not attempt to check if the tile arrangement can be solved before trying to solve it. To deal with invalid data, this timeout (in seconds) is used to stop the algorithm from running indefinitely. If the guidelines are followed, this should never be an issue.
Conditions
On solve finished
Triggered when a solution is found.
On solve timeout
Triggered when the algorithm is taking too long to find a solution.
Expressions
Moves
Returns the number of remaining moves in the solution sequence. This value will decrease as the solution moves are popped from the stack.
Next
Returns the next solution direction to move the blank tile: L, R, U, D.
Throttle Iteration Limit
Returns the Throttle Iteration Limit value set via the properties or Set Throttle Iteration Limit action. See properties for details.
Throttle Delay
Returns the Throttle Delay value set via the properties or Set Throttle Delay action. See properties for details.
Timeout
Returns the Timeout value set via the properties or Set Timeout action. See properties for details.
Actions
Sliding Puzzle
Solve
Given an input string of the commas-delimited number sequence of the tiles, start the asynchronous algorithm to solve the puzzle. Either On solve finished will be called when solved, or On solve timeout will be called if the algorithm takes too long. Input example: "6, 13, 2, 4, 0, 3, 11, 7, 1, 10, 5, 8, 14, 9, 15, 12".
Cancel
Cancels the solve algorithm. No triggers will be called, so deal with any cleanup yourself.
Set Throttle Iteration Limit
Sets the Throttle Iteration Limit value. See properties for details.
Set Throttle Delay
Sets the Throttle Delay. See properties for details.
Set Timeout
Sets the Timeout value. See properties for details.
Availability
     BHT Sliding Puzzle - v1.0 is only available through the Scirra Store.