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

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

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

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

    Fisher-Yates depends on the ability to swap any element with any other element. Since this violates the physics of the puzzle, I don't think you can use it here.

    The naive solution is to do what you would do manually, randomly select one of the tiles adjacent to the empty one and swap with it. I don't know how many swaps you'd need to do to get a good shuffle.

提交回复
热议问题