aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constants.h4
-rw-r--r--src/cube.h5
-rw-r--r--src/cube_array.c75
3 files changed, 84 insertions, 0 deletions
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)

Generated with cgit - Back to sebastiano.tronto.net