From ae055f1fc993d406939f57f11553d218e1efde82 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 13 Apr 2024 09:24:47 +0200 Subject: Simplified moves and trans --- cube.c | 717 +++-------------------------------------------------------------- 1 file changed, 32 insertions(+), 685 deletions(-) (limited to 'cube.c') diff --git a/cube.c b/cube.c index 16a5338..9ca9e68 100644 --- a/cube.c +++ b/cube.c @@ -27,10 +27,6 @@ #endif -/****************************************************************************** -Section: mathematical constants -******************************************************************************/ - #define _2p11 2048U #define _2p12 4096U #define _3p7 2187U @@ -38,94 +34,6 @@ Section: mathematical constants #define _12c4 495U #define _8c4 70U -_static int64_t binomial[12][12] = { - {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 3, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 4, 6, 4, 1, 0, 0, 0, 0, 0, 0, 0}, - {1, 5, 10, 10, 5, 1, 0, 0, 0, 0, 0, 0}, - {1, 6, 15, 20, 15, 6, 1, 0, 0, 0, 0, 0}, - {1, 7, 21, 35, 35, 21, 7, 1, 0, 0, 0, 0}, - {1, 8, 28, 56, 70, 56, 28, 8, 1, 0, 0, 0}, - {1, 9, 36, 84, 126, 126, 84, 36, 9, 1, 0, 0}, - {1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1, 0}, - {1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1}, -}; - -/****************************************************************************** -Section: moves definitions and tables -******************************************************************************/ - -#define U 0U -#define U2 1U -#define U3 2U -#define D 3U -#define D2 4U -#define D3 5U -#define R 6U -#define R2 7U -#define R3 8U -#define L 9U -#define L2 10U -#define L3 11U -#define F 12U -#define F2 13U -#define F3 14U -#define B 15U -#define B2 16U -#define B3 17U - -#define UFr 0 -#define ULr 1 -#define UBr 2 -#define URr 3 -#define DFr 4 -#define DLr 5 -#define DBr 6 -#define DRr 7 -#define RUr 8 -#define RFr 9 -#define RDr 10 -#define RBr 11 -#define LUr 12 -#define LFr 13 -#define LDr 14 -#define LBr 15 -#define FUr 16 -#define FRr 17 -#define FDr 18 -#define FLr 19 -#define BUr 20 -#define BRr 21 -#define BDr 22 -#define BLr 23 - -#define UFm 24 -#define ULm 25 -#define UBm 26 -#define URm 27 -#define DFm 28 -#define DLm 29 -#define DBm 30 -#define DRm 31 -#define RUm 32 -#define RFm 33 -#define RDm 34 -#define RBm 35 -#define LUm 36 -#define LFm 37 -#define LDm 38 -#define LBm 39 -#define FUm 40 -#define FRm 41 -#define FDm 42 -#define FLm 43 -#define BUm 44 -#define BRm 45 -#define BDm 46 -#define BLm 47 - #define _c_ufr 0U #define _c_ubl 1U #define _c_dfl 2U @@ -163,406 +71,29 @@ Section: moves definitions and tables #define _eflip 0x10U #define _error 0xFFU +typedef enum { + U, U2, U3, D, D2, D3, + R, R2, R3, L, L2, L3, + F, F2, F3, B, B2, B3 +} move_t; + +typedef enum { + UFr, ULr, UBr, URr, DFr, DLr, DBr, DRr, + RUr, RFr, RDr, RBr, LUr, LFr, LDr, LBr, + FUr, FRr, FDr, FLr, BUr, BRr, BDr, BLr, + + UFm, ULm, UBm, URm, DFm, DLm, DBm, DRm, + RUm, RFm, RDm, RBm, LUm, LFm, LDm, LBm, + FUm, FRm, FDm, FLm, BUm, BRm, BDm, BLm +} trans_t; + _static cube_t zero = { .corner = {0}, .edge = {0} }; _static cube_t solved = { .corner = {0, 1, 2, 3, 4, 5, 6, 7}, .edge = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} }; -#define zero_fast fastcube( \ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) -#define solved_fast fastcube( \ - 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) - -#define _move_cube_U fastcube( \ - 5, 4, 2, 3, 0, 1, 6, 7, 4, 5, 2, 3, 1, 0, 6, 7, 8, 9, 10, 11) -#define _move_cube_U2 fastcube( \ - 1, 0, 2, 3, 5, 4, 6, 7, 1, 0, 2, 3, 5, 4, 6, 7, 8, 9, 10, 11) -#define _move_cube_U3 fastcube( \ - 4, 5, 2, 3, 1, 0, 6, 7, 5, 4, 2, 3, 0, 1, 6, 7, 8, 9, 10, 11) -#define _move_cube_D fastcube( \ - 0, 1, 7, 6, 4, 5, 2, 3, 0, 1, 7, 6, 4, 5, 2, 3, 8, 9, 10, 11) -#define _move_cube_D2 fastcube( \ - 0, 1, 3, 2, 4, 5, 7, 6, 0, 1, 3, 2, 4, 5, 7, 6, 8, 9, 10, 11) -#define _move_cube_D3 fastcube( \ - 0, 1, 6, 7, 4, 5, 3, 2, 0, 1, 6, 7, 4, 5, 3, 2, 8, 9, 10, 11) -#define _move_cube_R fastcube( \ - 70, 1, 2, 69, 4, 32, 35, 7, 0, 1, 2, 3, 8, 5, 6, 11, 7, 9, 10, 4) -#define _move_cube_R2 fastcube( \ - 3, 1, 2, 0, 4, 6, 5, 7, 0, 1, 2, 3, 7, 5, 6, 4, 11, 9, 10, 8) -#define _move_cube_R3 fastcube( \ - 69, 1, 2, 70, 4, 35, 32, 7, 0, 1, 2, 3, 11, 5, 6, 8, 4, 9, 10, 7) -#define _move_cube_L fastcube( \ - 0, 71, 68, 3, 33, 5, 6, 34, 0, 1, 2, 3, 4, 10, 9, 7, 8, 5, 6, 11) -#define _move_cube_L2 fastcube( \ - 0, 2, 1, 3, 7, 5, 6, 4, 0, 1, 2, 3, 4, 6, 5, 7, 8, 10, 9, 11) -#define _move_cube_L3 fastcube( \ - 0, 68, 71, 3, 34, 5, 6, 33, 0, 1, 2, 3, 4, 9, 10, 7, 8, 6, 5, 11) -#define _move_cube_F fastcube( \ - 36, 1, 38, 3, 66, 5, 64, 7, 25, 1, 2, 24, 4, 5, 6, 7, 16, 19, 10, 11) -#define _move_cube_F2 fastcube( \ - 2, 1, 0, 3, 6, 5, 4, 7, 3, 1, 2, 0, 4, 5, 6, 7, 9, 8, 10, 11) -#define _move_cube_F3 fastcube( \ - 38, 1, 36, 3, 64, 5, 66, 7, 24, 1, 2, 25, 4, 5, 6, 7, 19, 16, 10, 11) -#define _move_cube_B fastcube( \ - 0, 37, 2, 39, 4, 67, 6, 65, 0, 27, 26, 3, 4, 5, 6, 7, 8, 9, 17, 18) -#define _move_cube_B2 fastcube( \ - 0, 3, 2, 1, 4, 7, 6, 5, 0, 2, 1, 3, 4, 5, 6, 7, 8, 9, 11, 10) -#define _move_cube_B3 fastcube( \ - 0, 39, 2, 37, 4, 65, 6, 67, 0, 26, 27, 3, 4, 5, 6, 7, 8, 9, 18, 17) - -#define _trans_cube_UFr fastcube( \ - 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 fastcube( \ - 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) -#define _trans_cube_ULr fastcube( \ - 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 fastcube( \ - 5, 4, 6, 7, 0, 1, 3, 2, 4, 5, 6, 7, 1, 0, 3, 2, 27, 24, 25, 26) -#define _trans_cube_UBr fastcube( \ - 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 fastcube( \ - 1, 0, 3, 2, 5, 4, 7, 6, 1, 0, 3, 2, 5, 4, 7, 6, 10, 11, 8, 9) -#define _trans_cube_URr fastcube( \ - 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 fastcube( \ - 4, 5, 7, 6, 1, 0, 2, 3, 5, 4, 7, 6, 0, 1, 2, 3, 25, 26, 27, 24) -#define _trans_cube_DFr fastcube( \ - 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 fastcube( \ - 2, 3, 0, 1, 6, 7, 4, 5, 3, 2, 1, 0, 6, 7, 4, 5, 9, 8, 11, 10) -#define _trans_cube_DLr fastcube( \ - 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 fastcube( \ - 7, 6, 4, 5, 2, 3, 1, 0, 6, 7, 4, 5, 2, 3, 0, 1, 26, 25, 24, 27) -#define _trans_cube_DBr fastcube( \ - 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 fastcube( \ - 3, 2, 1, 0, 7, 6, 5, 4, 2, 3, 0, 1, 7, 6, 5, 4, 11, 10, 9, 8) -#define _trans_cube_DRr fastcube( \ - 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 fastcube( \ - 6, 7, 5, 4, 3, 2, 0, 1, 7, 6, 5, 4, 3, 2, 1, 0, 24, 27, 26, 25) -#define _trans_cube_RUr fastcube( \ - 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 fastcube( \ - 32, 34, 35, 33, 70, 68, 69, 71, 8, 9, 10, 11, 16, 19, 18, 17, 20, 23, 22, 21) -#define _trans_cube_RFr fastcube( \ - 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 fastcube( \ - 36, 39, 38, 37, 66, 65, 64, 67, 25, 26, 27, 24, 21, 22, 23, 20, 16, 19, 18, 17) -#define _trans_cube_RDr fastcube( \ - 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 fastcube( \ - 33, 35, 34, 32, 71, 69, 68, 70, 10, 11, 8, 9, 17, 18, 19, 16, 21, 22, 23, 20) -#define _trans_cube_RBr fastcube( \ - 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 fastcube( \ - 37, 38, 39, 36, 67, 64, 65, 66, 27, 24, 25, 26, 20, 23, 22, 21, 17, 18, 19, 16) -#define _trans_cube_LUr fastcube( \ - 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 fastcube( \ - 34, 32, 33, 35, 68, 70, 71, 69, 9, 8, 11, 10, 19, 16, 17, 18, 22, 21, 20, 23) -#define _trans_cube_LFr fastcube( \ - 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 fastcube( \ - 38, 37, 36, 39, 64, 67, 66, 65, 24, 27, 26, 25, 23, 20, 21, 22, 19, 16, 17, 18) -#define _trans_cube_LDr fastcube( \ - 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 fastcube( \ - 35, 33, 32, 34, 69, 71, 70, 68, 11, 10, 9, 8, 18, 17, 16, 19, 23, 20, 21, 22) -#define _trans_cube_LBr fastcube( \ - 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 fastcube( \ - 39, 36, 37, 38, 65, 66, 67, 64, 26, 25, 24, 27, 22, 21, 20, 23, 18, 17, 16, 19) -#define _trans_cube_FUr fastcube( \ - 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 fastcube( \ - 68, 70, 69, 71, 32, 34, 33, 35, 16, 19, 18, 17, 9, 8, 11, 10, 5, 4, 7, 6) -#define _trans_cube_FRr fastcube( \ - 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 fastcube( \ - 64, 67, 65, 66, 37, 38, 36, 39, 20, 23, 22, 21, 24, 27, 26, 25, 0, 1, 2, 3) -#define _trans_cube_FDr fastcube( \ - 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 fastcube( \ - 69, 71, 68, 70, 33, 35, 32, 34, 17, 18, 19, 16, 11, 10, 9, 8, 4, 5, 6, 7) -#define _trans_cube_FLr fastcube( \ - 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 fastcube( \ - 65, 66, 64, 67, 36, 39, 37, 38, 21, 22, 23, 20, 26, 25, 24, 27, 1, 0, 3, 2) -#define _trans_cube_BUr fastcube( \ - 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 fastcube( \ - 70, 68, 71, 69, 34, 32, 35, 33, 19, 16, 17, 18, 8, 9, 10, 11, 7, 6, 5, 4) -#define _trans_cube_BRr fastcube( \ - 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 fastcube( \ - 66, 65, 67, 64, 39, 36, 38, 37, 22, 21, 20, 23, 25, 26, 27, 24, 3, 2, 1, 0) -#define _trans_cube_BDr fastcube( \ - 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 fastcube( \ - 71, 69, 70, 68, 35, 33, 34, 32, 18, 17, 16, 19, 10, 11, 8, 9, 6, 7, 4, 5) -#define _trans_cube_BLr fastcube( \ - 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 fastcube( \ - 67, 64, 66, 65, 38, 37, 39, 36, 23, 20, 21, 22, 27, 24, 25, 26, 2, 3, 0, 1) -#define _trans_cube_UFm fastcube( \ - 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 fastcube( \ - 4, 5, 6, 7, 0, 1, 2, 3, 0, 1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10) -#define _trans_cube_ULm fastcube( \ - 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 fastcube( \ - 0, 1, 3, 2, 5, 4, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3, 24, 27, 26, 25) -#define _trans_cube_UBm fastcube( \ - 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 fastcube( \ - 5, 4, 7, 6, 1, 0, 3, 2, 1, 0, 3, 2, 4, 5, 6, 7, 11, 10, 9, 8) -#define _trans_cube_URm fastcube( \ - 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 fastcube( \ - 1, 0, 2, 3, 4, 5, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 26, 25, 24, 27) -#define _trans_cube_DFm fastcube( \ - 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 fastcube( \ - 6, 7, 4, 5, 2, 3, 0, 1, 3, 2, 1, 0, 7, 6, 5, 4, 8, 9, 10, 11) -#define _trans_cube_DLm fastcube( \ - 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 fastcube( \ - 2, 3, 1, 0, 7, 6, 4, 5, 6, 7, 4, 5, 3, 2, 1, 0, 25, 26, 27, 24) -#define _trans_cube_DBm fastcube( \ - 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 fastcube( \ - 7, 6, 5, 4, 3, 2, 1, 0, 2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9) -#define _trans_cube_DRm fastcube( \ - 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 fastcube( \ - 3, 2, 0, 1, 6, 7, 5, 4, 7, 6, 5, 4, 2, 3, 0, 1, 27, 24, 25, 26) -#define _trans_cube_RUm fastcube( \ - 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 fastcube( \ - 70, 68, 69, 71, 32, 34, 35, 33, 8, 9, 10, 11, 19, 16, 17, 18, 23, 20, 21, 22) -#define _trans_cube_RFm fastcube( \ - 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 fastcube( \ - 66, 65, 64, 67, 36, 39, 38, 37, 25, 26, 27, 24, 22, 21, 20, 23, 19, 16, 17, 18) -#define _trans_cube_RDm fastcube( \ - 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 fastcube( \ - 71, 69, 68, 70, 33, 35, 34, 32, 10, 11, 8, 9, 18, 17, 16, 19, 22, 21, 20, 23) -#define _trans_cube_RBm fastcube( \ - 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 fastcube( \ - 67, 64, 65, 66, 37, 38, 39, 36, 27, 24, 25, 26, 23, 20, 21, 22, 18, 17, 16, 19) -#define _trans_cube_LUm fastcube( \ - 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 fastcube( \ - 68, 70, 71, 69, 34, 32, 33, 35, 9, 8, 11, 10, 16, 19, 18, 17, 21, 22, 23, 20) -#define _trans_cube_LFm fastcube( \ - 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 fastcube( \ - 64, 67, 66, 65, 38, 37, 36, 39, 24, 27, 26, 25, 20, 23, 22, 21, 16, 19, 18, 17) -#define _trans_cube_LDm fastcube( \ - 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 fastcube( \ - 69, 71, 70, 68, 35, 33, 32, 34, 11, 10, 9, 8, 17, 18, 19, 16, 20, 23, 22, 21) -#define _trans_cube_LBm fastcube( \ - 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 fastcube( \ - 65, 66, 67, 64, 39, 36, 37, 38, 26, 25, 24, 27, 21, 22, 23, 20, 17, 18, 19, 16) -#define _trans_cube_FUm fastcube( \ - 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 fastcube( \ - 32, 34, 33, 35, 68, 70, 69, 71, 16, 19, 18, 17, 8, 9, 10, 11, 4, 5, 6, 7) -#define _trans_cube_FRm fastcube( \ - 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 fastcube( \ - 37, 38, 36, 39, 64, 67, 65, 66, 20, 23, 22, 21, 27, 24, 25, 26, 1, 0, 3, 2) -#define _trans_cube_FDm fastcube( \ - 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 fastcube( \ - 33, 35, 32, 34, 69, 71, 68, 70, 17, 18, 19, 16, 10, 11, 8, 9, 5, 4, 7, 6) -#define _trans_cube_FLm fastcube( \ - 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 fastcube( \ - 36, 39, 37, 38, 65, 66, 64, 67, 21, 22, 23, 20, 25, 26, 27, 24, 0, 1, 2, 3) -#define _trans_cube_BUm fastcube( \ - 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 fastcube( \ - 34, 32, 35, 33, 70, 68, 71, 69, 19, 16, 17, 18, 9, 8, 11, 10, 6, 7, 4, 5) -#define _trans_cube_BRm fastcube( \ - 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 fastcube( \ - 39, 36, 38, 37, 66, 65, 67, 64, 22, 21, 20, 23, 26, 25, 24, 27, 2, 3, 0, 1) -#define _trans_cube_BDm fastcube( \ - 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 fastcube( \ - 35, 33, 34, 32, 71, 69, 70, 68, 18, 17, 16, 19, 11, 10, 9, 8, 7, 6, 5, 4) -#define _trans_cube_BLm fastcube( \ - 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 fastcube( \ - 38, 37, 39, 36, 67, 64, 66, 65, 23, 20, 21, 22, 24, 27, 26, 25, 3, 2, 1, 0) - -_static char *cornerstr[] = { - [_c_ufr] = "UFR", - [_c_ubl] = "UBL", - [_c_dfl] = "DFL", - [_c_dbr] = "DBR", - [_c_ufl] = "UFL", - [_c_ubr] = "UBR", - [_c_dfr] = "DFR", - [_c_dbl] = "DBL" -}; - -_static char *cornerstralt[] = { - [_c_ufr] = "URF", - [_c_ubl] = "ULB", - [_c_dfl] = "DLF", - [_c_dbr] = "DRB", - [_c_ufl] = "ULF", - [_c_ubr] = "URB", - [_c_dfr] = "DRF", - [_c_dbl] = "DLB" -}; - -_static char *edgestr[] = { - [_e_uf] = "UF", - [_e_ub] = "UB", - [_e_db] = "DB", - [_e_df] = "DF", - [_e_ur] = "UR", - [_e_ul] = "UL", - [_e_dl] = "DL", - [_e_dr] = "DR", - [_e_fr] = "FR", - [_e_fl] = "FL", - [_e_bl] = "BL", - [_e_br] = "BR" -}; - -_static char *movestr[] = { - [U] = "U", - [U2] = "U2", - [U3] = "U'", - [D] = "D", - [D2] = "D2", - [D3] = "D'", - [R] = "R", - [R2] = "R2", - [R3] = "R'", - [L] = "L", - [L2] = "L2", - [L3] = "L'", - [F] = "F", - [F2] = "F2", - [F3] = "F'", - [B] = "B", - [B2] = "B2", - [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", -}; - -static uint8_t inverse_trans_table[48] = { - [UFr] = UFr, - [UFm] = UFm, - [ULr] = URr, - [ULm] = ULm, - [UBr] = UBr, - [UBm] = UBm, - [URr] = ULr, - [URm] = URm, - [DFr] = DFr, - [DFm] = DFm, - [DLr] = DLr, - [DLm] = DRm, - [DBr] = DBr, - [DBm] = DBm, - [DRr] = DRr, - [DRm] = DLm, - [RUr] = FRr, - [RUm] = FLm, - [RFr] = LFr, - [RFm] = RFm, - [RDr] = BLr, - [RDm] = BRm, - [RBr] = RBr, - [RBm] = LBm, - [LUr] = FLr, - [LUm] = FRm, - [LFr] = RFr, - [LFm] = LFm, - [LDr] = BRr, - [LDm] = BLm, - [LBr] = LBr, - [LBm] = RBm, - [FUr] = FUr, - [FUm] = FUm, - [FRr] = RUr, - [FRm] = LUm, - [FDr] = BUr, - [FDm] = BUm, - [FLr] = LUr, - [FLm] = RUm, - [BUr] = FDr, - [BUm] = FDm, - [BRr] = LDr, - [BRm] = RDm, - [BDr] = BDr, - [BDm] = BDm, - [BLr] = RDr, - [BLm] = LDm, -}; +#include "tables.h" /****************************************************************************** Section: portable fast methods @@ -574,12 +105,6 @@ in the previous section(s) for unsupported architectures. typedef cube_t cube_fast_t; -_static_inline cube_fast_t fastcube( - uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, - uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, - uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, - uint8_t, uint8_t, uint8_t, uint8_t, uint8_t -); _static cube_fast_t cubetofast(cube_t); _static cube_t fasttocube(cube_fast_t); _static_inline bool equal_fast(cube_fast_t, cube_fast_t); @@ -590,44 +115,6 @@ _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); _static_inline int64_t coord_fast_co(cube_fast_t); _static_inline int64_t coord_fast_eo(cube_fast_t); -_static_inline cube_fast_t -fastcube( - uint8_t c_ufr, - uint8_t c_ubl, - uint8_t c_dfl, - uint8_t c_dbr, - uint8_t c_ufl, - uint8_t c_ubr, - uint8_t c_dfr, - uint8_t c_dbl, - - uint8_t e_uf, - uint8_t e_ub, - uint8_t e_db, - uint8_t e_df, - uint8_t e_ur, - uint8_t e_ul, - uint8_t e_dl, - uint8_t e_dr, - uint8_t e_fr, - uint8_t e_fl, - uint8_t e_bl, - uint8_t e_br -) -{ - cube_fast_t cube = { - .corner = { - c_ufr, c_ubl, c_dfl, c_dbr, c_ufl, c_ubr, c_dfr, c_dbl - }, - .edge = { - e_uf, e_ub, e_db, e_df, e_ur, e_ul, - e_dl, e_dr, e_fr, e_fl, e_bl, e_br - } - }; - - return cube; -} - _static cube_fast_t cubetofast(cube_t cube) { @@ -662,7 +149,7 @@ equal_fast(cube_fast_t c1, cube_fast_t c2) _static_inline bool issolved_fast(cube_fast_t cube) { - return equal_fast(cube, solved_fast); + return equal_fast(cube, solved); } _static_inline cube_fast_t @@ -687,7 +174,7 @@ compose_fast(cube_fast_t c1, cube_fast_t c2) cube_fast_t ret; uint8_t i, piece1, piece2, p, orien, aux, auy; - ret = zero_fast; + ret = zero; for (i = 0; i < 12; i++) { piece2 = c2.edge[i]; @@ -742,14 +229,7 @@ Some of these routines depend on the efficient functions implemented in the previous sections, while some other operate directly on the cube. ******************************************************************************/ -#define _move(M, c) compose_fast(c, _move_cube_ ## M) #define _premove(M, c) compose_fast(_move_cube_ ## M, c) -#define _trans_rotation(T, c) \ - compose_fast(compose_fast(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse) -#define _trans_mirrored(T, c) \ - invertco_fast(compose_fast(compose_fast(_trans_cube_ ## T, c), \ - _trans_cube_ ## T ## _inverse)) #define _foreach_move(_m, _c, _d, instruction) \ for (_m = 0; _m < 18; _m++) { _d = move(_c, _m); instruction } @@ -785,8 +265,8 @@ _static uint8_t readmodifier(char); _static uint8_t readtrans(char *); _static int writemoves(uint8_t *, int, char *); _static void writetrans(uint8_t, char *); -_static cube_fast_t move(cube_fast_t, uint8_t); -_static cube_fast_t transform(cube_fast_t, uint8_t); +_static cube_fast_t move(cube_fast_t, move_t); +_static cube_fast_t transform(cube_fast_t, trans_t); cube_t solvedcube(void) @@ -1339,155 +819,22 @@ writetrans(uint8_t t, char *buf) } _static cube_fast_t -move(cube_fast_t c, uint8_t m) +move(cube_fast_t c, move_t m) { - switch (m) { - case U: - return _move(U, c); - case U2: - return _move(U2, c); - case U3: - return _move(U3, c); - case D: - return _move(D, c); - case D2: - return _move(D2, c); - case D3: - return _move(D3, c); - case R: - return _move(R, c); - case R2: - return _move(R2, c); - case R3: - return _move(R3, c); - case L: - return _move(L, c); - case L2: - return _move(L2, c); - case L3: - return _move(L3, c); - case F: - return _move(F, c); - case F2: - return _move(F2, c); - case F3: - return _move(F3, c); - case B: - return _move(B, c); - case B2: - return _move(B2, c); - case B3: - return _move(B3, c); - default: - DBG_LOG("move error, unknown move\n"); - return zero_fast; - } + return compose_fast(c, move_table[m]); } _static cube_fast_t -transform(cube_fast_t c, uint8_t t) +transform(cube_fast_t c, trans_t t) { - switch (t) { - case UFr: - return _trans_rotation(UFr, c); - case ULr: - return _trans_rotation(ULr, c); - case UBr: - return _trans_rotation(UBr, c); - case URr: - return _trans_rotation(URr, c); - case DFr: - return _trans_rotation(DFr, c); - case DLr: - return _trans_rotation(DLr, c); - case DBr: - return _trans_rotation(DBr, c); - case DRr: - return _trans_rotation(DRr, c); - case RUr: - return _trans_rotation(RUr, c); - case RFr: - return _trans_rotation(RFr, c); - case RDr: - return _trans_rotation(RDr, c); - case RBr: - return _trans_rotation(RBr, c); - case LUr: - return _trans_rotation(LUr, c); - case LFr: - return _trans_rotation(LFr, c); - case LDr: - return _trans_rotation(LDr, c); - case LBr: - return _trans_rotation(LBr, c); - case FUr: - return _trans_rotation(FUr, c); - case FRr: - return _trans_rotation(FRr, c); - case FDr: - return _trans_rotation(FDr, c); - case FLr: - return _trans_rotation(FLr, c); - case BUr: - return _trans_rotation(BUr, c); - case BRr: - return _trans_rotation(BRr, c); - case BDr: - return _trans_rotation(BDr, c); - case BLr: - return _trans_rotation(BLr, c); - case UFm: - return _trans_mirrored(UFm, c); - case ULm: - return _trans_mirrored(ULm, c); - case UBm: - return _trans_mirrored(UBm, c); - case URm: - return _trans_mirrored(URm, c); - case DFm: - return _trans_mirrored(DFm, c); - case DLm: - return _trans_mirrored(DLm, c); - case DBm: - return _trans_mirrored(DBm, c); - case DRm: - return _trans_mirrored(DRm, c); - case RUm: - return _trans_mirrored(RUm, c); - case RFm: - return _trans_mirrored(RFm, c); - case RDm: - return _trans_mirrored(RDm, c); - case RBm: - return _trans_mirrored(RBm, c); - case LUm: - return _trans_mirrored(LUm, c); - case LFm: - return _trans_mirrored(LFm, c); - case LDm: - return _trans_mirrored(LDm, c); - case LBm: - return _trans_mirrored(LBm, c); - case FUm: - return _trans_mirrored(FUm, c); - case FRm: - return _trans_mirrored(FRm, c); - case FDm: - return _trans_mirrored(FDm, c); - case FLm: - return _trans_mirrored(FLm, c); - case BUm: - return _trans_mirrored(BUm, c); - case BRm: - return _trans_mirrored(BRm, c); - case BDm: - return _trans_mirrored(BDm, c); - case BLm: - return _trans_mirrored(BLm, c); - default: - DBG_LOG("transform error, unknown transformation\n"); - return zero_fast; - } + cube_t tcube, tinv; + + tcube = trans_table[t][NORMAL]; + tinv = trans_table[t][INVERSE]; + + return t < 24 ? + compose_fast(compose_fast(tcube, c), tinv) : + invertco_fast(compose_fast(compose_fast(tcube, c), tinv)); } /****************************************************************************** -- cgit v1.3