Yeah, I would chain the pieces together. Like, use a variable to signify when a piece is joined with another piece, store the index, sprite number, or whatever of the connected piece. Then make sure that all pieces that are connected have this variable set - the last piece, maybe just the lowest sprite number that is connected, should be connected to itself - so you know whether or not a piece is part of a set when you move a piece.
Then, when you click on a sprite to move it - you continually check the connection, and base the position on that linked sprite. Only allow user movement on sprites that have no set link, or are linked to themselves...
[0][1][2][3]
[4]
So if you had the above pieces, you would set the link variable on 1 to 0, always looking for the lowest sprite index to maintain continuity, avoid loops in your linking data. Anyway, 1 links with 0 instead of 2, and 2 links with 1 instead of 2, and 0 is linked, but has no lower index next to it, so it gets set to 0. Then, when you move sprite 2, you know that it's linked to sprite 1, so position it next to sprite 1. When you move sprite 1, you find that it's linked to sprite 0, so position it accordingly. Then, when you move sprite 0, you see that it is linked, but it's the 'key' link, it has it's link value set to 0, so move that. Then all the resulting checks will make the piece move logically with piece 0, no matter which sprite you are moving.
You never need to break the puzzle apart, so the links can stay permanent. You can always check the link number, then check the solution to see where each sprite should be in relation to it's link. Each time you try a link, you can just check each sprite and see where they should be on the solution. I imagine the solution as a simple 2D grid, an indice for each piece which contains the sprite index that should go there. Once the solution array is setup, randomly position all the sprites, and that's it, job done
- well, apart from a lot of coding. Hopefully you understand what I'm on about - just remember that because you don't break the succesful links, each sprite only really needs to link to 1 other sprite, in a chain, all the way down to the lowest sprite number, which is allowed to move because it isn't linked to anything apart from itself.
Health, Ammo, and bacon and eggs!