i'm trying to make a slidepuzzle.but i can't figure out an algorithm on how to make blank space move to numberposition and randomnumber-numberposition move to where spaceblank was without messing the number.
i know hot to move blank space up,down,left,right and adjacent number back to blank space but i need a pattern that doesn't mess my order.i can't explain it.
I'm back! I looked over your code, and I don't completely understand it. But, I did find the glitch (In the screen shot). Unfortunately, the way you programed it only works 50% of the time. This is because of the way that slider puzzles work. I'll start looking for a simple solution to this glitch.
I know what that part of the code if for. Anyway, I found a VERY complex algorithm to find if the puzzle can be solved. I'll help you implement it into your program.
Next you will see all of the data for the numbers. The last one is filled with spaces so I don't half to clear the text every time I move a piece. The numbers are simply overwritten with blank spaces.
Next you will find the DIM command. This is used to create arrays. Arrays are simply sets of organized variables. Next you'll find the FOR command this allows you to go through a set of numbers. after the two FOR commands you will find the READ command. this command reads the data up above. finally there is the CX and CY variables. these determine the location of the blank space in the puzzle.
DATA stores information in a stack that you can load into variables or arrays with READ.
This "stack" is basically a list of numbers or strings, data as we will call it.
@SPECIALDATA 'Optional
DATA 12,"LOL",15,16
This is a label, and a data stack assigned to a DATA command.
Optional: Use RESTORE @SPECIALDATA to tell SmileBASIC that you want to READ starting from that label.
Then, you can use READ VARIABLE to assign the first piece of data on the stack, 12, to the variable given to the READ command.
Imagine that the 12 was removed from the list of data.
Next up is "LOL". You will need a string variable to assign this data to. Let's call it STRINGVAR$.
READ STRINGVAR$ will assign such data to the STRINGVAR$ string var.
Note: Not using RESTORE will make the READ command
Next, you'll find @RESET. This represents the reset point. After that there is the GOSSUB command inside the FOR loop. This command goes to the specified label until it finds the RETURN command. Then it heads back. The second FOR command is so set the CX and CY variables back at coordinates (2,2).
Next is the main loop. It starts off with the REPEAT command. This command along with the UNTIL command creates a loop until the specified equation is true. Next there is the CHK variable. this is used to check if the puzzle is solved. Then there is the first FOR command used to find the value of the coordinate. The Second FOR command is used to find the value of the number. Next-
If the values are equal, then the number will be displayed. And the value will be checked to see if it is in it's original location. After that there are the BUTTON commands. these are used to detect if a button was just pressed on that frame. If the value is true then it will goto the specified label and skip the rest of the BUTTON commands.
Next is the VSYNC which is used to slow the program.
Next is the UNTIL command. In this case, it is used to detect when the puzzle is finished. If the value is true then it will continue to the BGMPLAY command whis is used to play music and simple tunes. The WAIT command waits for two seconts, and finally procedes to reset the game. The @M(0-3) are the different moves that can be performed. I'll explain everything you need in greated detail tomorrow
The SWAP command swaps the values of two variables. The CY<2 and CY>0 make sure that the blank space is inside the box after the move. So, if you press right on the D-Pad, it checks to see if the blank space is greater than zero. If the value is true, the it will swap the values of the blank space with the one to the left of it. Then it will move the blank space one to the left with CX=CX-1.
Equations MUST always, no matter what, be equal. Otherwise, they are inequations, which are never equal.
12 = 12
What you mean is a comparison.
Comparisons include both equations and inequations.
They can be true or false.
[12 = 12](12 Equals 12)TRUE
[12 < 13](12 is Less than 13)TRUE
[12 < 12](12 is Less than 12)FALSE
[12 != 13](12 Doesn't equal 13)TRUE
[12 != 12](12 Doesn't equal 12)FALSE