diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/constants.h | 75 | ||||
| -rw-r--r-- | src/cube.c (renamed from src/cube_array.c) | 20 | ||||
| -rw-r--r-- | src/cube.h | 93 | ||||
| -rw-r--r-- | src/cube_array.h | 6 |
4 files changed, 89 insertions, 105 deletions
diff --git a/src/constants.h b/src/constants.h deleted file mode 100644 index 9e0a7a7..0000000 --- a/src/constants.h +++ /dev/null | |||
| @@ -1,75 +0,0 @@ | |||
| 1 | /* Standard moves */ | ||
| 2 | #define U 0U | ||
| 3 | #define U2 1U | ||
| 4 | #define U3 2U | ||
| 5 | #define D 3U | ||
| 6 | #define D2 4U | ||
| 7 | #define D3 5U | ||
| 8 | #define R 6U | ||
| 9 | #define R2 7U | ||
| 10 | #define R3 8U | ||
| 11 | #define L 9U | ||
| 12 | #define L2 10U | ||
| 13 | #define L3 11U | ||
| 14 | #define F 12U | ||
| 15 | #define F2 13U | ||
| 16 | #define F3 14U | ||
| 17 | #define B 15U | ||
| 18 | #define B2 16U | ||
| 19 | #define B3 17U | ||
| 20 | |||
| 21 | /* Regular transformations (rotations) */ | ||
| 22 | #define UFr 0 | ||
| 23 | #define ULr 1 | ||
| 24 | #define UBr 2 | ||
| 25 | #define URr 3 | ||
| 26 | #define DFr 4 | ||
| 27 | #define DLr 5 | ||
| 28 | #define DBr 6 | ||
| 29 | #define DRr 7 | ||
| 30 | #define RUr 8 | ||
| 31 | #define RFr 9 | ||
| 32 | #define RDr 10 | ||
| 33 | #define RBr 11 | ||
| 34 | #define LUr 12 | ||
| 35 | #define LFr 13 | ||
| 36 | #define LDr 14 | ||
| 37 | #define LBr 15 | ||
| 38 | #define FUr 16 | ||
| 39 | #define FRr 17 | ||
| 40 | #define FDr 18 | ||
| 41 | #define FLr 19 | ||
| 42 | #define BUr 20 | ||
| 43 | #define BRr 21 | ||
| 44 | #define BDr 22 | ||
| 45 | #define BLr 23 | ||
| 46 | |||
| 47 | /* Mirrored transformations */ | ||
| 48 | #define UFm 24 | ||
| 49 | #define ULm 25 | ||
| 50 | #define UBm 26 | ||
| 51 | #define URm 27 | ||
| 52 | #define DFm 28 | ||
| 53 | #define DLm 29 | ||
| 54 | #define DBm 30 | ||
| 55 | #define DRm 31 | ||
| 56 | #define RUm 32 | ||
| 57 | #define RFm 33 | ||
| 58 | #define RDm 34 | ||
| 59 | #define RBm 35 | ||
| 60 | #define LUm 36 | ||
| 61 | #define LFm 37 | ||
| 62 | #define LDm 38 | ||
| 63 | #define LBm 39 | ||
| 64 | #define FUm 40 | ||
| 65 | #define FRm 41 | ||
| 66 | #define FDm 42 | ||
| 67 | #define FLm 43 | ||
| 68 | #define BUm 44 | ||
| 69 | #define BRm 45 | ||
| 70 | #define BDm 46 | ||
| 71 | #define BLm 47 | ||
| 72 | |||
| 73 | /* Errors */ | ||
| 74 | #define errormove 99U | ||
| 75 | #define errortrans 99U | ||
diff --git a/src/cube_array.c b/src/cube.c index cbf59e4..f6e6a8f 100644 --- a/src/cube_array.c +++ b/src/cube.c | |||
| @@ -1,22 +1,3 @@ | |||
| 1 | /* | ||
| 2 | In this implementation of the cube.h interface, the cube is represented | ||
| 3 | by two arrays of 8-bit unsigned integers, one for centers and one for | ||
| 4 | corners. The 4 leas-significant digits of each bit determine the piece, | ||
| 5 | the other 4 are used for orientation or kept to 0. | ||
| 6 | |||
| 7 | Edges: | ||
| 8 | xxxopppp (x = unused, o = orientation, p = piece) | ||
| 9 | |||
| 10 | Corners: | ||
| 11 | xooxpppp (x = unused, o = orientation, p = piece) | ||
| 12 | |||
| 13 | The two bits for CO are shifted to make it possible to perform mod 3 | ||
| 14 | operations (sum, inverse) using only addition and bitwise operators. | ||
| 15 | See below for details. | ||
| 16 | |||
| 17 | The third bit is needed because x+y+1 can exceed 4. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <inttypes.h> | 1 | #include <inttypes.h> |
| 21 | #include <stdbool.h> | 2 | #include <stdbool.h> |
| 22 | #include <string.h> | 3 | #include <string.h> |
| @@ -25,7 +6,6 @@ The third bit is needed because x+y+1 can exceed 4. | |||
| 25 | #include <stdio.h> | 6 | #include <stdio.h> |
| 26 | #endif | 7 | #endif |
| 27 | 8 | ||
| 28 | #include "constants.h" | ||
| 29 | #include "cube.h" | 9 | #include "cube.h" |
| 30 | 10 | ||
| 31 | #define _c_ufr 0U | 11 | #define _c_ufr 0U |
| @@ -1,14 +1,99 @@ | |||
| 1 | /* Constants *****************************************************************/ | ||
| 2 | |||
| 3 | /* Standard moves */ | ||
| 4 | #define U 0U | ||
| 5 | #define U2 1U | ||
| 6 | #define U3 2U | ||
| 7 | #define D 3U | ||
| 8 | #define D2 4U | ||
| 9 | #define D3 5U | ||
| 10 | #define R 6U | ||
| 11 | #define R2 7U | ||
| 12 | #define R3 8U | ||
| 13 | #define L 9U | ||
| 14 | #define L2 10U | ||
| 15 | #define L3 11U | ||
| 16 | #define F 12U | ||
| 17 | #define F2 13U | ||
| 18 | #define F3 14U | ||
| 19 | #define B 15U | ||
| 20 | #define B2 16U | ||
| 21 | #define B3 17U | ||
| 22 | |||
| 23 | /* Regular transformations (rotations) */ | ||
| 24 | #define UFr 0 | ||
| 25 | #define ULr 1 | ||
| 26 | #define UBr 2 | ||
| 27 | #define URr 3 | ||
| 28 | #define DFr 4 | ||
| 29 | #define DLr 5 | ||
| 30 | #define DBr 6 | ||
| 31 | #define DRr 7 | ||
| 32 | #define RUr 8 | ||
| 33 | #define RFr 9 | ||
| 34 | #define RDr 10 | ||
| 35 | #define RBr 11 | ||
| 36 | #define LUr 12 | ||
| 37 | #define LFr 13 | ||
| 38 | #define LDr 14 | ||
| 39 | #define LBr 15 | ||
| 40 | #define FUr 16 | ||
| 41 | #define FRr 17 | ||
| 42 | #define FDr 18 | ||
| 43 | #define FLr 19 | ||
| 44 | #define BUr 20 | ||
| 45 | #define BRr 21 | ||
| 46 | #define BDr 22 | ||
| 47 | #define BLr 23 | ||
| 48 | |||
| 49 | /* Mirrored transformations */ | ||
| 50 | #define UFm 24 | ||
| 51 | #define ULm 25 | ||
| 52 | #define UBm 26 | ||
| 53 | #define URm 27 | ||
| 54 | #define DFm 28 | ||
| 55 | #define DLm 29 | ||
| 56 | #define DBm 30 | ||
| 57 | #define DRm 31 | ||
| 58 | #define RUm 32 | ||
| 59 | #define RFm 33 | ||
| 60 | #define RDm 34 | ||
| 61 | #define RBm 35 | ||
| 62 | #define LUm 36 | ||
| 63 | #define LFm 37 | ||
| 64 | #define LDm 38 | ||
| 65 | #define LBm 39 | ||
| 66 | #define FUm 40 | ||
| 67 | #define FRm 41 | ||
| 68 | #define FDm 42 | ||
| 69 | #define FLm 43 | ||
| 70 | #define BUm 44 | ||
| 71 | #define BRm 45 | ||
| 72 | #define BDm 46 | ||
| 73 | #define BLm 47 | ||
| 74 | |||
| 75 | /* Errors */ | ||
| 76 | #define errormove 99U | ||
| 77 | #define errortrans 99U | ||
| 78 | |||
| 79 | /* Types *********************************************************************/ | ||
| 80 | |||
| 1 | /* TODO: ifdef for different implementations */ | 81 | /* TODO: ifdef for different implementations */ |
| 2 | #include "cube_array.h" | 82 | /* See doc/CUBE_INTERNAL.md for a description of the cube format */ |
| 83 | typedef struct { | ||
| 84 | uint8_t c[8]; | ||
| 85 | uint8_t e[12]; | ||
| 86 | } cube_t; | ||
| 3 | 87 | ||
| 4 | /* For moves and transformations, see constants.h */ | ||
| 5 | typedef uint8_t move_t; | 88 | typedef uint8_t move_t; |
| 6 | typedef uint8_t trans_t; | 89 | typedef uint8_t trans_t; |
| 7 | 90 | ||
| 8 | extern cube_t solvedcube; | 91 | extern cube_t solvedcube; |
| 9 | 92 | ||
| 93 | /* Functions *****************************************************************/ | ||
| 94 | |||
| 10 | /* Not all formats are supported for both read and write. */ | 95 | /* Not all formats are supported for both read and write. */ |
| 11 | /* See utils/FORMAT.txt for details. */ | 96 | /* See doc/CUBE_TEXT.md for details. */ |
| 12 | typedef enum {H48, SRC} format_t; | 97 | typedef enum {H48, SRC} format_t; |
| 13 | cube_t readcube(format_t, char *); | 98 | cube_t readcube(format_t, char *); |
| 14 | void writecube(format_t, cube_t, char *); | 99 | void writecube(format_t, cube_t, char *); |
| @@ -28,5 +113,5 @@ cube_t move(cube_t, move_t); | |||
| 28 | cube_t inverse(cube_t); | 113 | cube_t inverse(cube_t); |
| 29 | cube_t compose(cube_t, cube_t); | 114 | cube_t compose(cube_t, cube_t); |
| 30 | 115 | ||
| 31 | /* See utils/TRANSFORMATIONS.txt for how transformations are applied */ | 116 | /* See doc/TRANSFORMATIONS.md for how transformations are applied */ |
| 32 | cube_t transform(cube_t, trans_t); | 117 | cube_t transform(cube_t, trans_t); |
diff --git a/src/cube_array.h b/src/cube_array.h deleted file mode 100644 index 6d9603b..0000000 --- a/src/cube_array.h +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | /* Public properties specific to the array implementation */ | ||
| 2 | |||
| 3 | typedef struct { | ||
| 4 | uint8_t c[8]; | ||
| 5 | uint8_t e[12]; | ||
| 6 | } cube_t; | ||
