diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2023-10-22 14:48:42 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2023-10-22 14:48:42 +0200 |
| commit | 0c49ed5afc2ae9e4bc4aa1af9c655bbe1f3d14b8 (patch) | |
| tree | 4e69457ed87cb06decc12889a1ded18c17610dad | |
| parent | 259c7326f78d5495f5dc51c619932599a5279f68 (diff) | |
| download | nissy-core-0c49ed5afc2ae9e4bc4aa1af9c655bbe1f3d14b8.tar.gz nissy-core-0c49ed5afc2ae9e4bc4aa1af9c655bbe1f3d14b8.zip | |
Small change of plans, moved stuff around
Diffstat (limited to '')
| -rw-r--r-- | doc/CUBE_INTERNAL.md | 24 | ||||
| -rw-r--r-- | doc/CUBE_TEXT.md (renamed from utils/FORMAT.txt) | 6 | ||||
| -rw-r--r-- | doc/TRANSFORMATIONS.md (renamed from utils/TRANSFORMATIONS.txt) | 0 | ||||
| -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 | ||||
| -rw-r--r-- | test/05_transform/transform_tests.c | 1 | ||||
| -rwxr-xr-x | test/test.sh | 2 |
9 files changed, 118 insertions, 109 deletions
diff --git a/doc/CUBE_INTERNAL.md b/doc/CUBE_INTERNAL.md new file mode 100644 index 0000000..fd3148a --- /dev/null +++ b/doc/CUBE_INTERNAL.md | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | # Internal representation of the cube | ||
| 2 | |||
| 3 | The plan (TODO) is to have multiple implementations: some that | ||
| 4 | take advantage of advanced CPU instructions (SIMD) and a fallback | ||
| 5 | "array" representation that works on any architecture. | ||
| 6 | |||
| 7 | # Array representation (fallback) | ||
| 8 | |||
| 9 | In this implementation of the cube.h interface, the cube is represented | ||
| 10 | by two arrays of 8-bit unsigned integers, one for centers and one for | ||
| 11 | corners. The 4 leas-significant digits of each bit determine the piece, | ||
| 12 | the other 4 are used for orientation or kept to 0. | ||
| 13 | |||
| 14 | Edges: | ||
| 15 | xxxopppp (x = unused, o = orientation, p = piece) | ||
| 16 | |||
| 17 | Corners: | ||
| 18 | xooxpppp (x = unused, o = orientation, p = piece) | ||
| 19 | |||
| 20 | The two bits for CO are shifted to make it possible to perform mod 3 | ||
| 21 | operations (sum, inverse) using only addition and bitwise operators. | ||
| 22 | See below for details. | ||
| 23 | |||
| 24 | The third bit is needed because x+y+1 can exceed 4. | ||
diff --git a/utils/FORMAT.txt b/doc/CUBE_TEXT.md index 5bfb01e..b9234fc 100644 --- a/utils/FORMAT.txt +++ b/doc/CUBE_TEXT.md | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | # Textual representation of the cube | ||
| 2 | |||
| 1 | The functions readcube() and writecube() use different formats to read | 3 | The functions readcube() and writecube() use different formats to read |
| 2 | and write a cube to text. Not all formats are supported for both input | 4 | and write a cube to text. Not all formats are supported for both input |
| 3 | and output. | 5 | and output. |
| 4 | 6 | ||
| 5 | # H48 - standard format for h48 (read, write) | 7 | ## H48 - standard format for h48 (read, write) |
| 6 | 8 | ||
| 7 | Each edge is represented by two letters denoting the sides it belongs to | 9 | Each edge is represented by two letters denoting the sides it belongs to |
| 8 | and one number denoting its orientation (0 oriented, 1 mis-oriented). | 10 | and one number denoting its orientation (0 oriented, 1 mis-oriented). |
| @@ -25,7 +27,7 @@ The cube after the moves R'U'F looks like this: | |||
| 25 | FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0 | 27 | FL1 BR0 DB0 UR1 UF0 UB0 DL0 FR0 UL1 DF1 BL0 DR0 |
| 26 | UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0 | 28 | UBL1 DBR1 UFR2 DFR2 DFL2 UBL2 UFL2 DBL0 |
| 27 | 29 | ||
| 28 | # SRC - representation of the object in C code for cube_array (write) | 30 | ## SRC - representation of the object in C code for cube_array (write) |
| 29 | 31 | ||
| 30 | The exact format depends on the internal cube representation. It is | 32 | The exact format depends on the internal cube representation. It is |
| 31 | guaranteed that, if OUT is the output in this format, the line | 33 | guaranteed that, if OUT is the output in this format, the line |
diff --git a/utils/TRANSFORMATIONS.txt b/doc/TRANSFORMATIONS.md index 58446e8..58446e8 100644 --- a/utils/TRANSFORMATIONS.txt +++ b/doc/TRANSFORMATIONS.md | |||
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; | ||
diff --git a/test/05_transform/transform_tests.c b/test/05_transform/transform_tests.c index c648662..1e49037 100644 --- a/test/05_transform/transform_tests.c +++ b/test/05_transform/transform_tests.c | |||
| @@ -3,7 +3,6 @@ | |||
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | 4 | ||
| 5 | #include "../../src/cube.h" | 5 | #include "../../src/cube.h" |
| 6 | #include "../../src/constants.h" | ||
| 7 | 6 | ||
| 8 | #define STRLENMAX 10000 | 7 | #define STRLENMAX 10000 |
| 9 | 8 | ||
diff --git a/test/test.sh b/test/test.sh index 9eae127..00dd5ce 100755 --- a/test/test.sh +++ b/test/test.sh | |||
| @@ -5,7 +5,7 @@ CC="cc -DDEBUG -std=c99 -pthread -pedantic -Wall -Wextra \ | |||
| 5 | if [ $(uname) != "OpenBSD" ]; then | 5 | if [ $(uname) != "OpenBSD" ]; then |
| 6 | CC="$CC -fsanitize=address -fsanitize=undefined" | 6 | CC="$CC -fsanitize=address -fsanitize=undefined" |
| 7 | fi | 7 | fi |
| 8 | SRC="src/cube_array.c" | 8 | SRC="src/cube.c" |
| 9 | TESTBIN="test/run" | 9 | TESTBIN="test/run" |
| 10 | TESTOUT="test/last.out" | 10 | TESTOUT="test/last.out" |
| 11 | TESTERR="test/last.err" | 11 | TESTERR="test/last.err" |
