How can I ensure that when I shuffle my puzzle I still end up with an even permutation?

后端 未结 5 1323
北恋
北恋 2021-01-05 14:48

I\'m interested making an implementation of the 14-15 puzzle:

5条回答
  •  耶瑟儿~
    2021-01-05 15:31

    I wouldn't really try altering the algorithm itself, it's probably moot for this application anyway. From what I see there are two options:

    1. Just re-shuffle until you get an even permutation. This would probably throw away half a permutation on average (well, maybe a little more), but the extra work is very likely negligible.
    2. Shuffle the board by using the game's moves itself. That is, just do a few hundred random moves. Since you're not taking all pieces out and re-assembling them you can't generate a state that's impossible to solve.

提交回复
热议问题