From 18c9a8b8905304cf5f8fc15825769046a3144866 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 18 Aug 2024 14:26:45 +0200 Subject: Reorganized folder structure --- src/core/constant_cubes.h | 229 ++++++++++++++++++++++++++ src/core/core.h | 13 ++ src/core/cube.h | 291 ++++++++++++++++++++++++++++++++ src/core/io_cube.h | 348 +++++++++++++++++++++++++++++++++++++++ src/core/io_moves.h | 62 +++++++ src/core/io_trans.h | 25 +++ src/core/moves.h | 47 ++++++ src/core/transform.h | 176 ++++++++++++++++++++ src/core/transform_with_switch.h | 336 +++++++++++++++++++++++++++++++++++++ 9 files changed, 1527 insertions(+) create mode 100644 src/core/constant_cubes.h create mode 100644 src/core/core.h create mode 100644 src/core/cube.h create mode 100644 src/core/io_cube.h create mode 100644 src/core/io_moves.h create mode 100644 src/core/io_trans.h create mode 100644 src/core/moves.h create mode 100644 src/core/transform.h create mode 100644 src/core/transform_with_switch.h (limited to 'src/core') diff --git a/src/core/constant_cubes.h b/src/core/constant_cubes.h new file mode 100644 index 0000000..b7748d8 --- /dev/null +++ b/src/core/constant_cubes.h @@ -0,0 +1,229 @@ +#define _move_cube_U static_cube( \ + 5, 4, 2, 3, 0, 1, 6, 7, 4, 5, 2, 3, 1, 0, 6, 7, 8, 9, 10, 11) +#define _move_cube_U2 static_cube( \ + 1, 0, 2, 3, 5, 4, 6, 7, 1, 0, 2, 3, 5, 4, 6, 7, 8, 9, 10, 11) +#define _move_cube_U3 static_cube( \ + 4, 5, 2, 3, 1, 0, 6, 7, 5, 4, 2, 3, 0, 1, 6, 7, 8, 9, 10, 11) +#define _move_cube_D static_cube( \ + 0, 1, 7, 6, 4, 5, 2, 3, 0, 1, 7, 6, 4, 5, 2, 3, 8, 9, 10, 11) +#define _move_cube_D2 static_cube( \ + 0, 1, 3, 2, 4, 5, 7, 6, 0, 1, 3, 2, 4, 5, 7, 6, 8, 9, 10, 11) +#define _move_cube_D3 static_cube( \ + 0, 1, 6, 7, 4, 5, 3, 2, 0, 1, 6, 7, 4, 5, 3, 2, 8, 9, 10, 11) +#define _move_cube_R static_cube( \ + 70, 1, 2, 69, 4, 32, 35, 7, 0, 1, 2, 3, 8, 5, 6, 11, 7, 9, 10, 4) +#define _move_cube_R2 static_cube( \ + 3, 1, 2, 0, 4, 6, 5, 7, 0, 1, 2, 3, 7, 5, 6, 4, 11, 9, 10, 8) +#define _move_cube_R3 static_cube( \ + 69, 1, 2, 70, 4, 35, 32, 7, 0, 1, 2, 3, 11, 5, 6, 8, 4, 9, 10, 7) +#define _move_cube_L static_cube( \ + 0, 71, 68, 3, 33, 5, 6, 34, 0, 1, 2, 3, 4, 10, 9, 7, 8, 5, 6, 11) +#define _move_cube_L2 static_cube( \ + 0, 2, 1, 3, 7, 5, 6, 4, 0, 1, 2, 3, 4, 6, 5, 7, 8, 10, 9, 11) +#define _move_cube_L3 static_cube( \ + 0, 68, 71, 3, 34, 5, 6, 33, 0, 1, 2, 3, 4, 9, 10, 7, 8, 6, 5, 11) +#define _move_cube_F static_cube( \ + 36, 1, 38, 3, 66, 5, 64, 7, 25, 1, 2, 24, 4, 5, 6, 7, 16, 19, 10, 11) +#define _move_cube_F2 static_cube( \ + 2, 1, 0, 3, 6, 5, 4, 7, 3, 1, 2, 0, 4, 5, 6, 7, 9, 8, 10, 11) +#define _move_cube_F3 static_cube( \ + 38, 1, 36, 3, 64, 5, 66, 7, 24, 1, 2, 25, 4, 5, 6, 7, 19, 16, 10, 11) +#define _move_cube_B static_cube( \ + 0, 37, 2, 39, 4, 67, 6, 65, 0, 27, 26, 3, 4, 5, 6, 7, 8, 9, 17, 18) +#define _move_cube_B2 static_cube( \ + 0, 3, 2, 1, 4, 7, 6, 5, 0, 2, 1, 3, 4, 5, 6, 7, 8, 9, 11, 10) +#define _move_cube_B3 static_cube( \ + 0, 39, 2, 37, 4, 65, 6, 67, 0, 26, 27, 3, 4, 5, 6, 7, 8, 9, 18, 17) + +#define _trans_cube_UFr static_cube( \ + 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) +#define _trans_cube_UFr_inverse static_cube( \ + 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) +#define _trans_cube_ULr static_cube( \ + 4, 5, 7, 6, 1, 0, 2, 3, 5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24) +#define _trans_cube_ULr_inverse static_cube( \ + 5, 4, 6, 7, 0, 1, 3, 2, 4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26) +#define _trans_cube_UBr static_cube( \ + 1, 0, 3, 2, 5, 4, 7, 6, 1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9) +#define _trans_cube_UBr_inverse static_cube( \ + 1, 0, 3, 2, 5, 4, 7, 6, 1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9) +#define _trans_cube_URr static_cube( \ + 5, 4, 6, 7, 0, 1, 3, 2, 4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26) +#define _trans_cube_URr_inverse static_cube( \ + 4, 5, 7, 6, 1, 0, 2, 3, 5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24) +#define _trans_cube_DFr static_cube( \ + 2, 3, 0, 1, 6, 7, 4, 5, 3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10) +#define _trans_cube_DFr_inverse static_cube( \ + 2, 3, 0, 1, 6, 7, 4, 5, 3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10) +#define _trans_cube_DLr static_cube( \ + 7, 6, 4, 5, 2, 3, 1, 0, 6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27) +#define _trans_cube_DLr_inverse static_cube( \ + 7, 6, 4, 5, 2, 3, 1, 0, 6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27) +#define _trans_cube_DBr static_cube( \ + 3, 2, 1, 0, 7, 6, 5, 4, 2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8) +#define _trans_cube_DBr_inverse static_cube( \ + 3, 2, 1, 0, 7, 6, 5, 4, 2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8) +#define _trans_cube_DRr static_cube( \ + 6, 7, 5, 4, 3, 2, 0, 1, 7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25) +#define _trans_cube_DRr_inverse static_cube( \ + 6, 7, 5, 4, 3, 2, 0, 1, 7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25) +#define _trans_cube_RUr static_cube( \ + 64, 67, 65, 66, 37, 38, 36, 39, 20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3) +#define _trans_cube_RUr_inverse static_cube( \ + 32, 34, 35, 33, 70, 68, 69, 71, 8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21) +#define _trans_cube_RFr static_cube( \ + 38, 37, 36, 39, 64, 67, 66, 65, 24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18) +#define _trans_cube_RFr_inverse static_cube( \ + 36, 39, 38, 37, 66, 65, 64, 67, 25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17) +#define _trans_cube_RDr static_cube( \ + 67, 64, 66, 65, 38, 37, 39, 36, 23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1) +#define _trans_cube_RDr_inverse static_cube( \ + 33, 35, 34, 32, 71, 69, 68, 70, 10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20) +#define _trans_cube_RBr static_cube( \ + 37, 38, 39, 36, 67, 64, 65, 66, 27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16) +#define _trans_cube_RBr_inverse static_cube( \ + 37, 38, 39, 36, 67, 64, 65, 66, 27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16) +#define _trans_cube_LUr static_cube( \ + 65, 66, 64, 67, 36, 39, 37, 38, 21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2) +#define _trans_cube_LUr_inverse static_cube( \ + 34, 32, 33, 35, 68, 70, 71, 69, 9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23) +#define _trans_cube_LFr static_cube( \ + 36, 39, 38, 37, 66, 65, 64, 67, 25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17) +#define _trans_cube_LFr_inverse static_cube( \ + 38, 37, 36, 39, 64, 67, 66, 65, 24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18) +#define _trans_cube_LDr static_cube( \ + 66, 65, 67, 64, 39, 36, 38, 37, 22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0) +#define _trans_cube_LDr_inverse static_cube( \ + 35, 33, 32, 34, 69, 71, 70, 68, 11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22) +#define _trans_cube_LBr static_cube( \ + 39, 36, 37, 38, 65, 66, 67, 64, 26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19) +#define _trans_cube_LBr_inverse static_cube( \ + 39, 36, 37, 38, 65, 66, 67, 64, 26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19) +#define _trans_cube_FUr static_cube( \ + 68, 70, 69, 71, 32, 34, 33, 35, 16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6) +#define _trans_cube_FUr_inverse static_cube( \ + 68, 70, 69, 71, 32, 34, 33, 35, 16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6) +#define _trans_cube_FRr static_cube( \ + 32, 34, 35, 33, 70, 68, 69, 71, 8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21) +#define _trans_cube_FRr_inverse static_cube( \ + 64, 67, 65, 66, 37, 38, 36, 39, 20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3) +#define _trans_cube_FDr static_cube( \ + 70, 68, 71, 69, 34, 32, 35, 33, 19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4) +#define _trans_cube_FDr_inverse static_cube( \ + 69, 71, 68, 70, 33, 35, 32, 34, 17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7) +#define _trans_cube_FLr static_cube( \ + 34, 32, 33, 35, 68, 70, 71, 69, 9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23) +#define _trans_cube_FLr_inverse static_cube( \ + 65, 66, 64, 67, 36, 39, 37, 38, 21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2) +#define _trans_cube_BUr static_cube( \ + 69, 71, 68, 70, 33, 35, 32, 34, 17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7) +#define _trans_cube_BUr_inverse static_cube( \ + 70, 68, 71, 69, 34, 32, 35, 33, 19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4) +#define _trans_cube_BRr static_cube( \ + 35, 33, 32, 34, 69, 71, 70, 68, 11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22) +#define _trans_cube_BRr_inverse static_cube( \ + 66, 65, 67, 64, 39, 36, 38, 37, 22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0) +#define _trans_cube_BDr static_cube( \ + 71, 69, 70, 68, 35, 33, 34, 32, 18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5) +#define _trans_cube_BDr_inverse static_cube( \ + 71, 69, 70, 68, 35, 33, 34, 32, 18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5) +#define _trans_cube_BLr static_cube( \ + 33, 35, 34, 32, 71, 69, 68, 70, 10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20) +#define _trans_cube_BLr_inverse static_cube( \ + 67, 64, 66, 65, 38, 37, 39, 36, 23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1) +#define _trans_cube_UFm static_cube( \ + 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10) +#define _trans_cube_UFm_inverse static_cube( \ + 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10) +#define _trans_cube_ULm static_cube( \ + 0, 1, 3, 2, 5, 4, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25) +#define _trans_cube_ULm_inverse static_cube( \ + 0, 1, 3, 2, 5, 4, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25) +#define _trans_cube_UBm static_cube( \ + 5, 4, 7, 6, 1, 0, 3, 2, 1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8) +#define _trans_cube_UBm_inverse static_cube( \ + 5, 4, 7, 6, 1, 0, 3, 2, 1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8) +#define _trans_cube_URm static_cube( \ + 1, 0, 2, 3, 4, 5, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27) +#define _trans_cube_URm_inverse static_cube( \ + 1, 0, 2, 3, 4, 5, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27) +#define _trans_cube_DFm static_cube( \ + 6, 7, 4, 5, 2, 3, 0, 1, 3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11) +#define _trans_cube_DFm_inverse static_cube( \ + 6, 7, 4, 5, 2, 3, 0, 1, 3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11) +#define _trans_cube_DLm static_cube( \ + 3, 2, 0, 1, 6, 7, 5, 4, 7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26) +#define _trans_cube_DLm_inverse static_cube( \ + 2, 3, 1, 0, 7, 6, 4, 5, 6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24) +#define _trans_cube_DBm static_cube( \ + 7, 6, 5, 4, 3, 2, 1, 0, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9) +#define _trans_cube_DBm_inverse static_cube( \ + 7, 6, 5, 4, 3, 2, 1, 0, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9) +#define _trans_cube_DRm static_cube( \ + 2, 3, 1, 0, 7, 6, 4, 5, 6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24) +#define _trans_cube_DRm_inverse static_cube( \ + 3, 2, 0, 1, 6, 7, 5, 4, 7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26) +#define _trans_cube_RUm static_cube( \ + 68, 71, 69, 70, 33, 34, 32, 35, 21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3) +#define _trans_cube_RUm_inverse static_cube( \ + 70, 68, 69, 71, 32, 34, 35, 33, 8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22) +#define _trans_cube_RFm static_cube( \ + 34, 33, 32, 35, 68, 71, 70, 69, 25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18) +#define _trans_cube_RFm_inverse static_cube( \ + 66, 65, 64, 67, 36, 39, 38, 37, 25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18) +#define _trans_cube_RDm static_cube( \ + 71, 68, 70, 69, 34, 33, 35, 32, 22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1) +#define _trans_cube_RDm_inverse static_cube( \ + 71, 69, 68, 70, 33, 35, 34, 32, 10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23) +#define _trans_cube_RBm static_cube( \ + 33, 34, 35, 32, 71, 68, 69, 70, 26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16) +#define _trans_cube_RBm_inverse static_cube( \ + 67, 64, 65, 66, 37, 38, 39, 36, 27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19) +#define _trans_cube_LUm static_cube( \ + 69, 70, 68, 71, 32, 35, 33, 34, 20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2) +#define _trans_cube_LUm_inverse static_cube( \ + 68, 70, 71, 69, 34, 32, 33, 35, 9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20) +#define _trans_cube_LFm static_cube( \ + 32, 35, 34, 33, 70, 69, 68, 71, 24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17) +#define _trans_cube_LFm_inverse static_cube( \ + 64, 67, 66, 65, 38, 37, 36, 39, 24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17) +#define _trans_cube_LDm static_cube( \ + 70, 69, 71, 68, 35, 32, 34, 33, 23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0) +#define _trans_cube_LDm_inverse static_cube( \ + 69, 71, 70, 68, 35, 33, 32, 34, 11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21) +#define _trans_cube_LBm static_cube( \ + 35, 32, 33, 34, 69, 70, 71, 68, 27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19) +#define _trans_cube_LBm_inverse static_cube( \ + 65, 66, 67, 64, 39, 36, 37, 38, 26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16) +#define _trans_cube_FUm static_cube( \ + 64, 66, 65, 67, 36, 38, 37, 39, 16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7) +#define _trans_cube_FUm_inverse static_cube( \ + 32, 34, 33, 35, 68, 70, 69, 71, 16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7) +#define _trans_cube_FRm static_cube( \ + 36, 38, 39, 37, 66, 64, 65, 67, 9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20) +#define _trans_cube_FRm_inverse static_cube( \ + 37, 38, 36, 39, 64, 67, 65, 66, 20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2) +#define _trans_cube_FDm static_cube( \ + 66, 64, 67, 65, 38, 36, 39, 37, 19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5) +#define _trans_cube_FDm_inverse static_cube( \ + 33, 35, 32, 34, 69, 71, 68, 70, 17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6) +#define _trans_cube_FLm static_cube( \ + 38, 36, 37, 39, 64, 66, 67, 65, 8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22) +#define _trans_cube_FLm_inverse static_cube( \ + 36, 39, 37, 38, 65, 66, 64, 67, 21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3) +#define _trans_cube_BUm static_cube( \ + 65, 67, 64, 66, 37, 39, 36, 38, 17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6) +#define _trans_cube_BUm_inverse static_cube( \ + 34, 32, 35, 33, 70, 68, 71, 69, 19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5) +#define _trans_cube_BRm static_cube( \ + 39, 37, 36, 38, 65, 67, 66, 64, 10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23) +#define _trans_cube_BRm_inverse static_cube( \ + 39, 36, 38, 37, 66, 65, 67, 64, 22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1) +#define _trans_cube_BDm static_cube( \ + 67, 65, 66, 64, 39, 37, 38, 36, 18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4) +#define _trans_cube_BDm_inverse static_cube( \ + 35, 33, 34, 32, 71, 69, 70, 68, 18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4) +#define _trans_cube_BLm static_cube( \ + 37, 39, 38, 36, 67, 65, 64, 66, 11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21) +#define _trans_cube_BLm_inverse static_cube( \ + 38, 37, 39, 36, 67, 64, 66, 65, 23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0) diff --git a/src/core/core.h b/src/core/core.h new file mode 100644 index 0000000..6ffd76f --- /dev/null +++ b/src/core/core.h @@ -0,0 +1,13 @@ +#include "constant_cubes.h" +#include "io_moves.h" +#include "io_trans.h" +#include "cube.h" +#include "io_cube.h" +#include "moves.h" + +/* TODO: work in progress */ +#if 0 +#include "transform.h" +#else +#include "transform_with_switch.h" +#endif diff --git a/src/core/cube.h b/src/core/cube.h new file mode 100644 index 0000000..fe36f90 --- /dev/null +++ b/src/core/cube.h @@ -0,0 +1,291 @@ +#define _move(M, c) compose(c, _move_cube_ ## M) +#define _premove(M, c) compose(_move_cube_ ## M, c) + +_static cube_t cubefromarray(uint8_t [static 8], uint8_t [static 12]); +_static cube_t solvedcube(void); +_static bool isconsistent(cube_t); +_static bool issolvable(cube_t); +_static bool issolved(cube_t); +_static bool iserror(cube_t); +_static cube_t applymoves(cube_t, const char *); +_static cube_t applytrans(cube_t, const char *); +_static cube_t frommoves(const char *); +_static void getcube_fix(int64_t *, int64_t *, int64_t *, int64_t *); +_static cube_t getcube(int64_t, int64_t, int64_t, int64_t); + +_static cube_t move(cube_t, uint8_t); +_static cube_t transform_edges(cube_t, uint8_t); +_static cube_t transform_corners(cube_t, uint8_t); +_static cube_t transform(cube_t, uint8_t); + +_static cube_t +cubefromarray(uint8_t c[static 8], uint8_t e[static 12]) +{ + return static_cube( + c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], + e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], + e[8], e[9], e[10], e[11]); +} + +_static cube_t +solvedcube(void) +{ + return solved; +} + +_static bool +isconsistent(cube_t cube) +{ + uint8_t i, p, e, piece, corner[8], edge[12]; + bool found[12]; + + pieces(&cube, corner, edge); + + for (i = 0; i < 12; i++) + found[i] = false; + for (i = 0; i < 12; i++) { + piece = edge[i]; + p = piece & _pbits; + e = piece & _eobit; + if (p >= 12) + goto inconsistent_ep; + if (e != 0 && e != _eobit) + goto inconsistent_eo; + found[p] = true; + } + for (i = 0; i < 12; i++) + if (!found[i]) + goto inconsistent_ep; + + for (i = 0; i < 8; i++) + found[i] = false; + for (i = 0; i < 8; i++) { + piece = corner[i]; + p = piece & _pbits; + e = piece & _cobits; + if (p >= 8) + goto inconsistent_cp; + if (e != 0 && e != _ctwist_cw && e != _ctwist_ccw) + goto inconsistent_co; + found[p] = true; + } + for (i = 0; i < 8; i++) + if (!found[i]) + goto inconsistent_co; + + return true; + +inconsistent_ep: + LOG("Inconsistent EP\n"); + return false; +inconsistent_cp: + LOG("Inconsistent CP\n"); + return false; +inconsistent_eo: + LOG("Inconsistent EO\n"); + return false; +inconsistent_co: + LOG("Inconsistent CO\n"); + return false; +} + +_static bool +issolvable(cube_t cube) +{ + uint8_t i, eo, co, piece, edge[12], corner[8], ep[12], cp[8]; + + DBG_ASSERT(isconsistent(cube), false, + "issolvable: cube is inconsistent\n"); + + pieces(&cube, corner, edge); + for (i = 0; i < 12; i++) + ep[i] = edge[i] & _pbits; + for (i = 0; i < 8; i++) + cp[i] = corner[i] & _pbits; + + if (permsign(ep, 12) != permsign(cp, 8)) + goto issolvable_parity; + + eo = 0; + for (i = 0; i < 12; i++) { + piece = edge[i]; + eo += (piece & _eobit) >> _eoshift; + } + if (eo % 2 != 0) + goto issolvable_eo; + + co = 0; + for (i = 0; i < 8; i++) { + piece = corner[i]; + co += (piece & _cobits) >> _coshift; + } + if (co % 3 != 0) + goto issolvable_co; + + return true; + +issolvable_parity: + LOG("EP and CP parities are different\n"); + return false; +issolvable_eo: + LOG("Odd number of flipped edges\n"); + return false; +issolvable_co: + LOG("Sum of corner orientation is not multiple of 3\n"); + return false; +} + +bool +issolved(cube_t cube) +{ + return equal(cube, solved); +} + +bool +iserror(cube_t cube) +{ + return equal(cube, zero); +} + +_static cube_t +applymoves(cube_t cube, const char *buf) +{ + uint8_t r, m; + const char *b; + + DBG_ASSERT(isconsistent(cube), zero, + "move error: inconsistent cube\n"); + + for (b = buf; *b != '\0'; b++) { + while (*b == ' ' || *b == '\t' || *b == '\n') + b++; + if (*b == '\0') + goto applymoves_finish; + if ((r = readmove(*b)) == _error) + goto applymoves_error; + if ((m = readmodifier(*(b+1))) != 0) + b++; + cube = move(cube, r + m); + } + +applymoves_finish: + return cube; + +applymoves_error: + LOG("applymoves error\n"); + return zero; +} + +_static cube_t +frommoves(const char *buf) +{ + return applymoves(solved, buf); +} + +_static void +getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) +{ + uint8_t e[12], c[8], coarr[8]; + + *ep = (*ep % _12f + _12f) % _12f; + *eo = (*eo % _2p11 + _2p11) % _2p11; + *cp = (*cp % _8f + _8f) % _8f; + *co = (*cp % _3p7 + _3p7) % _3p7; + + indextoperm(*ep, 12, e); + indextoperm(*cp, 8, c); + if (permsign(e, 12) != permsign(c, 8)) { + _swap(c[0], c[1]); + *cp = permtoindex(c, 8); + + sumzerotodigits(*co, 8, 3, coarr); + _swap(coarr[0], coarr[1]); + *co = digitstosumzero(coarr, 8, 3); + } +} + +_static cube_t +getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co) +{ + uint8_t i, earr[12], carr[8], eoarr[12], coarr[8]; + + sumzerotodigits(eo, 12, 2, eoarr); + DBG_ASSERT(eoarr[0] != _error, zero, "Error making EO"); + indextoperm(ep, 12, earr); + DBG_ASSERT(earr[0] != _error, zero, "Error making EP"); + for (i = 0; i < 12; i++) + earr[i] |= eoarr[i] << _eoshift; + + sumzerotodigits(co, 8, 3, coarr); + DBG_ASSERT(coarr[0] != _error, zero, "Error making CO"); + indextoperm(cp, 8, carr); + DBG_ASSERT(carr[0] != _error, zero, "Error making CP"); + for (i = 0; i < 8; i++) + carr[i] |= coarr[i] << _coshift; + + return cubefromarray(carr, earr); +} + +_static cube_t +applytrans(cube_t cube, const char *buf) +{ + uint8_t t; + + DBG_ASSERT(isconsistent(cube), zero, + "transformation error: inconsistent cube\n"); + + t = readtrans(buf); + + return transform(cube, t); +} + +_static cube_t +move(cube_t c, uint8_t m) +{ + switch (m) { + case _move_U: + return _move(U, c); + case _move_U2: + return _move(U2, c); + case _move_U3: + return _move(U3, c); + case _move_D: + return _move(D, c); + case _move_D2: + return _move(D2, c); + case _move_D3: + return _move(D3, c); + case _move_R: + return _move(R, c); + case _move_R2: + return _move(R2, c); + case _move_R3: + return _move(R3, c); + case _move_L: + return _move(L, c); + case _move_L2: + return _move(L2, c); + case _move_L3: + return _move(L3, c); + case _move_F: + return _move(F, c); + case _move_F2: + return _move(F2, c); + case _move_F3: + return _move(F3, c); + case _move_B: + return _move(B, c); + case _move_B2: + return _move(B2, c); + case _move_B3: + return _move(B3, c); + default: + LOG("move error, unknown move\n"); + return zero; + } +} + +/* +TODO transform is now relegated to a separated file because it is too long. +It would be nice to make it shorter without loosing performance. +*/ diff --git a/src/core/io_cube.h b/src/core/io_cube.h new file mode 100644 index 0000000..956494d --- /dev/null +++ b/src/core/io_cube.h @@ -0,0 +1,348 @@ +_static uint8_t readco(const char *); +_static uint8_t readcp(const char *); +_static uint8_t readeo(const char *); +_static uint8_t readep(const char *); +_static cube_t readcube_B32(const char *); +_static cube_t readcube_H48(const char *); +_static uint8_t readpiece_LST(const char **); +_static cube_t readcube_LST(const char *); + +_static int writepiece_LST(uint8_t, char *); +_static void writecube_B32(cube_t, char *); +_static void writecube_H48(cube_t, char *); +_static void writecube_LST(cube_t, char *); + +_static uint8_t b32toedge(char); +_static uint8_t b32tocorner(char); +_static char edgetob32(uint8_t); +_static char cornertob32(uint8_t); + +_static struct { + const char *name; + cube_t (*read)(const char *); + void (*write)(cube_t, char *); +} ioformat[] = +{ + { .name = "B32", .read = readcube_B32, .write = writecube_B32 }, + { .name = "LST", .read = readcube_LST, .write = writecube_LST }, + { .name = "H48", .read = readcube_H48, .write = writecube_H48 }, + { .name = "NONE", .read = NULL, .write = NULL }, +}; + +cube_t +readcube(const char *format, const char *buf) +{ + int i; + + for (i = 0; ioformat[i].read != NULL; i++) + if (!strcmp(format, ioformat[i].name)) + return ioformat[i].read(buf); + + LOG("Cannot read cube in the given format\n"); + return zero; +} + +void +writecube(const char *format, cube_t cube, char *buf) +{ + char *errormsg; + size_t len; + + if (!isconsistent(cube)) { + errormsg = "ERROR: inconsistent"; + goto writecube_error; + } + + int i; + + for (i = 0; ioformat[i].write != NULL; i++) { + if (!strcmp(format, ioformat[i].name)) { + ioformat[i].write(cube, buf); + return; + } + } + + errormsg = "ERROR: format"; + +writecube_error: + LOG("writecube error, see stdout for details\n"); + len = strlen(errormsg); + memcpy(buf, errormsg, len); + buf[len] = '\n'; + buf[len+1] = '\0'; +} + +_static uint8_t +readco(const char *str) +{ + if (*str == '0') + return 0; + if (*str == '1') + return _ctwist_cw; + if (*str == '2') + return _ctwist_ccw; + + LOG("Error reading CO\n"); + return _error; +} + +_static uint8_t +readcp(const char *str) +{ + uint8_t c; + + for (c = 0; c < 8; c++) + if (!strncmp(str, cornerstr[c], 3) || + !strncmp(str, cornerstralt[c], 3)) + return c; + + LOG("Error reading CP\n"); + return _error; +} + +_static uint8_t +readeo(const char *str) +{ + if (*str == '0') + return 0; + if (*str == '1') + return _eflip; + + LOG("Error reading EO\n"); + return _error; +} + +_static uint8_t +readep(const char *str) +{ + uint8_t e; + + for (e = 0; e < 12; e++) + if (!strncmp(str, edgestr[e], 2)) + return e; + + LOG("Error reading EP\n"); + return _error; +} + +_static cube_t +readcube_B32(const char *buf) +{ + int i; + uint8_t c[8], e[12]; + + for (i = 0; i < 8; i++) { + c[i] = b32tocorner(buf[i]); + DBG_ASSERT(c[i] < 255, zero, + "Error reading B32 corner %d (char %d)\n", i, i); + } + + for (i = 0; i < 12; i++) { + e[i] = b32toedge(buf[i+9]); + DBG_ASSERT(e[i] < 255, zero, + "Error reading B32 edge %d (char %d)\n", i, i+9); + } + + return cubefromarray(c, e); +} + +_static cube_t +readcube_H48(const char *buf) +{ + int i; + uint8_t piece, orient, c[8], e[12]; + const char *b; + + b = buf; + + for (i = 0; i < 12; i++) { + while (*b == ' ' || *b == '\t' || *b == '\n') + b++; + if ((piece = readep(b)) == _error) + return zero; + b += 2; + if ((orient = readeo(b)) == _error) + return zero; + b++; + e[i] = piece | orient; + } + for (i = 0; i < 8; i++) { + while (*b == ' ' || *b == '\t' || *b == '\n') + b++; + if ((piece = readcp(b)) == _error) + return zero; + b += 3; + if ((orient = readco(b)) == _error) + return zero; + b++; + c[i] = piece | orient; + } + + return cubefromarray(c, e); +} + +_static uint8_t +readpiece_LST(const char **b) +{ + uint8_t ret; + bool read; + + while (**b == ',' || **b == ' ' || **b == '\t' || **b == '\n') + (*b)++; + + for (ret = 0, read = false; **b >= '0' && **b <= '9'; (*b)++) { + read = true; + ret = ret * 10 + (**b) - '0'; + } + + return read ? ret : _error; +} + +_static cube_t +readcube_LST(const char *buf) +{ + int i; + uint8_t c[8], e[12]; + + for (i = 0; i < 8; i++) + c[i] = readpiece_LST(&buf); + + for (i = 0; i < 12; i++) + e[i] = readpiece_LST(&buf); + + return cubefromarray(c, e); +} + +_static int +writepiece_LST(uint8_t piece, char *buf) +{ + char digits[3]; + int i, len; + + len = 0; + while (piece != 0) { + digits[len++] = (piece % 10) + '0'; + piece /= 10; + } + + if (len == 0) + digits[len++] = '0'; + + for (i = 0; i < len; i++) + buf[i] = digits[len-i-1]; + + buf[len] = ','; + buf[len+1] = ' '; + + return len+2; +} + +_static void +writecube_B32(cube_t cube, char *buf) +{ + int i; + uint8_t corner[8], edge[12]; + + pieces(&cube, corner, edge); + + for (i = 0; i < 8; i++) + buf[i] = cornertob32(corner[i]); + + buf[8] = '='; + + for (i = 0; i < 12; i++) + buf[i+9] = edgetob32(edge[i]); + + buf[21] = '\0'; +} + +_static void +writecube_H48(cube_t cube, char *buf) +{ + uint8_t piece, perm, orient, corner[8], edge[12]; + int i; + + pieces(&cube, corner, edge); + + for (i = 0; i < 12; i++) { + piece = edge[i]; + perm = piece & _pbits; + orient = (piece & _eobit) >> _eoshift; + buf[4*i ] = edgestr[perm][0]; + buf[4*i + 1] = edgestr[perm][1]; + buf[4*i + 2] = orient + '0'; + buf[4*i + 3] = ' '; + } + for (i = 0; i < 8; i++) { + piece = corner[i]; + perm = piece & _pbits; + orient = (piece & _cobits) >> _coshift; + buf[48 + 5*i ] = cornerstr[perm][0]; + buf[48 + 5*i + 1] = cornerstr[perm][1]; + buf[48 + 5*i + 2] = cornerstr[perm][2]; + buf[48 + 5*i + 3] = orient + '0'; + buf[48 + 5*i + 4] = ' '; + } + + buf[48+39] = '\0'; +} + +_static void +writecube_LST(cube_t cube, char *buf) +{ + int i; + size_t ptr; + uint8_t piece, corner[8], edge[12]; + + ptr = 0; + pieces(&cube, corner, edge); + + for (i = 0; i < 8; i++) { + piece = corner[i]; + ptr += writepiece_LST(piece, buf + ptr); + } + + for (i = 0; i < 12; i++) { + piece = edge[i]; + ptr += writepiece_LST(piece, buf + ptr); + } + + *(buf+ptr-2) = 0; +} + +_static uint8_t +b32toedge(char c) +{ + if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) + return 255; + + return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; +} + +_static uint8_t +b32tocorner(char c) { + uint8_t val; + + if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) + return 255; + + val = c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; + + return (val & 7) | ((val & 24) << 2); +} + +_static char +edgetob32(uint8_t edge) +{ + return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26); +} + +_static char +cornertob32(uint8_t corner) +{ + uint8_t val; + + val = (corner & 7) | ((corner & 96) >> 2); + + return val < 26 ? 'A' + (char)val : 'a' + (char)(val - 26); +} diff --git a/src/core/io_moves.h b/src/core/io_moves.h new file mode 100644 index 0000000..eb6290e --- /dev/null +++ b/src/core/io_moves.h @@ -0,0 +1,62 @@ +_static uint8_t readmove(char); +_static uint8_t readmodifier(char); +_static int writemoves(uint8_t *, int, char *); + +_static uint8_t +readmove(char c) +{ + switch (c) { + case 'U': + return _move_U; + case 'D': + return _move_D; + case 'R': + return _move_R; + case 'L': + return _move_L; + case 'F': + return _move_F; + case 'B': + return _move_B; + default: + return _error; + } +} + +_static uint8_t +readmodifier(char c) +{ + switch (c) { + case '1': /* Fallthrough */ + case '2': /* Fallthrough */ + case '3': + return c - '0' - 1; + case '\'': + return 2; + default: + return 0; + } +} + +_static int +writemoves(uint8_t *m, int n, char *buf) +{ + int i; + size_t len; + const char *s; + char *b; + + for (i = 0, b = buf; i < n; i++, b++) { + s = movestr[m[i]]; + len = strlen(s); + memcpy(b, s, len); + b += len; + *b = ' '; + } + + if (b != buf) + b--; /* Remove last space */ + *b = '\0'; + + return b - buf; +} diff --git a/src/core/io_trans.h b/src/core/io_trans.h new file mode 100644 index 0000000..7187b7a --- /dev/null +++ b/src/core/io_trans.h @@ -0,0 +1,25 @@ +_static uint8_t readtrans(const char *); +_static void writetrans(uint8_t, char *); + +_static uint8_t +readtrans(const char *buf) +{ + uint8_t t; + + for (t = 0; t < 48; t++) + if (!strncmp(buf, transstr[t], 11)) + return t; + + LOG("readtrans error\n"); + return _error; +} + +_static void +writetrans(uint8_t t, char *buf) +{ + if (t >= 48) + memcpy(buf, "error trans", 11); + else + memcpy(buf, transstr[t], 11); + buf[11] = '\0'; +} diff --git a/src/core/moves.h b/src/core/moves.h new file mode 100644 index 0000000..7da6405 --- /dev/null +++ b/src/core/moves.h @@ -0,0 +1,47 @@ +_static_inline bool allowednextmove(uint8_t *, uint8_t); +_static_inline uint8_t inverse_trans(uint8_t); +_static_inline uint8_t movebase(uint8_t); +_static_inline uint8_t moveaxis(uint8_t); + +_static bool +allowednextmove(uint8_t *moves, uint8_t n) +{ + uint8_t base[3], axis[3]; + + if (n < 2) + return true; + + base[0] = movebase(moves[n-1]); + axis[0] = moveaxis(moves[n-1]); + base[1] = movebase(moves[n-2]); + axis[1] = moveaxis(moves[n-2]); + + if (base[0] == base[1] || (axis[0] == axis[1] && base[0] < base[1])) + return false; + + if (n == 2) + return true; + + base[2] = movebase(moves[n-3]); + axis[2] = moveaxis(moves[n-3]); + + return axis[1] != axis[2] || base[0] != base[2]; +} + +_static_inline uint8_t +inverse_trans(uint8_t t) +{ + return inverse_trans_table[t]; +} + +_static_inline uint8_t +movebase(uint8_t move) +{ + return move / 3; +} + +_static_inline uint8_t +moveaxis(uint8_t move) +{ + return move / 6; +} diff --git a/src/core/transform.h b/src/core/transform.h new file mode 100644 index 0000000..358b051 --- /dev/null +++ b/src/core/transform.h @@ -0,0 +1,176 @@ +/* TODO: remove these macros, if the below works */ + +#define _trans_edges_rotation(T, c) \ + compose_edges(compose_edges(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse) +#define _trans_edges_mirrored(T, c) _trans_edges_rotation(T, c) + +#define _trans_corners_rotation(T, c) \ + compose_corners(compose_corners(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse) +#define _trans_corners_mirrored(T, c) \ + invertco(compose_corners( \ + compose_corners(_trans_cube_ ## T, c), _trans_cube_ ## T ## _inverse)) + +#define _trans_rotation(T, c) \ + compose(compose(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse) +#define _trans_mirrored(T, c) \ + invertco(compose(compose(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse)) + +static cube_t cube_trans_table[48] = { + [_trans_UFr] = _trans_cube_UFr, + [_trans_UFm] = _trans_cube_UFm, + [_trans_ULr] = _trans_cube_URr, + [_trans_ULm] = _trans_cube_ULm, + [_trans_UBr] = _trans_cube_UBr, + [_trans_UBm] = _trans_cube_UBm, + [_trans_URr] = _trans_cube_ULr, + [_trans_URm] = _trans_cube_URm, + [_trans_DFr] = _trans_cube_DFr, + [_trans_DFm] = _trans_cube_DFm, + [_trans_DLr] = _trans_cube_DLr, + [_trans_DLm] = _trans_cube_DRm, + [_trans_DBr] = _trans_cube_DBr, + [_trans_DBm] = _trans_cube_DBm, + [_trans_DRr] = _trans_cube_DRr, + [_trans_DRm] = _trans_cube_DLm, + [_trans_RUr] = _trans_cube_FRr, + [_trans_RUm] = _trans_cube_FLm, + [_trans_RFr] = _trans_cube_LFr, + [_trans_RFm] = _trans_cube_RFm, + [_trans_RDr] = _trans_cube_BLr, + [_trans_RDm] = _trans_cube_BRm, + [_trans_RBr] = _trans_cube_RBr, + [_trans_RBm] = _trans_cube_LBm, + [_trans_LUr] = _trans_cube_FLr, + [_trans_LUm] = _trans_cube_FRm, + [_trans_LFr] = _trans_cube_RFr, + [_trans_LFm] = _trans_cube_LFm, + [_trans_LDr] = _trans_cube_BRr, + [_trans_LDm] = _trans_cube_BLm, + [_trans_LBr] = _trans_cube_LBr, + [_trans_LBm] = _trans_cube_RBm, + [_trans_FUr] = _trans_cube_FUr, + [_trans_FUm] = _trans_cube_FUm, + [_trans_FRr] = _trans_cube_RUr, + [_trans_FRm] = _trans_cube_LUm, + [_trans_FDr] = _trans_cube_BUr, + [_trans_FDm] = _trans_cube_BUm, + [_trans_FLr] = _trans_cube_LUr, + [_trans_FLm] = _trans_cube_RUm, + [_trans_BUr] = _trans_cube_FDr, + [_trans_BUm] = _trans_cube_FDm, + [_trans_BRr] = _trans_cube_LDr, + [_trans_BRm] = _trans_cube_RDm, + [_trans_BDr] = _trans_cube_BDr, + [_trans_BDm] = _trans_cube_BDm, + [_trans_BLr] = _trans_cube_RDr, + [_trans_BLm] = _trans_cube_LDm, +}; + +static cube_t cube_trans_table_inverse[48] = { + [_trans_UFr] = _trans_cube_UFr_inverse, + [_trans_UFm] = _trans_cube_UFm_inverse, + [_trans_ULr] = _trans_cube_URr_inverse, + [_trans_ULm] = _trans_cube_ULm_inverse, + [_trans_UBr] = _trans_cube_UBr_inverse, + [_trans_UBm] = _trans_cube_UBm_inverse, + [_trans_URr] = _trans_cube_ULr_inverse, + [_trans_URm] = _trans_cube_URm_inverse, + [_trans_DFr] = _trans_cube_DFr_inverse, + [_trans_DFm] = _trans_cube_DFm_inverse, + [_trans_DLr] = _trans_cube_DLr_inverse, + [_trans_DLm] = _trans_cube_DRm_inverse, + [_trans_DBr] = _trans_cube_DBr_inverse, + [_trans_DBm] = _trans_cube_DBm_inverse, + [_trans_DRr] = _trans_cube_DRr_inverse, + [_trans_DRm] = _trans_cube_DLm_inverse, + [_trans_RUr] = _trans_cube_FRr_inverse, + [_trans_RUm] = _trans_cube_FLm_inverse, + [_trans_RFr] = _trans_cube_LFr_inverse, + [_trans_RFm] = _trans_cube_RFm_inverse, + [_trans_RDr] = _trans_cube_BLr_inverse, + [_trans_RDm] = _trans_cube_BRm_inverse, + [_trans_RBr] = _trans_cube_RBr_inverse, + [_trans_RBm] = _trans_cube_LBm_inverse, + [_trans_LUr] = _trans_cube_FLr_inverse, + [_trans_LUm] = _trans_cube_FRm_inverse, + [_trans_LFr] = _trans_cube_RFr_inverse, + [_trans_LFm] = _trans_cube_LFm_inverse, + [_trans_LDr] = _trans_cube_BRr_inverse, + [_trans_LDm] = _trans_cube_BLm_inverse, + [_trans_LBr] = _trans_cube_LBr_inverse, + [_trans_LBm] = _trans_cube_RBm_inverse, + [_trans_FUr] = _trans_cube_FUr_inverse, + [_trans_FUm] = _trans_cube_FUm_inverse, + [_trans_FRr] = _trans_cube_RUr_inverse, + [_trans_FRm] = _trans_cube_LUm_inverse, + [_trans_FDr] = _trans_cube_BUr_inverse, + [_trans_FDm] = _trans_cube_BUm_inverse, + [_trans_FLr] = _trans_cube_LUr_inverse, + [_trans_FLm] = _trans_cube_RUm_inverse, + [_trans_BUr] = _trans_cube_FDr_inverse, + [_trans_BUm] = _trans_cube_FDm_inverse, + [_trans_BRr] = _trans_cube_LDr_inverse, + [_trans_BRm] = _trans_cube_RDm_inverse, + [_trans_BDr] = _trans_cube_BDr_inverse, + [_trans_BDm] = _trans_cube_BDm_inverse, + [_trans_BLr] = _trans_cube_RDr_inverse, + [_trans_BLm] = _trans_cube_LDm_inverse, +}; + +_static cube_t +transform_edges(cube_t c, uint8_t t) +{ + cube_t ret, trans_cube, trans_inv; + + DBG_ASSERT(t < 48, zero, + "transform: invalid transformation %" PRIu8 + ", must be between 0 and 47\n", t); + + trans_cube = cube_trans_table[t]; + trans_inv = cube_trans_table_inverse[t]; + + ret = compose_edges(trans_cube, c); + ret = compose_edges(ret, trans_inv); + + return ret; +} + +_static cube_t +transform_corners(cube_t c, uint8_t t) +{ + cube_t ret, trans_cube, trans_inv; + + DBG_ASSERT(t < 48, zero, + "transform: invalid transformation %" PRIu8 + ", must be between 0 and 47\n", t); + + trans_cube = cube_trans_table[t]; + trans_inv = cube_trans_table_inverse[t]; + + ret = compose_corners(trans_cube, c); + ret = compose_corners(ret, trans_inv); + + return t < 24 ? ret : invertco(ret); +} + +_static cube_t +transform(cube_t c, uint8_t t) +{ + cube_t ret, trans_cube, trans_inv; + + DBG_ASSERT(t < 48, zero, + "transform: invalid transformation %" PRIu8 + ", must be between 0 and 47\n", t); + + trans_cube = cube_trans_table[t]; + trans_inv = cube_trans_table_inverse[t]; + + ret = compose(trans_cube, c); + ret = compose(ret, trans_inv); + + return t < 24 ? ret : invertco(ret); +} diff --git a/src/core/transform_with_switch.h b/src/core/transform_with_switch.h new file mode 100644 index 0000000..d3a108c --- /dev/null +++ b/src/core/transform_with_switch.h @@ -0,0 +1,336 @@ +#define _trans_edges_rotation(T, c) \ + compose_edges(compose_edges(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse) +#define _trans_edges_mirrored(T, c) _trans_edges_rotation(T, c) + +#define _trans_corners_rotation(T, c) \ + compose_corners(compose_corners(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse) +#define _trans_corners_mirrored(T, c) \ + invertco(compose_corners( \ + compose_corners(_trans_cube_ ## T, c), _trans_cube_ ## T ## _inverse)) + +#define _trans_rotation(T, c) \ + compose(compose(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse) +#define _trans_mirrored(T, c) \ + invertco(compose(compose(_trans_cube_ ## T, c), \ + _trans_cube_ ## T ## _inverse)) + +_static cube_t +transform_edges(cube_t c, uint8_t t) +{ + switch (t) { + case _trans_UFr: + return c; + case _trans_ULr: + return _trans_edges_rotation(ULr, c); + case _trans_UBr: + return _trans_edges_rotation(UBr, c); + case _trans_URr: + return _trans_edges_rotation(URr, c); + case _trans_DFr: + return _trans_edges_rotation(DFr, c); + case _trans_DLr: + return _trans_edges_rotation(DLr, c); + case _trans_DBr: + return _trans_edges_rotation(DBr, c); + case _trans_DRr: + return _trans_edges_rotation(DRr, c); + case _trans_RUr: + return _trans_edges_rotation(RUr, c); + case _trans_RFr: + return _trans_edges_rotation(RFr, c); + case _trans_RDr: + return _trans_edges_rotation(RDr, c); + case _trans_RBr: + return _trans_edges_rotation(RBr, c); + case _trans_LUr: + return _trans_edges_rotation(LUr, c); + case _trans_LFr: + return _trans_edges_rotation(LFr, c); + case _trans_LDr: + return _trans_edges_rotation(LDr, c); + case _trans_LBr: + return _trans_edges_rotation(LBr, c); + case _trans_FUr: + return _trans_edges_rotation(FUr, c); + case _trans_FRr: + return _trans_edges_rotation(FRr, c); + case _trans_FDr: + return _trans_edges_rotation(FDr, c); + case _trans_FLr: + return _trans_edges_rotation(FLr, c); + case _trans_BUr: + return _trans_edges_rotation(BUr, c); + case _trans_BRr: + return _trans_edges_rotation(BRr, c); + case _trans_BDr: + return _trans_edges_rotation(BDr, c); + case _trans_BLr: + return _trans_edges_rotation(BLr, c); + case _trans_UFm: + return _trans_edges_mirrored(UFm, c); + case _trans_ULm: + return _trans_edges_mirrored(ULm, c); + case _trans_UBm: + return _trans_edges_mirrored(UBm, c); + case _trans_URm: + return _trans_edges_mirrored(URm, c); + case _trans_DFm: + return _trans_edges_mirrored(DFm, c); + case _trans_DLm: + return _trans_edges_mirrored(DLm, c); + case _trans_DBm: + return _trans_edges_mirrored(DBm, c); + case _trans_DRm: + return _trans_edges_mirrored(DRm, c); + case _trans_RUm: + return _trans_edges_mirrored(RUm, c); + case _trans_RFm: + return _trans_edges_mirrored(RFm, c); + case _trans_RDm: + return _trans_edges_mirrored(RDm, c); + case _trans_RBm: + return _trans_edges_mirrored(RBm, c); + case _trans_LUm: + return _trans_edges_mirrored(LUm, c); + case _trans_LFm: + return _trans_edges_mirrored(LFm, c); + case _trans_LDm: + return _trans_edges_mirrored(LDm, c); + case _trans_LBm: + return _trans_edges_mirrored(LBm, c); + case _trans_FUm: + return _trans_edges_mirrored(FUm, c); + case _trans_FRm: + return _trans_edges_mirrored(FRm, c); + case _trans_FDm: + return _trans_edges_mirrored(FDm, c); + case _trans_FLm: + return _trans_edges_mirrored(FLm, c); + case _trans_BUm: + return _trans_edges_mirrored(BUm, c); + case _trans_BRm: + return _trans_edges_mirrored(BRm, c); + case _trans_BDm: + return _trans_edges_mirrored(BDm, c); + case _trans_BLm: + return _trans_edges_mirrored(BLm, c); + default: + LOG("transform error, unknown transformation %" PRIu8 "\n", t); + return zero; + } +} + +_static cube_t +transform_corners(cube_t c, uint8_t t) +{ + switch (t) { + case _trans_UFr: + return c; + case _trans_ULr: + return _trans_corners_rotation(ULr, c); + case _trans_UBr: + return _trans_corners_rotation(UBr, c); + case _trans_URr: + return _trans_corners_rotation(URr, c); + case _trans_DFr: + return _trans_corners_rotation(DFr, c); + case _trans_DLr: + return _trans_corners_rotation(DLr, c); + case _trans_DBr: + return _trans_corners_rotation(DBr, c); + case _trans_DRr: + return _trans_corners_rotation(DRr, c); + case _trans_RUr: + return _trans_corners_rotation(RUr, c); + case _trans_RFr: + return _trans_corners_rotation(RFr, c); + case _trans_RDr: + return _trans_corners_rotation(RDr, c); + case _trans_RBr: + return _trans_corners_rotation(RBr, c); + case _trans_LUr: + return _trans_corners_rotation(LUr, c); + case _trans_LFr: + return _trans_corners_rotation(LFr, c); + case _trans_LDr: + return _trans_corners_rotation(LDr, c); + case _trans_LBr: + return _trans_corners_rotation(LBr, c); + case _trans_FUr: + return _trans_corners_rotation(FUr, c); + case _trans_FRr: + return _trans_corners_rotation(FRr, c); + case _trans_FDr: + return _trans_corners_rotation(FDr, c); + case _trans_FLr: + return _trans_corners_rotation(FLr, c); + case _trans_BUr: + return _trans_corners_rotation(BUr, c); + case _trans_BRr: + return _trans_corners_rotation(BRr, c); + case _trans_BDr: + return _trans_corners_rotation(BDr, c); + case _trans_BLr: + return _trans_corners_rotation(BLr, c); + case _trans_UFm: + return _trans_corners_mirrored(UFm, c); + case _trans_ULm: + return _trans_corners_mirrored(ULm, c); + case _trans_UBm: + return _trans_corners_mirrored(UBm, c); + case _trans_URm: + return _trans_corners_mirrored(URm, c); + case _trans_DFm: + return _trans_corners_mirrored(DFm, c); + case _trans_DLm: + return _trans_corners_mirrored(DLm, c); + case _trans_DBm: + return _trans_corners_mirrored(DBm, c); + case _trans_DRm: + return _trans_corners_mirrored(DRm, c); + case _trans_RUm: + return _trans_corners_mirrored(RUm, c); + case _trans_RFm: + return _trans_corners_mirrored(RFm, c); + case _trans_RDm: + return _trans_corners_mirrored(RDm, c); + case _trans_RBm: + return _trans_corners_mirrored(RBm, c); + case _trans_LUm: + return _trans_corners_mirrored(LUm, c); + case _trans_LFm: + return _trans_corners_mirrored(LFm, c); + case _trans_LDm: + return _trans_corners_mirrored(LDm, c); + case _trans_LBm: + return _trans_corners_mirrored(LBm, c); + case _trans_FUm: + return _trans_corners_mirrored(FUm, c); + case _trans_FRm: + return _trans_corners_mirrored(FRm, c); + case _trans_FDm: + return _trans_corners_mirrored(FDm, c); + case _trans_FLm: + return _trans_corners_mirrored(FLm, c); + case _trans_BUm: + return _trans_corners_mirrored(BUm, c); + case _trans_BRm: + return _trans_corners_mirrored(BRm, c); + case _trans_BDm: + return _trans_corners_mirrored(BDm, c); + case _trans_BLm: + return _trans_corners_mirrored(BLm, c); + default: + LOG("transform error, unknown transformation %" PRIu8 "\n", t); + return zero; + } +} + +_static cube_t +transform(cube_t c, uint8_t t) +{ + switch (t) { + case _trans_UFr: + return c; + case _trans_ULr: + return _trans_rotation(ULr, c); + case _trans_UBr: + return _trans_rotation(UBr, c); + case _trans_URr: + return _trans_rotation(URr, c); + case _trans_DFr: + return _trans_rotation(DFr, c); + case _trans_DLr: + return _trans_rotation(DLr, c); + case _trans_DBr: + return _trans_rotation(DBr, c); + case _trans_DRr: + return _trans_rotation(DRr, c); + case _trans_RUr: + return _trans_rotation(RUr, c); + case _trans_RFr: + return _trans_rotation(RFr, c); + case _trans_RDr: + return _trans_rotation(RDr, c); + case _trans_RBr: + return _trans_rotation(RBr, c); + case _trans_LUr: + return _trans_rotation(LUr, c); + case _trans_LFr: + return _trans_rotation(LFr, c); + case _trans_LDr: + return _trans_rotation(LDr, c); + case _trans_LBr: + return _trans_rotation(LBr, c); + case _trans_FUr: + return _trans_rotation(FUr, c); + case _trans_FRr: + return _trans_rotation(FRr, c); + case _trans_FDr: + return _trans_rotation(FDr, c); + case _trans_FLr: + return _trans_rotation(FLr, c); + case _trans_BUr: + return _trans_rotation(BUr, c); + case _trans_BRr: + return _trans_rotation(BRr, c); + case _trans_BDr: + return _trans_rotation(BDr, c); + case _trans_BLr: + return _trans_rotation(BLr, c); + case _trans_UFm: + return _trans_mirrored(UFm, c); + case _trans_ULm: + return _trans_mirrored(ULm, c); + case _trans_UBm: + return _trans_mirrored(UBm, c); + case _trans_URm: + return _trans_mirrored(URm, c); + case _trans_DFm: + return _trans_mirrored(DFm, c); + case _trans_DLm: + return _trans_mirrored(DLm, c); + case _trans_DBm: + return _trans_mirrored(DBm, c); + case _trans_DRm: + return _trans_mirrored(DRm, c); + case _trans_RUm: + return _trans_mirrored(RUm, c); + case _trans_RFm: + return _trans_mirrored(RFm, c); + case _trans_RDm: + return _trans_mirrored(RDm, c); + case _trans_RBm: + return _trans_mirrored(RBm, c); + case _trans_LUm: + return _trans_mirrored(LUm, c); + case _trans_LFm: + return _trans_mirrored(LFm, c); + case _trans_LDm: + return _trans_mirrored(LDm, c); + case _trans_LBm: + return _trans_mirrored(LBm, c); + case _trans_FUm: + return _trans_mirrored(FUm, c); + case _trans_FRm: + return _trans_mirrored(FRm, c); + case _trans_FDm: + return _trans_mirrored(FDm, c); + case _trans_FLm: + return _trans_mirrored(FLm, c); + case _trans_BUm: + return _trans_mirrored(BUm, c); + case _trans_BRm: + return _trans_mirrored(BRm, c); + case _trans_BDm: + return _trans_mirrored(BDm, c); + case _trans_BLm: + return _trans_mirrored(BLm, c); + default: + LOG("transform error, unknown transformation %" PRIu8 "\n", t); + return zero; + } +} -- cgit v1.3