From 259c7326f78d5495f5dc51c619932599a5279f68 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 22 Oct 2023 12:49:20 +0200 Subject: Progess with transformation implementation --- src/constants.h | 4 +++ src/cube.h | 5 ++++ src/cube_array.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) (limited to 'src') 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 @@ #define BRm 45 #define BDm 46 #define BLm 47 + +/* Errors */ +#define errormove 99U +#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); int readmoves(char *, move_t *); void writemoves(move_t *, int, char *); +trans_t readtrans(char *); +void writetrans(trans_t, char *); + cube_t move(cube_t, move_t); cube_t inverse(cube_t); cube_t compose(cube_t, cube_t); + +/* See utils/TRANSFORMATIONS.txt for how transformations are applied */ cube_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[] = { [B3] = "B'", }; +static char *transstr[] = { + [UFr] = "rotation UF", + [UFm] = "mirrored UF", + [ULr] = "rotation UL", + [ULm] = "mirrored UL", + [UBr] = "rotation UB", + [UBm] = "mirrored UB", + [URr] = "rotation UR", + [URm] = "mirrored UR", + [DFr] = "rotation DF", + [DFm] = "mirrored DF", + [DLr] = "rotation DL", + [DLm] = "mirrored DL", + [DBr] = "rotation DB", + [DBm] = "mirrored DB", + [DRr] = "rotation DR", + [DRm] = "mirrored DR", + [RUr] = "rotation RU", + [RUm] = "mirrored RU", + [RFr] = "rotation RF", + [RFm] = "mirrored RF", + [RDr] = "rotation RD", + [RDm] = "mirrored RD", + [RBr] = "rotation RB", + [RBm] = "mirrored RB", + [LUr] = "rotation LU", + [LUm] = "mirrored LU", + [LFr] = "rotation LF", + [LFm] = "mirrored LF", + [LDr] = "rotation LD", + [LDm] = "mirrored LD", + [LBr] = "rotation LB", + [LBm] = "mirrored LB", + [FUr] = "rotation FU", + [FUm] = "mirrored FU", + [FRr] = "rotation FR", + [FRm] = "mirrored FR", + [FDr] = "rotation FD", + [FDm] = "mirrored FD", + [FLr] = "rotation FL", + [FLm] = "mirrored FL", + [BUr] = "rotation BU", + [BUm] = "mirrored BU", + [BRr] = "rotation BR", + [BRm] = "mirrored BR", + [BDr] = "rotation BD", + [BDm] = "mirrored BD", + [BLr] = "rotation BL", + [BLm] = "mirrored BL", +}; + cube_t solvedcube = { .c = { [_c_ufr] = _c_ufr, @@ -452,6 +503,21 @@ readmoves_error: return -1; } +trans_t +readtrans(char *buf) +{ + uint8_t t; + + for (t = 0; t < 48; t++) + if (!strncmp(buf, transstr[t], 11)) + return t; + +#ifdef DEBUG + fprintf(stderr, "readtrans error\n"); +#endif + return errortrans; +} + void writemoves(move_t *m, int n, char *buf) { @@ -469,6 +535,15 @@ writemoves(move_t *m, int n, char *buf) *b = '\0'; } +void +writetrans(trans_t t, char *buf) +{ + if (t >= 48) + memcpy(buf, "error trans", 11); + else + memcpy(buf, transstr[t], 11); + buf[11] = '\0'; +} static int permsign(uint8_t *a, int n) -- cgit v1.3