复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163#include <iostream>= using namespace std; const int nGridCount = 8; int s_color[nGridCount][nGridCount] = { 34, 92, 26, 34, 93, 10, 34, 39, 10, 10, 34, 39, 15, 15, 39, 93, 15, 26, 26, 93, 93, 39, 10, 15, 26, 34, 39, 15, 39, 34, 34, 26, 34, 39, 39, 34, 52, 26, 10, 10, 26, 34, 10, 15, 52, 52, 15, 39, 93, 15, 26, 26, 15, 39, 93, 93, 34, 52, 93, 10, 93, 10, 39, 26 }; #define OUTPUT_PAIR(x1, y1, x2, y2) printf("(%d, %d), (%d, %d)n", x1, y1, x2, y2); printf("%d %dn", s_color[x1][y1], s_color[x2][y2]) int main() { // 横向地检查一遍 for (int i = 0; i < nGridCount; i++) { for (int j = 0; j < nGridCount - 1; j++) { // xx | x | xx | x | x xx | xx x // x | xx | x | xx | | 这些情况的处理 if ( s_color[i][j] == s_color[i][j+1]) { // ? // xx 检查后端这两个点 // ? if (i - 1 >= 0 && j + 2 < nGridCount && s_color[i-1][j+2] == s_color[i][j]) { OUTPUT_PAIR(i, j+2, i-1, j+2); } if (i + 1 < nGridCount && j + 2 < nGridCount && s_color[i+1][j+2] == s_color[i][j]) { OUTPUT_PAIR(i, j+2, i+1, j+2); } // ? // xx 检查前端这两个点 // ? if (i - 1 >= 0 && j - 1 >= 0 && s_color[i-1][j-1] == s_color[i][j]) { OUTPUT_PAIR(i, j-1, i-1, j-1); } if (i + 1 < nGridCount && j - 1 >= 0 && s_color[i+1][j-1] == s_color[i][j]) { OUTPUT_PAIR(i, j-1, i+1, j-1); } // ? xx ? 检查这两个点 if (j - 2 >= 0 && s_color[i][j-2] == s_color[i][j]) { OUTPUT_PAIR(i, j-2, i, j-1); } if (j + 3 < nGridCount && s_color[i][j+3] == s_color[i][j]) { OUTPUT_PAIR(i, j+3, i, j+2); } } } // x x | x // x | x x 这些情况的处理 for (int j = 0; j < nGridCount - 2; j++) { if (s_color[i][j] == s_color[i][j+2]) { if (i - 1 >= 0 && s_color[i][j] == s_color[i-1][j+1]) { OUTPUT_PAIR(i, j+1, i-1, j+1); } if (i + 1 < nGridCount && s_color[i][j] == s_color[i+1][j+1]) { OUTPUT_PAIR(i, j+1, i+1, j+1); } } } } puts("- - - - - - - - - - "); // 再纵向地看一遍 for (int j = 0; j < nGridCount; j++) { for (int i = 0; i < nGridCount - 1; i++) { // x | x | x | x // x | x | x | x 这些情况的处理 // x | x | x | x if ( s_color[i][j] == s_color[i+1][j]) { // x // x 检查后端这两个点 // ? ? if (j - 1 >= 0 && i + 2 < nGridCount && s_color[i+2][j-1] == s_color[i][j]) { OUTPUT_PAIR(i+2, j, i+2, j-1); } if (j + 1 < nGridCount && i + 2 < nGridCount && s_color[i+2][j+1] == s_color[i][j]) { OUTPUT_PAIR(i+2, j, i+2, j+1); } // ? ? // x 检查前端这两个点 // x if (j - 1 >= 0 && i - 1 >= 0 && s_color[i-1][j-1] == s_color[i][j]) { OUTPUT_PAIR(i-1, j, i-1, j-1); } if (j + 1 < nGridCount && i - 1 >= 0 && s_color[i-1][j+1] == s_color[i][j]) { OUTPUT_PAIR(i-1, j, i-1, j+1); } // ? xx ? 检查这两个点 if (i - 2 >= 0 && s_color[i-2][j] == s_color[i][j]) { OUTPUT_PAIR(i-2, j, i-1, j); } if (i + 3 < nGridCount && s_color[i+3][j] == s_color[i][j]) { OUTPUT_PAIR(i+3, j, i+2, j); } } } // x | x // x | x 这些情况的处理 // x | x for (int i = 0; i < nGridCount - 2; i++) { if (s_color[i][j] == s_color[i+2][j]) { if (j - 1 >= 0 && s_color[i][j] == s_color[i+1][j-1]) { OUTPUT_PAIR(i+1, j, i+1, j-1); } if (j + 1 < nGridCount && s_color[i][j] == s_color[i+1][j+1]) { OUTPUT_PAIR(i+1, j, i+1, j+1); } } } } cin >> ws; }
最后
以上就是爱笑乌龟最近收集整理的关于对对碰(宝石迷阵 Bejeweled)游戏求解算法的全部内容,更多相关对对碰(宝石迷阵内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复