aboutsummaryrefslogtreecommitdiff
path: root/old/2021-05-26-before-restyle/moves.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 22:05:00 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-11 22:05:00 +0100
commit4fb67201414169a2687f41c4056b2e284b4938cb (patch)
treea68246e3e21435229541f83f485ab41cfb2ba08a /old/2021-05-26-before-restyle/moves.c
parent3568412f8f230774d0d11d7ed1c897424f95d3ef (diff)
downloadnissy-4fb67201414169a2687f41c4056b2e284b4938cb.tar.gz
nissy-4fb67201414169a2687f41c4056b2e284b4938cb.zip
Removed old files
Diffstat (limited to '')
-rw-r--r--old/2021-05-26-before-restyle/moves.c412
1 files changed, 0 insertions, 412 deletions
diff --git a/old/2021-05-26-before-restyle/moves.c b/old/2021-05-26-before-restyle/moves.c
deleted file mode 100644
index 15f0238..0000000
--- a/old/2021-05-26-before-restyle/moves.c
+++ /dev/null
@@ -1,412 +0,0 @@
1#include "moves.h"
2
3Cube apply_move_cubearray(Move m, Cube cube, PieceFilter f);
4/* void sort_cancel_rotate(NissMove *alg, int n, bool inv, int top, int front); */
5bool read_ttables_file();
6bool write_ttables_file();
7
8/* Transition tables */
9uint16_t epose_ttable[NMOVES][factorial12/factorial8];
10uint16_t eposs_ttable[NMOVES][factorial12/factorial8];
11uint16_t eposm_ttable[NMOVES][factorial12/factorial8];
12uint16_t eofb_ttable[NMOVES][pow2to11];
13uint16_t eorl_ttable[NMOVES][pow2to11];
14uint16_t eoud_ttable[NMOVES][pow2to11];
15uint16_t cp_ttable[NMOVES][factorial8];
16uint16_t coud_ttable[NMOVES][pow3to7];
17uint16_t cofb_ttable[NMOVES][pow3to7];
18uint16_t corl_ttable[NMOVES][pow3to7];
19uint16_t cpos_ttable[NMOVES][factorial6];
20
21bool commute[NMOVES][NMOVES];
22bool possible_next[NMOVES][NMOVES][NMOVES];
23Move inverse[NMOVES];
24NissMove rotation_algs[24][3] = {
25 { { .m = NULLMOVE }, { .m = NULLMOVE }, { .m = NULLMOVE } },
26 { { .m = y }, { .m = NULLMOVE }, { .m = NULLMOVE } },
27 { { .m = y2 }, { .m = NULLMOVE }, { .m = NULLMOVE } },
28 { { .m = y3 }, { .m = NULLMOVE }, { .m = NULLMOVE } },
29 { { .m = z2 }, { .m = NULLMOVE }, { .m = NULLMOVE } },
30 { { .m = y }, { .m = z2 }, { .m = NULLMOVE } },
31 { { .m = x2 }, { .m = NULLMOVE }, { .m = NULLMOVE } },
32 { { .m = y3 }, { .m = z2 }, { .m = NULLMOVE } },
33 { { .m = z3 }, { .m = NULLMOVE }, { .m = NULLMOVE } },
34 { { .m = z3 }, { .m = y }, { .m = NULLMOVE } },
35 { { .m = z3 }, { .m = y2 }, { .m = NULLMOVE } },
36 { { .m = z3 }, { .m = y3 }, { .m = NULLMOVE } },
37 { { .m = z }, { .m = NULLMOVE }, { .m = NULLMOVE } },
38 { { .m = z }, { .m = y3 }, { .m = NULLMOVE } },
39 { { .m = z }, { .m = y2 }, { .m = NULLMOVE } },
40 { { .m = z }, { .m = y }, { .m = NULLMOVE } },
41 { { .m = x }, { .m = y2 }, { .m = NULLMOVE } },
42 { { .m = x }, { .m = y }, { .m = NULLMOVE } },
43 { { .m = x }, { .m = NULLMOVE }, { .m = NULLMOVE } },
44 { { .m = x }, { .m = y3 }, { .m = NULLMOVE } },
45 { { .m = x3 }, { .m = NULLMOVE }, { .m = NULLMOVE } },
46 { { .m = x3 }, { .m = y }, { .m = NULLMOVE } },
47 { { .m = x3 }, { .m = y2 }, { .m = NULLMOVE } },
48 { { .m = x3 }, { .m = y3 }, { .m = NULLMOVE } },
49};
50
51char move_string[NMOVES][5] =
52 { "-",
53 "U", "U2", "U\'", "D", "D2", "D\'", "R", "R2", "R\'",
54 "L", "L2", "L\'", "F", "F2", "F\'", "B", "B2", "B\'",
55 "Uw", "Uw2", "Uw\'", "Dw", "Dw2", "Dw\'", "Rw", "Rw2", "Rw\'",
56 "Lw", "Lw2", "Lw\'", "Fw", "Fw2", "Fw\'", "Bw", "Bw2", "Bw\'",
57 "M", "M2", "M\'", "S", "S2", "S\'", "E", "E2", "E\'",
58 "x", "x2", "x\'", "y", "y2", "y\'", "z", "z2", "z\'" };
59
60/* For each type of pieces only the effects of U, x and y are described */
61int edge_cycle[NMOVES][12] =
62 { [U] = {UR, UF, UL, UB, DF, DL, DB, DR, FR, FL, BL, BR},
63 [x] = {DF, FL, UF, FR, DB, BL, UB, BR, DR, DL, UL, UR},
64 [y] = {UR, UF, UL, UB, DR, DF, DL, DB, BR, FR, FL, BL} };
65int eofb_flipped[NMOVES][12] =
66 { [x] = { [UF] = 1, [UB] = 1, [DF] = 1, [DB] = 1 },
67 [y] = { [FR] = 1, [FL] = 1, [BL] = 1, [BR] = 1 } };
68int eorl_flipped[NMOVES][12] =
69 { [x] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
70 [y] = { [FR] = 1, [FL] = 1, [BL] = 1, [BR] = 1 } };
71int eoud_flipped[NMOVES][12] =
72 { [U] = { [UF] = 1, [UL] = 1, [UB] = 1, [UR] = 1 },
73 [x] = { [UF] = 1, [UB] = 1, [DF] = 1, [DB] = 1 },
74 [y] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
75int corner_cycle[NMOVES][8] =
76 { [U] = {UBR, UFR, UFL, UBL, DFR, DFL, DBL, DBR},
77 [x] = {DFR, DFL, UFL, UFR, DBR, DBL, UBL, UBR},
78 [y] = {UBR, UFR, UFL, UBL, DBR, DFR, DFL, DBL} };
79int coud_flipped[NMOVES][8] =
80 { [x] = {[UFR]=2,[UBR]=1,[DBR]=2,[DFR]=1,[UFL]=1,[UBL]=2,[DBL]=1,[DFL]=2} };
81int corl_flipped[NMOVES][8] =
82 { [U] = { [UFR] = 1, [UBR] = 2, [UBL] = 1, [UFL] = 2 },
83 [y] = {[UFR]=1,[UBR]=2,[UBL]=1,[UFL]=2,[DFR]=2,[DBR]=1,[DBL]=2,[DFL]=1} };
84int cofb_flipped[NMOVES][8] =
85 { [U] = { [UFR] = 2, [UBR] = 1, [UBL] = 2, [UFL] = 1 },
86 [x] = {[UFR]=1,[UBR]=2,[DFR]=2,[DBR]=1,[UBL]=1,[UFL]=2,[DBL]=2,[DFL]=1},
87 [y] = {[UFR]=2,[UBR]=1,[UBL]=2,[UFL]=1,[DFR]=1,[DBR]=2,[DBL]=1,[DFL]=2} };
88int center_cycle[NMOVES][6] =
89 { [x] = {F_center, B_center, R_center, L_center, D_center, U_center},
90 [y] = {U_center, D_center, B_center, F_center, R_center, L_center} };
91
92/* Each move is reduced to a combination of U, x and y using this table */
93Move equiv_moves[NMOVES][14] = {
94 [U] = { U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
95 [U2] = { U, U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
96 [U3] = { U, U, U, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
97 [D] = { x, x, U, x, x, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
98 [D2] = { x, x, U, U, x, x, 0, 0, 0, 0, 0, 0, 0, 0 },
99 [D3] = { x, x, U, U, U, x, x, 0, 0, 0, 0, 0, 0, 0 },
100 [R] = { y, x, U, x, x, x, y, y, y, 0, 0, 0, 0, 0 },
101 [R2] = { y, x, U, U, x, x, x, y, y, y, 0, 0, 0, 0 },
102 [R3] = { y, x, U, U, U, x, x, x, y, y, y, 0, 0, 0 },
103 [L] = { y, y, y, x, U, x, x, x, y, 0, 0, 0, 0, 0 },
104 [L2] = { y, y, y, x, U, U, x, x, x, y, 0, 0, 0, 0 },
105 [L3] = { y, y, y, x, U, U, U, x, x, x, y, 0, 0, 0 },
106 [F] = { x, U, x, x, x, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
107 [F2] = { x, U, U, x, x, x, 0, 0, 0, 0, 0, 0, 0, 0 },
108 [F3] = { x, U, U, U, x, x, x, 0, 0, 0, 0, 0, 0, 0 },
109 [B] = { x, x, x, U, x, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
110 [B2] = { x, x, x, U, U, x, 0, 0, 0, 0, 0, 0, 0, 0 },
111 [B3] = { x, x, x, U, U, U, x, 0, 0, 0, 0, 0, 0, 0 },
112
113 [Uw] = { x, x, U, x, x, y, 0, 0, 0, 0, 0, 0, 0, 0 },
114 [Uw2] = { x, x, U, U, x, x, y, y, 0, 0, 0, 0, 0, 0 },
115 [Uw3] = { x, x, U, U, U, x, x, y, y, y, 0, 0, 0, 0 },
116 [Dw] = { U, y, y, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
117 [Dw2] = { U, U, y, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
118 [Dw3] = { U, U, U, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
119 [Rw] = { y, y, y, x, U, x, x, x, y, x, 0, 0, 0, 0 },
120 [Rw2] = { y, y, y, x, U, U, x, x, x, y, x, x, 0, 0 },
121 [Rw3] = { y, y, y, x, U, U, U, y, x, x, x, y, 0, 0 },
122 [Lw] = { y, x, U, x, x, x, y, y, y, x, x, x, 0, 0 },
123 [Lw2] = { y, x, U, U, x, x, x, y, y, y, x, x, 0, 0 },
124 [Lw3] = { y, x, U, U, U, x, x, x, y, y, y, x, 0, 0 },
125 [Fw] = { x, x, x, U, y, y, y, x, 0, 0, 0, 0, 0, 0 },
126 [Fw2] = { x, x, x, U, U, y, y, x, 0, 0, 0, 0, 0, 0 },
127 [Fw3] = { x, x, x, U, U, U, y, x, 0, 0, 0, 0, 0, 0 },
128 [Bw] = { x, U, y, y, y, x, x, x, 0, 0, 0, 0, 0, 0 },
129 [Bw2] = { x, U, U, y, y, x, x, x, 0, 0, 0, 0, 0, 0 },
130 [Bw3] = { x, U, U, U, y, x, x, x, 0, 0, 0, 0, 0, 0 },
131
132 [M] = { y, x, U, x, x, U, U, U, y, x, y, y, y, 0 },
133 [M2] = { y, x, U, U, x, x, U, U, x, x, x, y, 0, 0 },
134 [M3] = { y, x, U, U, U, x, x, U, y, x, x, x, y, 0 },
135 [S] = { x, U, U, U, x, x, U, y, y, y, x, 0, 0, 0 },
136 [S2] = { x, U, U, x, x, U, U, y, y, x, 0, 0, 0, 0 },
137 [S3] = { x, U, x, x, U, U, U, y, x, 0, 0, 0, 0, 0 },
138 [E] = { U, x, x, U, U, U, x, x, y, y, y, 0, 0, 0 },
139 [E2] = { U, U, x, x, U, U, x, x, y, y, 0, 0, 0, 0 },
140 [E3] = { U, U, U, x, x, U, x, x, y, 0, 0, 0, 0, 0 },
141
142 [x] = { x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
143 [x2] = { x, x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
144 [x3] = { x, x, x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
145 [y] = { y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
146 [y2] = { y, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
147 [y3] = { y, y, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
148 [z] = { y, y, y, x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
149 [z2] = { y, y, x, x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
150 [z3] = { y, x, y, y, y, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
151};
152
153/* Movesets */
154bool standard_moveset[NMOVES] = {
155 [U] = true, [U2] = true, [U3] = true, [D] = true, [D2] = true, [D3] = true,
156 [R] = true, [R2] = true, [R3] = true, [L] = true, [L2] = true, [L3] = true,
157 [F] = true, [F2] = true, [F3] = true, [B] = true, [B2] = true, [B3] = true,
158};
159
160bool is_solved_up_to_reorient(Cube cube) {
161 for (int i = 0; i < 25; i++)
162 if (is_solved(apply_alg(rotation_algs[i], cube)))
163 return true;
164 return false;
165}
166
167Cube apply_move_cubearray(Move m, Cube cube, PieceFilter f) {
168 return move_via_arrays((CubeArray)
169 { edge_cycle[m], eofb_flipped[m], eorl_flipped[m], eoud_flipped[m],
170 corner_cycle[m], coud_flipped[m], corl_flipped[m], cofb_flipped[m],
171 center_cycle[m] }, cube, f);
172}
173
174int len(NissMove *alg) {
175 int i;
176 for (i = 0; alg[i].m != NULLMOVE; i++);
177 return i;
178}
179
180int copy_alg(NissMove *src, NissMove *dest) {
181 int i;
182 for (i = 0; src[i].m != NULLMOVE; i++)
183 dest[i] = src[i];
184 dest[i].m = NULLMOVE;
185 return i;
186}
187
188int invert_alg(NissMove *src, NissMove *dest) {
189 int n = len(src);
190 for (int i = 0; i < n; i++)
191 dest[n-i-1] = (NissMove){.m=inverse[src[i].m], .inverse=src[i].inverse};
192 dest[n].m = NULLMOVE;
193 return n;
194}
195
196int concat(NissMove *src1, NissMove *src2, NissMove *dest) {
197 int n1 = len(src1), n2 = len(src2);
198 copy_alg(src1, dest);
199 copy_alg(src2, dest+n1);
200 return n1+n2;
201}
202
203/* TODO: all strings start with space?? */
204void print_alg(NissMove *alg) {
205 bool niss = false;
206 for (int i = 0; alg[i].m != NULLMOVE; i++) {
207 char *fill = !niss && alg[i].inverse ? " (" :
208 (niss && !alg[i].inverse ? ") " : " ");
209 printf("%s%s", fill, move_string[alg[i].m]);
210 niss = alg[i].inverse;
211 }
212 printf("%s\n", niss ? ")" : "");
213}
214
215int read_moves(char *str, NissMove *alg, int n) {
216 bool niss = false;
217 int c = 0;
218
219 for (int i = 0; str[i] && c < n; i++) {
220 if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n')
221 continue;
222
223 if (str[i] == '(' || str[i] == ')') {
224 if ((niss && str[i] == '(') || (!niss && str[i] == ')'))
225 return -1;
226 niss = !niss;
227 continue;
228 }
229
230 alg[c].inverse = niss; alg[c].m = NULLMOVE;
231 for (Move j = 0; j < NMOVES; j++) {
232 if (str[i] == move_string[j][0]) {
233 alg[c].m = j;
234 if (alg[c].m <= B && str[i+1]=='w') { alg[c].m += Uw - U; i++; }
235 if (str[i+1]=='2') { alg[c].m += 1; i++; }
236 else if (str[i+1]=='\'' || str[i+1]=='3') { alg[c].m += 2; i++; }
237 c++;
238 break;
239 }
240 }
241 }
242
243 alg[c].m = NULLMOVE;
244 return c;
245}
246
247/* TODO: rewrite cleanup(). Idea:
248 1. split alg in normal + inverse part, rewriting each with equiv_moves
249 2. shift rotations to the end while transforming all moves in between
250 ARGH! this uses transformation! One more reason to merge everything in
251 one file.
252 3. cancellations
253*/
254
255bool read_ttables_file() {
256 FILE *ttf;
257 long unsigned int me[11] = { factorial12/factorial8, factorial12/factorial8,
258 factorial12/factorial8, pow2to11, pow2to11, pow2to11,
259 factorial8, pow3to7, pow3to7, pow3to7, factorial6 };
260 if ((ttf = fopen("ttables", "rb")) != NULL) {
261 bool r = true;
262 for (int m = 0; m < NMOVES; m++) {
263 r = r && fread(epose_ttable[m], sizeof(uint16_t), me[0], ttf) == me[0];
264 r = r && fread(eposs_ttable[m], sizeof(uint16_t), me[1], ttf) == me[1];
265 r = r && fread(eposm_ttable[m], sizeof(uint16_t), me[2], ttf) == me[2];
266 r = r && fread(eofb_ttable[m], sizeof(uint16_t), me[3], ttf) == me[3];
267 r = r && fread(eorl_ttable[m], sizeof(uint16_t), me[4], ttf) == me[4];
268 r = r && fread(eoud_ttable[m], sizeof(uint16_t), me[5], ttf) == me[5];
269 r = r && fread(cp_ttable[m], sizeof(uint16_t), me[6], ttf) == me[6];
270 r = r && fread(coud_ttable[m], sizeof(uint16_t), me[7], ttf) == me[7];
271 r = r && fread(corl_ttable[m], sizeof(uint16_t), me[8], ttf) == me[8];
272 r = r && fread(cofb_ttable[m], sizeof(uint16_t), me[9], ttf) == me[9];
273 r = r && fread(cpos_ttable[m], sizeof(uint16_t), me[10], ttf) == me[10];
274 }
275 fclose(ttf);
276 return r;
277 } else return false;
278}
279
280bool write_ttables_file() {
281 FILE *ttf;
282 long unsigned int me[11] = { factorial12/factorial8, factorial12/factorial8,
283 factorial12/factorial8, pow2to11, pow2to11, pow2to11,
284 factorial8, pow3to7, pow3to7, pow3to7, factorial6 };
285 if ((ttf = fopen("ttables", "wb")) != NULL) {
286 bool r = true;
287 for (int m = 0; m < NMOVES; m++) {
288 r = r && fwrite(epose_ttable[m], sizeof(uint16_t), me[0], ttf) == me[0];
289 r = r && fwrite(eposs_ttable[m], sizeof(uint16_t), me[1], ttf) == me[1];
290 r = r && fwrite(eposm_ttable[m], sizeof(uint16_t), me[2], ttf) == me[2];
291 r = r && fwrite(eofb_ttable[m], sizeof(uint16_t), me[3], ttf) == me[3];
292 r = r && fwrite(eorl_ttable[m], sizeof(uint16_t), me[4], ttf) == me[4];
293 r = r && fwrite(eoud_ttable[m], sizeof(uint16_t), me[5], ttf) == me[5];
294 r = r && fwrite(cp_ttable[m], sizeof(uint16_t), me[6], ttf) == me[6];
295 r = r && fwrite(coud_ttable[m], sizeof(uint16_t), me[7], ttf) == me[7];
296 r = r && fwrite(corl_ttable[m], sizeof(uint16_t), me[8], ttf) == me[8];
297 r = r && fwrite(cofb_ttable[m], sizeof(uint16_t), me[9], ttf) == me[9];
298 r = r && fwrite(cpos_ttable[m], sizeof(uint16_t), me[10],ttf) == me[10];
299 }
300 fclose(ttf);
301 return r;
302 } else return false;
303}
304
305void init_ttables(bool read, bool write) {
306 /* Generate all move cycles and flips; I do this regardless */
307 for (int i = 0; i < NMOVES; i++) {
308 if (i == U || i == x || i == y)
309 continue;
310
311 Cube c = {0};
312 for (int j = 0; equiv_moves[i][j]; j++)
313 c = apply_move_cubearray(equiv_moves[i][j], c, pf_all);
314
315 CubeArray arrs = {
316 edge_cycle[i], eofb_flipped[i], eorl_flipped[i], eoud_flipped[i],
317 corner_cycle[i], coud_flipped[i], corl_flipped[i], cofb_flipped[i],
318 center_cycle[i]
319 };
320 cube_to_arrays(c, &arrs, pf_all);
321 }
322
323 if (read)
324 if (read_ttables_file())
325 return;
326
327 /* Initialize transition tables */
328 for (int m = 0; m < NMOVES; m++) {
329 for (uint16_t i = 0; i < factorial12/factorial8; i++) {
330 epose_ttable[m][i] = apply_move_cubearray(m,(Cube){.epose=i},pf_e).epose;
331 eposs_ttable[m][i] = apply_move_cubearray(m,(Cube){.eposs=i},pf_s).eposs;
332 eposm_ttable[m][i] = apply_move_cubearray(m,(Cube){.eposm=i},pf_m).eposm;
333 }
334 for (uint16_t i = 0; i < pow2to11; i++ ) {
335 eofb_ttable[m][i] = apply_move_cubearray(m,(Cube){.eofb=i},pf_eo).eofb;
336 eorl_ttable[m][i] = apply_move_cubearray(m,(Cube){.eorl=i},pf_eo).eorl;
337 eoud_ttable[m][i] = apply_move_cubearray(m,(Cube){.eoud=i},pf_eo).eoud;
338 }
339 for (uint16_t i = 0; i < pow3to7; i++) {
340 coud_ttable[m][i] = apply_move_cubearray(m,(Cube){.coud=i},pf_co).coud;
341 corl_ttable[m][i] = apply_move_cubearray(m,(Cube){.corl=i},pf_co).corl;
342 cofb_ttable[m][i] = apply_move_cubearray(m,(Cube){.cofb=i},pf_co).cofb;
343 }
344 for (uint16_t i = 0; i < factorial8; i++)
345 cp_ttable[m][i] = apply_move_cubearray(m,(Cube){.cp=i},pf_cp).cp;
346 for (uint16_t i = 0; i < factorial6; i++)
347 cpos_ttable[m][i] = apply_move_cubearray(m,(Cube){.cpos=i},pf_cpos).cpos;
348 }
349
350 if (write)
351 if (!write_ttables_file())
352 printf("Error in writing ttables: file not writable\n");
353}
354
355Cube move_cube(Move m, Cube cube) {
356 Cube moved = {0};
357
358 moved.epose = epose_ttable[m][cube.epose];
359 moved.eposs = eposs_ttable[m][cube.eposs];
360 moved.eposm = eposm_ttable[m][cube.eposm];
361 moved.eofb = eofb_ttable[m][cube.eofb];
362 moved.eorl = eorl_ttable[m][cube.eorl];
363 moved.eoud = eoud_ttable[m][cube.eoud];
364 moved.coud = coud_ttable[m][cube.coud];
365 moved.cofb = cofb_ttable[m][cube.cofb];
366 moved.corl = corl_ttable[m][cube.corl];
367 moved.cp = cp_ttable[m][cube.cp];
368 moved.cpos = cpos_ttable[m][cube.cpos];
369
370 return moved;
371}
372
373Cube apply_alg_filtered(NissMove *alg, Cube cube, PieceFilter f) {
374 Cube ret = {0};
375 for (int i = 0; alg[i].m != NULLMOVE; i++)
376 if (alg[i].inverse)
377 ret = move_cube(alg[i].m, ret);
378
379 ret = compose_filtered(cube, inverse_cube(ret), f);
380
381 for (int i = 0; alg[i].m != NULLMOVE; i++)
382 if (!alg[i].inverse)
383 ret = move_cube(alg[i].m, ret);
384 return ret;
385}
386
387Cube apply_alg(NissMove *alg, Cube cube) {
388 return apply_alg_filtered(alg, cube, pf_all);
389}
390
391void init_aux_tables() {
392 /* Commute */
393 for (int i = 0; i < NMOVES; i++)
394 for (int j = 0; j < NMOVES; j++)
395 commute[i][j] = equal(move_cube(i, move_cube(j, (Cube){0})),
396 move_cube(j, move_cube(i, (Cube){0})));
397
398 /* Possible next (if the sequence i j k is valid) */
399 for (int i = 0; i < NMOVES; i++)
400 for (int j = 0; j < NMOVES; j++)
401 for (int k = 0; k < NMOVES; k++)
402 possible_next[i][j][k] =
403 (j == 0) ||
404 (j != 0 && (j-(j-1)%3) != (k-(k-1)%3) &&
405 !(i != 0 && commute[i][j] && (i-(i-1)%3) == (k-(k-1)%3)));
406
407 /* Inverse */
408 for (int i = 0; i < NMOVES; i++)
409 inverse[i] = i == NULLMOVE ? NULLMOVE : i + 2 - 2*((i-1)%3);
410
411}
412

Generated with cgit - Back to sebastiano.tronto.net