aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--src/constants.h4
-rw-r--r--src/cube.h5
-rw-r--r--src/cube_array.c75
-rw-r--r--test/05_transform/00_solved_UFr.in2
-rw-r--r--test/05_transform/00_solved_UFr.out1
-rw-r--r--test/05_transform/01_solved_BLm.in2
-rw-r--r--test/05_transform/01_solved_BLm.out1
-rw-r--r--test/05_transform/transform_tests.c38
-rw-r--r--utils/TRANSFORMATIONS.txt6
-rwxr-xr-xutils/mirror.sh2
-rw-r--r--utils/transform_moves.txt95
12 files changed, 232 insertions, 2 deletions
diff --git a/README.md b/README.md
index d25ca27..229eb8f 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,8 @@ Work in progress.
4 4
5TODO: 5TODO:
6 6
7* test SRC: scrambled cube, rename directory in io_SRC_write 7* write script to generate tests for trans (see utils/transform_moves.txt)
8* add tests for transformation
8* implement transformations (use write to SRC to make life easier) 9* implement transformations (use write to SRC to make life easier)
9* setup benchmarks 10* setup benchmarks
10* coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym 11* coordinates: co, eo, epsep, cpsep_sym, cocpsep_sym, cphtr_sym, cocphtr_sym
diff --git a/src/constants.h b/src/constants.h
index 54152bc..9e0a7a7 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -69,3 +69,7 @@
69#define BRm 45 69#define BRm 45
70#define BDm 46 70#define BDm 46
71#define BLm 47 71#define BLm 47
72
73/* Errors */
74#define errormove 99U
75#define errortrans 99U
diff --git a/src/cube.h b/src/cube.h
index 129062d..67f04bf 100644
--- a/src/cube.h
+++ b/src/cube.h
@@ -21,7 +21,12 @@ bool iserror(cube_t);
21int readmoves(char *, move_t *); 21int readmoves(char *, move_t *);
22void writemoves(move_t *, int, char *); 22void writemoves(move_t *, int, char *);
23 23
24trans_t readtrans(char *);
25void writetrans(trans_t, char *);
26
24cube_t move(cube_t, move_t); 27cube_t move(cube_t, move_t);
25cube_t inverse(cube_t); 28cube_t inverse(cube_t);
26cube_t compose(cube_t, cube_t); 29cube_t compose(cube_t, cube_t);
30
31/* See utils/TRANSFORMATIONS.txt for how transformations are applied */
27cube_t transform(cube_t, trans_t); 32cube_t transform(cube_t, trans_t);
diff --git a/src/cube_array.c b/src/cube_array.c
index 1d2da86..cbf59e4 100644
--- a/src/cube_array.c
+++ b/src/cube_array.c
@@ -120,6 +120,57 @@ static char *movestr[] = {
120 [B3] = "B'", 120 [B3] = "B'",
121}; 121};
122 122
123static char *transstr[] = {
124 [UFr] = "rotation UF",
125 [UFm] = "mirrored UF",
126 [ULr] = "rotation UL",
127 [ULm] = "mirrored UL",
128 [UBr] = "rotation UB",
129 [UBm] = "mirrored UB",
130 [URr] = "rotation UR",
131 [URm] = "mirrored UR",
132 [DFr] = "rotation DF",
133 [DFm] = "mirrored DF",
134 [DLr] = "rotation DL",
135 [DLm] = "mirrored DL",
136 [DBr] = "rotation DB",
137 [DBm] = "mirrored DB",
138 [DRr] = "rotation DR",
139 [DRm] = "mirrored DR",
140 [RUr] = "rotation RU",
141 [RUm] = "mirrored RU",
142 [RFr] = "rotation RF",
143 [RFm] = "mirrored RF",
144 [RDr] = "rotation RD",
145 [RDm] = "mirrored RD",
146 [RBr] = "rotation RB",
147 [RBm] = "mirrored RB",
148 [LUr] = "rotation LU",
149 [LUm] = "mirrored LU",
150 [LFr] = "rotation LF",
151 [LFm] = "mirrored LF",
152 [LDr] = "rotation LD",
153 [LDm] = "mirrored LD",
154 [LBr] = "rotation LB",
155 [LBm] = "mirrored LB",
156 [FUr] = "rotation FU",
157 [FUm] = "mirrored FU",
158 [FRr] = "rotation FR",
159 [FRm] = "mirrored FR",
160 [FDr] = "rotation FD",
161 [FDm] = "mirrored FD",
162 [FLr] = "rotation FL",
163 [FLm] = "mirrored FL",
164 [BUr] = "rotation BU",
165 [BUm] = "mirrored BU",
166 [BRr] = "rotation BR",
167 [BRm] = "mirrored BR",
168 [BDr] = "rotation BD",
169 [BDm] = "mirrored BD",
170 [BLr] = "rotation BL",
171 [BLm] = "mirrored BL",
172};
173
123cube_t solvedcube = { 174cube_t solvedcube = {
124 .c = { 175 .c = {
125 [_c_ufr] = _c_ufr, 176 [_c_ufr] = _c_ufr,
@@ -452,6 +503,21 @@ readmoves_error:
452 return -1; 503 return -1;
453} 504}
454 505
506trans_t
507readtrans(char *buf)
508{
509 uint8_t t;
510
511 for (t = 0; t < 48; t++)
512 if (!strncmp(buf, transstr[t], 11))
513 return t;
514
515#ifdef DEBUG
516 fprintf(stderr, "readtrans error\n");
517#endif
518 return errortrans;
519}
520
455void 521void
456writemoves(move_t *m, int n, char *buf) 522writemoves(move_t *m, int n, char *buf)
457{ 523{
@@ -469,6 +535,15 @@ writemoves(move_t *m, int n, char *buf)
469 *b = '\0'; 535 *b = '\0';
470} 536}
471 537
538void
539writetrans(trans_t t, char *buf)
540{
541 if (t >= 48)
542 memcpy(buf, "error trans", 11);
543 else
544 memcpy(buf, transstr[t], 11);
545 buf[11] = '\0';
546}
472 547
473static int 548static int
474permsign(uint8_t *a, int n) 549permsign(uint8_t *a, int n)
diff --git a/test/05_transform/00_solved_UFr.in b/test/05_transform/00_solved_UFr.in
new file mode 100644
index 0000000..aa89e85
--- /dev/null
+++ b/test/05_transform/00_solved_UFr.in
@@ -0,0 +1,2 @@
1rotation UF
2UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
diff --git a/test/05_transform/00_solved_UFr.out b/test/05_transform/00_solved_UFr.out
new file mode 100644
index 0000000..dff224d
--- /dev/null
+++ b/test/05_transform/00_solved_UFr.out
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
diff --git a/test/05_transform/01_solved_BLm.in b/test/05_transform/01_solved_BLm.in
new file mode 100644
index 0000000..43aadb8
--- /dev/null
+++ b/test/05_transform/01_solved_BLm.in
@@ -0,0 +1,2 @@
1mirrored BL
2UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
diff --git a/test/05_transform/01_solved_BLm.out b/test/05_transform/01_solved_BLm.out
new file mode 100644
index 0000000..dff224d
--- /dev/null
+++ b/test/05_transform/01_solved_BLm.out
@@ -0,0 +1 @@
UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0
diff --git a/test/05_transform/transform_tests.c b/test/05_transform/transform_tests.c
new file mode 100644
index 0000000..c648662
--- /dev/null
+++ b/test/05_transform/transform_tests.c
@@ -0,0 +1,38 @@
1#include <stdbool.h>
2#include <stdint.h>
3#include <stdio.h>
4
5#include "../../src/cube.h"
6#include "../../src/constants.h"
7
8#define STRLENMAX 10000
9
10int main() {
11 char str[STRLENMAX];
12 trans_t t;
13 cube_t cube;
14
15 fgets(str, STRLENMAX, stdin);
16 t = readtrans(str);
17
18 if (t == errortrans) {
19 printf("Error reading trans\n");
20 return 1;
21 }
22
23 fgets(str, STRLENMAX, stdin);
24 cube = readcube(H48, str);
25
26 cube = transform(cube, t);
27
28 if (iserror(cube)) {
29 printf("Error transforming cube\n");
30 } else if (!issolvable(cube)) {
31 printf("Transformed cube is not solvable\n");
32 } else {
33 writecube(H48, cube, str);
34 printf("%s\n", str);
35 }
36
37 return 0;
38}
diff --git a/utils/TRANSFORMATIONS.txt b/utils/TRANSFORMATIONS.txt
index 6ff6946..58446e8 100644
--- a/utils/TRANSFORMATIONS.txt
+++ b/utils/TRANSFORMATIONS.txt
@@ -8,6 +8,12 @@ the rotation that brings the F face on top and the D face on front.
8A composed rotation + mirror is obtained by applying the corresponding 8A composed rotation + mirror is obtained by applying the corresponding
9rotation to the solved cube mirrored along the M plane. 9rotation to the solved cube mirrored along the M plane.
10 10
11For example, to apply the transformation RBm (mirrored RB) to a cube C:
12 1a. Apply a mirror along the M plane to the solved cube
13 1b. Rotate the mirrored cube with z' y2
14 3. Apply the cube C to the transformed solved cube
15 4. Apply the transformations of step 1a and 1b in reverse
16
11The orientation of pieces after a rotation ignores the new position 17The orientation of pieces after a rotation ignores the new position
12of centers. A rotated cube can technically be inconsistent, because 18of centers. A rotated cube can technically be inconsistent, because
13the parity of the edge permutation has to be adjusted considering the 19the parity of the edge permutation has to be adjusted considering the
diff --git a/utils/mirror.sh b/utils/mirror.sh
index 57b02d1..41a434f 100755
--- a/utils/mirror.sh
+++ b/utils/mirror.sh
@@ -1,3 +1,3 @@
1#!/bin/sh 1#!/bin/sh
2 2
3sed 's/R/l/g ; s/L/R/g ; s/l/L/g' 3tr 'LR' 'RL'
diff --git a/utils/transform_moves.txt b/utils/transform_moves.txt
new file mode 100644
index 0000000..469008b
--- /dev/null
+++ b/utils/transform_moves.txt
@@ -0,0 +1,95 @@
1UFr U U
2UFr R R
3UFr F F
4
5ULr U U
6ULr R F
7ULr F L
8
9UBr U U
10UBr R L
11UBr F B
12
13URr U U
14URr R B
15URr F R
16
17DFr U D
18DFr R L
19DFr F F
20
21DLr U D
22DLr R B
23DLr F L
24
25DBr U D
26DBr R R
27DBr F B
28
29DRr U D
30DRr R F
31DRr F R
32
33RUr U R
34RUr R F
35RUr F U
36
37RFr U R
38RFr R D
39RFr F F
40
41RDr U R
42RDr R B
43RDr F D
44
45RBr U R
46RBr R U
47RBr F B
48
49LUr U L
50LUr R B
51LUr F U
52
53LFr U L
54LFr R U
55LFr F F
56
57LDr U L
58LDr R F
59LDr F D
60
61LBr U L
62LBr R D
63LBr F B
64
65FUr U F
66FUr R L
67FUr F U
68
69FRr U F
70FRr R U
71FRr F R
72
73FDr U F
74FDr R R
75FDr F D
76
77FLr U F
78FLr R D
79FLr F L
80
81BUr U B
82BUr R R
83BUr F U
84
85BRr U B
86BRr R D
87BRr F R
88
89BDr U B
90BDr R L
91BDr F D
92
93BLr U B
94BLr R U
95BLr F L

Generated with cgit - Back to sebastiano.tronto.net