15_puzzle_v6

Project Description

This version handles the initiation of the 15 puzzle through cloning and applying the right - premade - costume to each clone.

The positions of all slides are collected into a list called RowList - containing id, row, column, xpos, ypos.

The gap is item 16.

At clicking the neighbours are checked through a double keep items (see nextToGap). If the gap is neighbouring, the swap between the clicked slide and the gap is done. The positions in Rowlist are updated.

The scrambling is done through a list of 16 unique numbers.

IIt has taken a really long time to find the definitive answer as to when a sliding puzzle is solvable and when not. I found the answer in a sliding puzzle assignment from Princeton University. I quote their answers below: 

"Odd-sized boards. First, we’ll consider the case when the board size n is an odd integer. In this case, each move changes the number of inversions by an even number. Thus, if a board has an odd number of inversions, it is unsolvable because the goal board has an even number (zero) of inversions. It turns out that the converse is also true: if a board has an even number of inversions, then it is solvable.In summary, when n is odd, an n-by-n board is solvable if and only if its number of inversions is even."

"Even-sized boards. Now, we’ll consider the case when the board size n is an even integer. In this case, the parity of the number of inversions is not invariant. However, the parity of the number of inversions plus the row of the blank square (indexed starting at 0) is invariant: each move changes this sum by an even number.
That is, when n is even, an n-by-n board is solvable if and only if the number of inversions plus the row of the blank square is odd."

N.B. the row of the blank square is counted from the top, index starting at 0

Created September 2, 2025

Last updated September 3, 2025

Published September 2, 2025