Puzzle Random
-
Hi guys, I created a 3x3 puzzle game and I randomize the button at form load. It's a success, but sometimes I can't solve the puzzle no matter how hard I try. This is where the puzzle stuck at, http://i39.tinypic.com/9k17dh.jpg[^] Maybe there is a way to random puzzle? Or maybe I don't know how to play puzzle?
-
Hi guys, I created a 3x3 puzzle game and I randomize the button at form load. It's a success, but sometimes I can't solve the puzzle no matter how hard I try. This is where the puzzle stuck at, http://i39.tinypic.com/9k17dh.jpg[^] Maybe there is a way to random puzzle? Or maybe I don't know how to play puzzle?
-
Hi guys, I created a 3x3 puzzle game and I randomize the button at form load. It's a success, but sometimes I can't solve the puzzle no matter how hard I try. This is where the puzzle stuck at, http://i39.tinypic.com/9k17dh.jpg[^] Maybe there is a way to random puzzle? Or maybe I don't know how to play puzzle?
There are a couple of ways to randomise it: 1) Insert each piece of the puzzle at a random location on the board, by using the random number generator to specify the location. This is quick to generate, but as Harold says, it can generate puzzles that can't be solved - you need a post-processing step to ensure that it can. 2) Use the random number generator to generate a direction, and move the pieces that way, exactly as if the user had done so. You then repeat this a number of times to "scramble" the puzzle. This is slower to generate, but the result is always solvable, and it means that a "difficulty level" can be added very simply by changing the number of times the random move is implemented.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
There are a couple of ways to randomise it: 1) Insert each piece of the puzzle at a random location on the board, by using the random number generator to specify the location. This is quick to generate, but as Harold says, it can generate puzzles that can't be solved - you need a post-processing step to ensure that it can. 2) Use the random number generator to generate a direction, and move the pieces that way, exactly as if the user had done so. You then repeat this a number of times to "scramble" the puzzle. This is slower to generate, but the result is always solvable, and it means that a "difficulty level" can be added very simply by changing the number of times the random move is implemented.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
I thought about that second method, but concluded that I couldn't guarantee anything about how random the result would be, so I decided against recommending it. It could be faster though, the way I mentioned has a probability of 0.5 at every step to terminate, you could have bad luck.
-
I thought about that second method, but concluded that I couldn't guarantee anything about how random the result would be, so I decided against recommending it. It could be faster though, the way I mentioned has a probability of 0.5 at every step to terminate, you could have bad luck.
It generally works out pretty random: since at any stage you will have 4, 3, or two possible moves (depending on where the hole is in respect of the edges) it's a pretty simple matter to "ban" the move which reverses the previous one. That does give good randomness in practice - it's down to how many iterations you go for.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
-
It generally works out pretty random: since at any stage you will have 4, 3, or two possible moves (depending on where the hole is in respect of the edges) it's a pretty simple matter to "ban" the move which reverses the previous one. That does give good randomness in practice - it's down to how many iterations you go for.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
I suppose so, but I had to think of that argument for why the "swap any two random elements n times" algorithm doesn't shuffle an array correctly - some configurations have more paths to them than others, so they get chosen too often. I'm not sure that isn't the case here.
-
I suppose so, but I had to think of that argument for why the "swap any two random elements n times" algorithm doesn't shuffle an array correctly - some configurations have more paths to them than others, so they get chosen too often. I'm not sure that isn't the case here.
I was able to solve it using a timer that randomly click the movable button in 5 second and it worked. Thank you very much for the help guys. :laugh: