Sliding puzzle - shuffling

Hi,
I’m currently trying to create a sliding puzzle like this:

http://play.google.com/store/apps/details?id=com.panagola.game.arrangefree

It’s just a basic 3x3 sliding puzzle with numbers…
I have the mechanism set up, but I need an advice. I want to shuffle the tiles in front of the player. This means, when I load the screen, I want to see the tiles shuffling randomly up and down, left and right…for about 5 seconds.
I created a for cycle with random number generation, which said which row or column and where it will move. And then transition.to() But the code was very chunky and super long. There must be a better way to do this. Would anyone know how to make the shuffling easier? I would be grateful.

Thanks in advance

Im also creating this one…and some point there is some problem is there anybody has sample code how sliding puzzle works perfectly?

Hi, I just ended up doing it the chunky, long way… I set up the tiles to move one at a time with transition.to(), but If someone has better solution, I would be interested too :slight_smile:

Hey vasek,

I would break up the shuffling into two phases.

  1. Phase: Start with the finished grid an shuffle it step by step. Store each step in a table, so you can loop through it later. Start with the free tile and pick one of its neighbours randomly. Store the last moved tile, so you won’t chosse it again in the next. Do this x times to shuffle your board.

  2. Phase: Take the first entry of your array and move the tile with a transition. At the end of the transition move the tile in the second entry of your array etc. Like that you can show the shuffling process step by step.

Hope that hels to give you a starting point.

Greetings Torben :slight_smile:

Im also creating this one…and some point there is some problem is there anybody has sample code how sliding puzzle works perfectly?

Hi, I just ended up doing it the chunky, long way… I set up the tiles to move one at a time with transition.to(), but If someone has better solution, I would be interested too :slight_smile:

Hey vasek,

I would break up the shuffling into two phases.

  1. Phase: Start with the finished grid an shuffle it step by step. Store each step in a table, so you can loop through it later. Start with the free tile and pick one of its neighbours randomly. Store the last moved tile, so you won’t chosse it again in the next. Do this x times to shuffle your board.

  2. Phase: Take the first entry of your array and move the tile with a transition. At the end of the transition move the tile in the second entry of your array etc. Like that you can show the shuffling process step by step.

Hope that hels to give you a starting point.

Greetings Torben :slight_smile: