Phaser滑动拼图随机排序问题

时间:2018-02-04 02:43:58

标签: phaser-framework

我使用移相器滑动拼图算法,但我注意到随机排序有时会排除无法解决的难题。

有人解释如下

Difficult to solve the phaser sliding puzzle as some parts of the original image is missing

但我不明白[5,3,4,2,6,1,8,7,9]是如何得到的 5-3,5-4,5-2,5-1,3-2 3-1,4-2 4-1,2-1,6-1,8-7

我注意到如果我有这个组合3x3工作 [8,6,0,2,3,5,4,7,1]。

1 个答案:

答案 0 :(得分:0)

这又是我;)我的意思是较高值图块之前(在数组中;在左侧)较低值图块的次数。因此,在较低的数字之前计算所有较大数字的对。

为了使这个算法起作用,重要的是根据拼图的目标解决方案计算间隙拼贴(空拼贴)。因此,如果间隙/孔砖应该在末尾(右下角),那么它应该是最高的数字。我怀疑您使用的是这个空图块的错误编号,您使用的是0而不是9吗?这取决于目标布局是什么。

Goal layout:
Correct   Incorrect
0 1 2     1 2 3
3 4 5     4 5 6
6 7 8     7 8 0

如果空白区块必须在最后处理以解决难题,那么您应将其计为最高编号区块,例如9。 从你的例子中我可以假设0是最后必须去的区块,所以最后一个位置在数组中。那你的例子应该是这样的:

array = [8,6,9,2,3,5,4,7,1]

Count all pairs=
1: 8 is before 6
2: 8 is before 2
3: 8 is before 3
4: 8 is before 5
5: 8 is before 4
6: 8 is before 7
7: 8 is before 1
8: 6 is before 2
9: 6 is before 3
10: 6 is before 5
11: 6 is before 4
12: 6 is before 1
13: 9 is before 2
14: 9 is before 3
15: 9 is before 5
16: 9 is before 4
17: 9 is before 7
18: 9 is before 1
19: 2 is before 1
20: 3 is before 1
21: 5 is before 4
22: 5 is before 1
23: 4 is before 1
24: 7 is before 1

总共需要24次倒置,24次甚至是可以解决的。