aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands.c24
-rw-r--r--src/moves.c120
-rw-r--r--src/moves.h1
3 files changed, 145 insertions, 0 deletions
diff --git a/src/commands.c b/src/commands.c
index d9d6b50..13405b7 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -12,6 +12,7 @@ CommandArgs * scramble_parse_args(int c, char **v);
12/* Exec functions ************************************************************/ 12/* Exec functions ************************************************************/
13 13
14static void gen_exec(CommandArgs *args); 14static void gen_exec(CommandArgs *args);
15static void cleanup_exec(CommandArgs *args);
15static void invert_exec(CommandArgs *args); 16static void invert_exec(CommandArgs *args);
16static void solve_exec(CommandArgs *args); 17static void solve_exec(CommandArgs *args);
17static void scramble_exec(CommandArgs *args); 18static void scramble_exec(CommandArgs *args);
@@ -123,6 +124,15 @@ quit_cmd = {
123}; 124};
124 125
125Command 126Command
127cleanup_cmd = {
128 .name = "cleanup",
129 .usage = "cleanup SCRAMBLE",
130 .description = "Rewrite a scramble using only standard moves (HTM)",
131 .parse_args = parse_only_scramble,
132 .exec = cleanup_exec,
133};
134
135Command
126unniss_cmd = { 136unniss_cmd = {
127 .name = "unniss", 137 .name = "unniss",
128 .usage = "unniss SCRAMBLE", 138 .usage = "unniss SCRAMBLE",
@@ -151,6 +161,7 @@ Command *commands[NCOMMANDS] = {
151 &scramble_cmd, 161 &scramble_cmd,
152 &steps_cmd, 162 &steps_cmd,
153 &twophase_cmd, 163 &twophase_cmd,
164 &cleanup_cmd,
154 &unniss_cmd, 165 &unniss_cmd,
155 &version_cmd, 166 &version_cmd,
156}; 167};
@@ -499,6 +510,19 @@ quit_exec(CommandArgs *args)
499} 510}
500 511
501static void 512static void
513cleanup_exec(CommandArgs *args)
514{
515 Alg *alg;
516
517 init_moves();
518
519 alg = cleanup(args->scramble);
520 print_alg(alg, false);
521
522 free_alg(alg);
523}
524
525static void
502unniss_exec(CommandArgs *args) 526unniss_exec(CommandArgs *args)
503{ 527{
504 unniss(args->scramble); 528 unniss(args->scramble);
diff --git a/src/moves.c b/src/moves.c
index 9547de9..7c33db4 100644
--- a/src/moves.c
+++ b/src/moves.c
@@ -3,6 +3,7 @@
3/* Local functions ***********************************************************/ 3/* Local functions ***********************************************************/
4 4
5static Cube apply_move_cubearray(Move m, Cube cube, PieceFilter f); 5static Cube apply_move_cubearray(Move m, Cube cube, PieceFilter f);
6static void cleanup_aux(Alg *alg, Alg *ret, bool inv);
6static bool read_mtables_file(); 7static bool read_mtables_file();
7static bool write_mtables_file(); 8static bool write_mtables_file();
8 9
@@ -221,6 +222,125 @@ apply_move(Move m, Cube cube)
221 }; 222 };
222} 223}
223 224
225Alg *
226cleanup(Alg *alg)
227{
228 int i, j, k, b[2], n, L;
229 Move bb, m;
230 Alg *ret;
231
232 ret = new_alg("");
233 cleanup_aux(alg, ret, false);
234 cleanup_aux(alg, ret, true);
235
236 do {
237 for (i = 0, j = 0, n = 0; i < ret->len; i = j) {
238 if (ret->move[i] > B3) {
239 ret->move[n] = ret->move[i];
240 ret->inv[n] = ret->inv[i];
241 n++;
242 j++;
243 continue;
244 }
245
246 bb = 1 + ((base_move(ret->move[i]) - 1)/6)*6;
247 while (j < ret->len &&
248 ret->move[j] <= B3 &&
249 ret->inv[j] == ret->inv[i] &&
250 1 + ((base_move(ret->move[j]) - 1)/6)*6 == bb)
251 j++;
252
253 for (k = i, b[0] = 0, b[1] = 0; k < j; k++) {
254 m = ret->move[k];
255 if (base_move(m) == bb)
256 b[0] = (b[0]+1+m-base_move(m)) % 4;
257 else
258 b[1] = (b[1]+1+m-base_move(m)) % 4;
259 }
260
261 for (k = 0; k < 2; k++) {
262 if (b[k] != 0) {
263 ret->move[n] = bb + b[k] - 1 + 3*k;
264 ret->inv[n] = ret->inv[i];
265 n++;
266 }
267 }
268 }
269
270 L = ret->len;
271 ret->len = n;
272 } while (L != n);
273
274 return ret;
275}
276
277static void
278cleanup_aux(Alg *alg, Alg *ret, bool inv)
279{
280 int i, j;
281 Cube c, d;
282 Move m, mm;
283 Alg *equiv_alg;
284
285 c = (Cube){0};
286 for (i = 0; i < alg->len; i++) {
287 if (alg->inv[i] != inv)
288 continue;
289
290 equiv_alg = new_alg(equiv_alg_string[alg->move[i]]);
291
292 for (j = 0; j < equiv_alg->len; j++) {
293 m = equiv_alg->move[j];
294 if (m == U) {
295 mm = 3*what_center_at(c, U_center) + 1;
296 append_move(ret, mm, inv);
297 } else {
298 c = apply_move(m, c);
299 }
300 }
301
302 free_alg(equiv_alg);
303 }
304
305 m = NULLMOVE;
306 switch (what_center_at(c, F_center)) {
307 case U_center:
308 m = x3;
309 break;
310 case D_center:
311 m = x;
312 break;
313 case R_center:
314 m = y;
315 break;
316 case L_center:
317 m = y3;
318 break;
319 case B_center:
320 if (what_center_at(c, U_center) == U_center)
321 m = y2;
322 else
323 m = x2;
324 break;
325 default:
326 break;
327 }
328 d = apply_move(m, (Cube){0});
329 if (m != NULLMOVE)
330 append_move(ret, m, inv);
331
332 m = NULLMOVE;
333 if (what_center_at(c, U_center) == what_center_at(d, D_center)) {
334 m = z2;
335 } else if (what_center_at(c, U_center) == what_center_at(d, R_center)) {
336 m = z3;
337 } else if (what_center_at(c, U_center) == what_center_at(d, L_center)) {
338 m = z;
339 }
340 if (m != NULLMOVE)
341 append_move(ret, m, inv);
342}
343
224static bool 344static bool
225read_mtables_file() 345read_mtables_file()
226{ 346{
diff --git a/src/moves.h b/src/moves.h
index 4820f65..e7881a4 100644
--- a/src/moves.h
+++ b/src/moves.h
@@ -8,6 +8,7 @@
8Cube apply_alg(Alg *alg, Cube cube); 8Cube apply_alg(Alg *alg, Cube cube);
9Cube apply_alg_generic(Alg *alg, Cube c, PieceFilter f, bool a); 9Cube apply_alg_generic(Alg *alg, Cube c, PieceFilter f, bool a);
10Cube apply_move(Move m, Cube cube); 10Cube apply_move(Move m, Cube cube);
11Alg * cleanup(Alg *alg);
11 12
12void init_moves(); 13void init_moves();
13 14

Generated with cgit - Back to sebastiano.tronto.net