aboutsummaryrefslogtreecommitdiff
path: root/src/coordinates.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 21:37:34 +0100
commit3568412f8f230774d0d11d7ed1c897424f95d3ef (patch)
tree77223792d8c925a9b1fc32b3f4341e943b5f8209 /src/coordinates.c
parent67e1b5e6e6a2c917a2fe58a37a1382c982b1e5c5 (diff)
downloadnissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.tar.gz
nissy-3568412f8f230774d0d11d7ed1c897424f95d3ef.zip
Rewritten from scratch. Welocme nissy 2.0!
Diffstat (limited to 'src/coordinates.c')
-rw-r--r--src/coordinates.c286
1 files changed, 0 insertions, 286 deletions
diff --git a/src/coordinates.c b/src/coordinates.c
deleted file mode 100644
index be61698..0000000
--- a/src/coordinates.c
+++ /dev/null
@@ -1,286 +0,0 @@
1#include <stdio.h>
2
3#include "utils.h"
4#include "coordinates.h"
5
6/* Names of pieces and moves. */
7char edge_string_list[12][5] = {
8 "UF", "UL", "UB", "UR", "DF", "DL", "DB", "DR", "FR", "FL", "BL", "BR"
9};
10
11char corner_string_list[8][5] = {
12 "UFR", "UFL", "UBL", "UBR", "DFR", "DFL", "DBL", "DBR"
13};
14
15char move_string_list[19][5] = {
16 "-",
17 "U", "U2", "U\'", "D", "D2", "D\'", "R", "R2", "R\'",
18 "L", "L2", "L\'", "F", "F2", "F\'", "B", "B2", "B\'"
19};
20
21int inverse_move[19] = {
22 -1, U3, U2, U, D3, D2, D, R3, R2, R, L3, L2, L, F3, F2, F, B3, B2, B
23};
24
25/* Convert piece representation from integer to array.
26 * Come convertions are not "perfect": for example, and epud type of piece
27 * is represented by a permutation index in 8! elements, but it as an array
28 * it is converted to the first 8 elements of a 12 elements ep array (with
29 * meaningless values for the other 4 elements). */
30
31void ep_int_to_array(int ep, int a[12]) {
32 index_to_perm(ep, 12, a);
33}
34
35void epud_int_to_array(int epud, int a[12]) {
36 index_to_perm(epud, 8, a); /* Last 4 elements are left untouched. */
37}
38
39void epfb_int_to_array(int epfb, int a[12]) {
40 int edges[] = {UF, UB, DF, DB, FR, FL, BL, BR};
41 int b[8];
42 index_to_perm(epfb, 8, b);
43 for (int i = 0; i < 8; i++)
44 a[edges[i]] = edges[b[i]];
45}
46
47void eprl_int_to_array(int eprl, int a[12]) {
48 int edges[] = {UL, UR, DL, DR, FR, FL, BL, BR};
49 int b[8];
50 index_to_perm(eprl, 8, b);
51 for (int i = 0; i < 8; i++)
52 a[edges[i]] = edges[b[i]];
53}
54
55void epose_int_to_array(int epos, int a[12]) {
56 int edges[] = {FR, FL, BL, BR};
57 index_to_subset(epos, 12, 4, a);
58 for (int i = 0, j = 0; i < 12; i++)
59 a[i] = (a[i] == 1) ? edges[j++] : -1;
60}
61
62void eposs_int_to_array(int epos, int a[12]) {
63 int edges[] = {UL, UR, DL, DR};
64 index_to_subset(epos, 12, 4, a);
65 for (int i = 0, j = 0; i < 12; i++)
66 a[i] = (a[i] == 1) ? edges[j++] : -1;
67 /* Swap with last 4, so 0 is alway solved state */
68 for (int i = 0; i < 4; i++)
69 swap(&a[edges[i]], &a[i+8]);
70}
71
72void eposm_int_to_array(int epos, int a[12]) {
73 int edges[] = {UF, UB, DF, DB};
74 index_to_subset(epos, 12, 4, a);
75 for (int i = 0, j = 0; i < 12; i++)
76 a[i] = (a[i] == 1) ? edges[j++] : -1;
77 /* Swap with last 4, so 0 is alway solved state */
78 for (int i = 0; i < 4; i++)
79 swap(&a[edges[i]], &a[i+8]);
80}
81
82void epe_int_to_array(int epe, int a[12]) {
83 index_to_perm(epe, 4, a+8);
84 for (int i = 0; i < 4; i++)
85 a[i+8] += 8;
86}
87
88void eps_int_to_array(int eps, int a[12]) {
89 int edges[] = {UL, UR, DL, DR};
90 int b[4];
91 index_to_perm(eps, 4, b);
92 for (int i = 0; i < 4; i++)
93 a[edges[i]] = edges[b[i]];
94}
95
96void epm_int_to_array(int epm, int a[12]) {
97 int edges[] = {UF, UB, DF, DB};
98 int b[4];
99 index_to_perm(epm, 4, b);
100 for (int i = 0; i < 4; i++)
101 a[edges[i]] = edges[b[i]];
102}
103
104void emslices_int_to_array(int emslices, int a[12]) {
105 int b[] = {0,0,0,0,0,0,0,0};
106 int eslice[] = {FR, FL, BL, BR};
107 int mslice[] = {UF, UB, DF, DB};
108
109 index_to_subset(emslices % binom12on4, 12, 4, a);
110 index_to_subset(emslices / binom12on4, 8, 4, b);
111
112 if (emslices % binom12on4 == 0) {
113 swap(&b[UF], &b[DL]);
114 swap(&b[UB], &b[DR]);
115 /*for (int i = 0; i < 4; i++)
116 swap(&b[mslice[i]], &b[i+4]);*/
117 }
118
119 for (int i = 0, j = 0; j < 8; i++, j++) {
120 while (a[i])
121 i++;
122 a[i] = b[j] ? 2 : -1;
123 }
124 for (int i = 0, j1 = 0, j2 = 0; i < 12; i++) {
125 if (a[i] == 1)
126 a[i] = eslice[j1++];
127 if (a[i] == 2)
128 a[i] = mslice[j2++];
129 }
130}
131
132void cp_int_to_array(int cp, int a[8]) {
133 index_to_perm(cp, 8, a);
134}
135
136void eo_11bits_to_array(int eo, int a[12]) {
137 int_to_sum_zero_array(eo, 2, 12, a);
138}
139
140void co_7trits_to_array(int co, int a[8]) {
141 int_to_sum_zero_array(co, 3, 8, a);
142}
143
144
145
146
147
148int ep_array_to_int(int ep[12]) {
149 return perm_to_index(ep, 12);
150}
151
152int epud_array_to_int(int ep[12]) {
153 return perm_to_index(ep, 8); /* Last 4 elements are ignored */
154}
155
156int epfb_array_to_int(int ep[12]) {
157 int index[] = {0, -1, 1, -1, 2, -1, 3, -1, 4, 5, 6, 7};
158 int b[8];
159 for (int i = 0; i < 12; i++)
160 if (index[i] != -1)
161 b[index[i]] = index[ep[i]];
162 return perm_to_index(b, 8);
163}
164
165int eprl_array_to_int(int ep[12]) {
166 int index[] = {-1, 0, -1, 1, -1, 2, -1, 3, 4, 5, 6, 7};
167 int b[8];
168 for (int i = 0; i < 12; i++)
169 if (index[i] != -1)
170 b[index[i]] = index[ep[i]];
171 return perm_to_index(b, 8);
172}
173
174int epose_array_to_int(int ep[12]) {
175 int a[12];
176 for (int i = 0; i < 12; i++)
177 a[i] = (ep[i] >= FR);
178 return subset_to_index(a, 12, 4);
179}
180
181int eposs_array_to_int(int ep[12]) {
182 int a[12];
183 int edges[] = {UL, UR, DL, DR};
184 for (int i = 0; i < 12; i++)
185 a[i] = (ep[i] == UL || ep[i] == UR || ep[i] == DL || ep[i] == DR);
186 /* Swap with last 4, so 0 is alway solved state */
187 for (int i = 0; i < 4; i++)
188 swap(&a[edges[i]], &a[i+8]);
189 return subset_to_index(a, 12, 4);
190}
191
192int eposm_array_to_int(int ep[12]) {
193 int a[12];
194 int edges[] = {UF, UB, DF, DB};
195 for (int i = 0; i < 12; i++)
196 a[i] = (ep[i] == UF || ep[i] == UB || ep[i] == DF || ep[i] == DB);
197 /* Swap with last 4, so 0 is alway solved state */
198 for (int i = 0; i < 4; i++)
199 swap(&a[edges[i]], &a[i+8]);
200 return subset_to_index(a, 12, 4);
201}
202
203int epe_array_to_int(int ep[12]) {
204 int b[4];
205 for (int i = 0; i < 4; i++)
206 b[i] = ep[i+8] - 8;
207 return perm_to_index(b, 4);
208}
209
210int eps_array_to_int(int ep[12]) {
211 int index[] = {-1, 0, -1, 1, -1, 2, -1, 3, -1, -1, -1, -1};
212 int b[4];
213 for (int i = 0; i < 12; i++)
214 if (index[i] != -1)
215 b[index[i]] = index[ep[i]];
216 return perm_to_index(b, 4);
217}
218
219int epm_array_to_int(int ep[12]) {
220 int index[] = {0, -1, 1, -1, 2, -1, 3, -1, -1, -1, -1, -1};
221 int b[4];
222 for (int i = 0; i < 12; i++)
223 if (index[i] != -1)
224 b[index[i]] = index[ep[i]];
225 return perm_to_index(b, 4);
226}
227
228int emslices_array_to_int(int ep[12]) {
229 int a[12], b[12], c[8] = {0, 0, 0, 0, 0, 0, 0, 0};
230 /*int edges[] = {UF, UB, DF, DB};*/
231 for (int i = 0; i < 12; i++) {
232 a[i] = (ep[i] >= FR) ? 1 : 0;
233 b[i] = (ep[i] == UF || ep[i] == UB || ep[i] == DF || ep[i] == DB) ? 1 : 0;
234 }
235
236 /*for ( int i = 0; i < 12; i++)
237 printf("%d ", ep[i]);
238 printf("\n");*/
239
240 for (int i = 0, j = 0; i < 12; i++, j++) {
241 if (a[i])
242 j--;
243 if (b[i])
244 c[j] = 1;
245 }
246
247 int epose = subset_to_index(a, 12, 4);
248
249 /*if (epose == 0) {
250 printf("Before: ");
251 for (int i = 0; i < 8; i++)
252 printf("%d ", c[i]);
253 printf("\n");
254 for (int i = 0; i < 4; i++)
255 swap(&c[edges[i]], &c[i+4]);
256 printf("After: ");
257 for (int i = 0; i < 8; i++)
258 printf("%d ", c[i]);
259 printf("\n");
260 }*/
261 if (epose == 0) {
262 swap(&c[UF], &c[DL]);
263 swap(&c[UB], &c[DR]);
264 }
265
266 /*for ( int i = 0; i < 8; i++)
267 printf("%d ", c[i]);
268 printf("\n");*/
269 int eposm = subset_to_index(c, 8, 4);
270
271 return epose + 495*eposm;
272}
273
274
275int cp_array_to_int(int cp[8]) {
276 return perm_to_index(cp, 8);
277}
278
279int eo_array_to_11bits(int a[12]) {
280 return digit_array_to_int(a, 11, 2);
281}
282
283int co_array_to_7trits(int a[8]) {
284 return digit_array_to_int(a, 7, 3);
285}
286

Generated with cgit - Back to sebastiano.tronto.net