This project recreates the classic 15-puzzle in Scratch. Click Start to begin playing. You can slide the tiles around with the goal of putting them back in numerical order. You can slide multiple tiles at once. Play for the shortest time or the fewest moves and try to beat the global high score! You can even see the list of highscores that people have set by clicking "cloud data log."
Thanks to Paddle2See for frontpage! CHANGELOG Version 1.01: Made it impossible to set the highscore to 0, even if you somehow managed to beat the game with a time of 0. If you leave the game open for 100 minutes, the time will stop at 99:59. If you left your browser open so long that this happened, just hit Start or Reset. The same applies if you make more than 9999 moves. You can actually play a randomized puzzle here by clicking Start, or you can just mess around with the grid of numbers. If you don't click Start, the time and moves counters will not increment. This is designed to prevent players from moving a tile out and then back into place and solving the puzzle in a very short amount of time - an anti-cheat mechanism which does not exist in the Windows version. Thanks to the Fisher-Yates shuffle for a randomization algorithm that takes an average of only 1.2 seconds, including ensuring proper parity! The best I could come up with myself took about 3.5. Also thanks to stackoverflow.com and cs.princeton.edu for the information that gave me the key to solving the parity problem. One question that is asked of many programmers about their projects is, "What was the hardest thing that you accomplished while doing this project?" To answer it for me would also have the added benefit of explaining the parity problem. Parity is basically whether a number is odd or even. Only half of all the possible combinations of this puzzle are solvable - if you were to randomly drop the tiles in a box and try to solve it, it would only work half of the time. If a puzzle is unsolvable you can get it completely solved except with 14 and 15 flipped, which is known as the Sam Loyd scenario. My difficult task was to detect whether the puzzle was solvable, and if not, try to fix it, without taking a ridiculously long amount of time. After many hours of hunting on the Internet, I found out that the key to a solvable puzzle was that the parity (odd or even) of the position of the blank tile on the board had to be the same as the parity of the number of inversions that took place while the board was being randomized. An inversion (a term which took even more hours of Internet-hunting to define) is apparently defined as a scenario in the list of numbers where one number appears after another number and yet is less than that other number. After devising a script to find the number of inversions in my list of tiles, I found that a typical board randomized with the Fisher-Yates shuffle has 50-70 inversions, and also that the number of inversions is ALWAYS ODD. This meant that if the blank tile was in an odd position, then it was solvable, while if it was in an even position, it was unsolvable. But I solved the puzzle several times and found that the definition of "odd" and "even" was not what you'd expect - that the tiles in positions 2, 4, 6 etc. are even and all the rest are odd. No, the tiles were divided by a checkerboard pattern in which the even tiles were in the checkerboard including the top-left to bottom-right diagonal, and the odd tiles were in the other one. After coming up with a complicated equation to find the parity of the blank tile, I was equipped to find out if a puzzle was solvable or not. Then I had to fix it if it was not solvable, which proved to be less difficult. I had already found out that the parity of the number of inversions was directly associated with the number of swaps performed during the Fisher-Yates shuffle, so all I had to do was make another swap if the parity of the blank tile was different from the parity of the number of inversions. With this done, the parity problem was solved and every problem was solvable. As this was one of the most challenging programming endeavors I have accomplished and it was done entirely in Scratch 1.4, I decided to do a little bit with 2.0 in adding a global highscore feature using cloud variables. This was my first major project to use 2.0 features.