h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

constants.h (8134B)


      1 #define UINT8_BIT(i) (UINT8_C(1) << (uint8_t)(i))
      2 
      3 #define FACTORIAL_MAX INT64_C(12)
      4 
      5 #define POW_2_11   INT64_C(2048)
      6 #define POW_3_7    INT64_C(2187)
      7 #define FACT_12    INT64_C(479001600)
      8 #define FACT_8     INT64_C(40320)
      9 #define COMB_12_4  INT64_C(495)
     10 #define COMB_8_4   INT64_C(70)
     11 
     12 STATIC int64_t binomial[12][12] = {
     13 	{1,  0,  0,   0,   0,   0,   0,   0,   0,  0,  0, 0},
     14 	{1,  1,  0,   0,   0,   0,   0,   0,   0,  0,  0, 0},
     15 	{1,  2,  1,   0,   0,   0,   0,   0,   0,  0,  0, 0},
     16 	{1,  3,  3,   1,   0,   0,   0,   0,   0,  0,  0, 0},
     17 	{1,  4,  6,   4,   1,   0,   0,   0,   0,  0,  0, 0},
     18 	{1,  5, 10,  10,   5,   1,   0,   0,   0,  0,  0, 0},
     19 	{1,  6, 15,  20,  15,   6,   1,   0,   0,  0,  0, 0},
     20 	{1,  7, 21,  35,  35,  21,   7,   1,   0,  0,  0, 0},
     21 	{1,  8, 28,  56,  70,  56,  28,   8,   1,  0,  0, 0},
     22 	{1,  9, 36,  84, 126, 126,  84,  36,   9,  1,  0, 0},
     23 	{1, 10, 45, 120, 210, 252, 210, 120,  45, 10,  1, 0},
     24 	{1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1},
     25 };
     26 
     27 #define MOVE_U  UINT8_C(0)
     28 #define MOVE_U2 UINT8_C(1)
     29 #define MOVE_U3 UINT8_C(2)
     30 #define MOVE_D  UINT8_C(3)
     31 #define MOVE_D2 UINT8_C(4)
     32 #define MOVE_D3 UINT8_C(5)
     33 #define MOVE_R  UINT8_C(6)
     34 #define MOVE_R2 UINT8_C(7)
     35 #define MOVE_R3 UINT8_C(8)
     36 #define MOVE_L  UINT8_C(9)
     37 #define MOVE_L2 UINT8_C(10)
     38 #define MOVE_L3 UINT8_C(11)
     39 #define MOVE_F  UINT8_C(12)
     40 #define MOVE_F2 UINT8_C(13)
     41 #define MOVE_F3 UINT8_C(14)
     42 #define MOVE_B  UINT8_C(15)
     43 #define MOVE_B2 UINT8_C(16)
     44 #define MOVE_B3 UINT8_C(17)
     45 
     46 #define TRANS_UFr UINT8_C(0)
     47 #define TRANS_ULr UINT8_C(1)
     48 #define TRANS_UBr UINT8_C(2)
     49 #define TRANS_URr UINT8_C(3)
     50 #define TRANS_DFr UINT8_C(4)
     51 #define TRANS_DLr UINT8_C(5)
     52 #define TRANS_DBr UINT8_C(6)
     53 #define TRANS_DRr UINT8_C(7)
     54 #define TRANS_RUr UINT8_C(8)
     55 #define TRANS_RFr UINT8_C(9)
     56 #define TRANS_RDr UINT8_C(10)
     57 #define TRANS_RBr UINT8_C(11)
     58 #define TRANS_LUr UINT8_C(12)
     59 #define TRANS_LFr UINT8_C(13)
     60 #define TRANS_LDr UINT8_C(14)
     61 #define TRANS_LBr UINT8_C(15)
     62 #define TRANS_FUr UINT8_C(16)
     63 #define TRANS_FRr UINT8_C(17)
     64 #define TRANS_FDr UINT8_C(18)
     65 #define TRANS_FLr UINT8_C(19)
     66 #define TRANS_BUr UINT8_C(20)
     67 #define TRANS_BRr UINT8_C(21)
     68 #define TRANS_BDr UINT8_C(22)
     69 #define TRANS_BLr UINT8_C(23)
     70 
     71 #define TRANS_UFm UINT8_C(24)
     72 #define TRANS_ULm UINT8_C(25)
     73 #define TRANS_UBm UINT8_C(26)
     74 #define TRANS_URm UINT8_C(27)
     75 #define TRANS_DFm UINT8_C(28)
     76 #define TRANS_DLm UINT8_C(29)
     77 #define TRANS_DBm UINT8_C(30)
     78 #define TRANS_DRm UINT8_C(31)
     79 #define TRANS_RUm UINT8_C(32)
     80 #define TRANS_RFm UINT8_C(33)
     81 #define TRANS_RDm UINT8_C(34)
     82 #define TRANS_RBm UINT8_C(35)
     83 #define TRANS_LUm UINT8_C(36)
     84 #define TRANS_LFm UINT8_C(37)
     85 #define TRANS_LDm UINT8_C(38)
     86 #define TRANS_LBm UINT8_C(39)
     87 #define TRANS_FUm UINT8_C(40)
     88 #define TRANS_FRm UINT8_C(41)
     89 #define TRANS_FDm UINT8_C(42)
     90 #define TRANS_FLm UINT8_C(43)
     91 #define TRANS_BUm UINT8_C(44)
     92 #define TRANS_BRm UINT8_C(45)
     93 #define TRANS_BDm UINT8_C(46)
     94 #define TRANS_BLm UINT8_C(47)
     95 
     96 #define MM_NORMAL         UINT8_C(0x00)
     97 #define MM_INVERSE        UINT8_C(0x01)
     98 #define MM_INVERSEBRANCH  UINT8_C(0x03)
     99 #define MM_NORMALBRANCH   UINT8_C(0x02)
    100 #define MM_ALLMOVES       UINT32_C(0x3FFFF)
    101 #define MM_NOHALFTURNS    UINT32_C(0x2DB6D)
    102 
    103 #define CORNER_UFR      UINT8_C(0)
    104 #define CORNER_UBL      UINT8_C(1)
    105 #define CORNER_DFL      UINT8_C(2)
    106 #define CORNER_DBR      UINT8_C(3)
    107 #define CORNER_UFL      UINT8_C(4)
    108 #define CORNER_UBR      UINT8_C(5)
    109 #define CORNER_DFR      UINT8_C(6)
    110 #define CORNER_DBL      UINT8_C(7)
    111 
    112 #define EDGE_UF       UINT8_C(0)
    113 #define EDGE_UB       UINT8_C(1)
    114 #define EDGE_DB       UINT8_C(2)
    115 #define EDGE_DF       UINT8_C(3)
    116 #define EDGE_UR       UINT8_C(4)
    117 #define EDGE_UL       UINT8_C(5)
    118 #define EDGE_DL       UINT8_C(6)
    119 #define EDGE_DR       UINT8_C(7)
    120 #define EDGE_FR       UINT8_C(8)
    121 #define EDGE_FL       UINT8_C(9)
    122 #define EDGE_BL       UINT8_C(10)
    123 #define EDGE_BR       UINT8_C(11)
    124 
    125 #define EOSHIFT     UINT8_C(4)
    126 #define COSHIFT     UINT8_C(5)
    127 
    128 #define PBITS       UINT8_C(0xF)
    129 #define ESEPBIT_1   UINT8_C(0x4)
    130 #define ESEPBIT_2   UINT8_C(0x8)
    131 #define CSEPBIT     UINT8_C(0x4)
    132 #define EOBIT       UINT8_C(0x10)
    133 #define COBITS      UINT8_C(0xF0)
    134 #define COBITS_2    UINT8_C(0x60)
    135 #define CTWIST_CW   UINT8_C(0x20)
    136 #define CTWIST_CCW  UINT8_C(0x40)
    137 #define EFLIP       UINT8_C(0x10)
    138 #define UINT8_ERROR UINT8_C(0xFF)
    139 
    140 STATIC const char *cornerstr[] = {
    141 	[CORNER_UFR] = "UFR",
    142 	[CORNER_UBL] = "UBL",
    143 	[CORNER_DFL] = "DFL",
    144 	[CORNER_DBR] = "DBR",
    145 	[CORNER_UFL] = "UFL",
    146 	[CORNER_UBR] = "UBR",
    147 	[CORNER_DFR] = "DFR",
    148 	[CORNER_DBL] = "DBL"
    149 };
    150 
    151 STATIC const char *cornerstralt[] = {
    152 	[CORNER_UFR] = "URF",
    153 	[CORNER_UBL] = "ULB",
    154 	[CORNER_DFL] = "DLF",
    155 	[CORNER_DBR] = "DRB",
    156 	[CORNER_UFL] = "ULF",
    157 	[CORNER_UBR] = "URB",
    158 	[CORNER_DFR] = "DRF",
    159 	[CORNER_DBL] = "DLB"
    160 };
    161 
    162 STATIC const char *edgestr[] = {
    163 	[EDGE_UF] = "UF",
    164 	[EDGE_UB] = "UB",
    165 	[EDGE_DB] = "DB",
    166 	[EDGE_DF] = "DF",
    167 	[EDGE_UR] = "UR",
    168 	[EDGE_UL] = "UL",
    169 	[EDGE_DL] = "DL",
    170 	[EDGE_DR] = "DR",
    171 	[EDGE_FR] = "FR",
    172 	[EDGE_FL] = "FL",
    173 	[EDGE_BL] = "BL",
    174 	[EDGE_BR] = "BR"
    175 };
    176 
    177 STATIC const char *movestr[] = {
    178 	[MOVE_U]  = "U",
    179 	[MOVE_U2] = "U2",
    180 	[MOVE_U3] = "U'",
    181 	[MOVE_D]  = "D",
    182 	[MOVE_D2] = "D2",
    183 	[MOVE_D3] = "D'",
    184 	[MOVE_R]  = "R",
    185 	[MOVE_R2] = "R2",
    186 	[MOVE_R3] = "R'",
    187 	[MOVE_L]  = "L",
    188 	[MOVE_L2] = "L2",
    189 	[MOVE_L3] = "L'",
    190 	[MOVE_F]  = "F",
    191 	[MOVE_F2] = "F2",
    192 	[MOVE_F3] = "F'",
    193 	[MOVE_B]  = "B",
    194 	[MOVE_B2] = "B2",
    195 	[MOVE_B3] = "B'",
    196 };
    197 
    198 STATIC const char *transstr[] = {
    199 	[TRANS_UFr] = "rotation UF",
    200 	[TRANS_UFm] = "mirrored UF",
    201 	[TRANS_ULr] = "rotation UL",
    202 	[TRANS_ULm] = "mirrored UL",
    203 	[TRANS_UBr] = "rotation UB",
    204 	[TRANS_UBm] = "mirrored UB",
    205 	[TRANS_URr] = "rotation UR",
    206 	[TRANS_URm] = "mirrored UR",
    207 	[TRANS_DFr] = "rotation DF",
    208 	[TRANS_DFm] = "mirrored DF",
    209 	[TRANS_DLr] = "rotation DL",
    210 	[TRANS_DLm] = "mirrored DL",
    211 	[TRANS_DBr] = "rotation DB",
    212 	[TRANS_DBm] = "mirrored DB",
    213 	[TRANS_DRr] = "rotation DR",
    214 	[TRANS_DRm] = "mirrored DR",
    215 	[TRANS_RUr] = "rotation RU",
    216 	[TRANS_RUm] = "mirrored RU",
    217 	[TRANS_RFr] = "rotation RF",
    218 	[TRANS_RFm] = "mirrored RF",
    219 	[TRANS_RDr] = "rotation RD",
    220 	[TRANS_RDm] = "mirrored RD",
    221 	[TRANS_RBr] = "rotation RB",
    222 	[TRANS_RBm] = "mirrored RB",
    223 	[TRANS_LUr] = "rotation LU",
    224 	[TRANS_LUm] = "mirrored LU",
    225 	[TRANS_LFr] = "rotation LF",
    226 	[TRANS_LFm] = "mirrored LF",
    227 	[TRANS_LDr] = "rotation LD",
    228 	[TRANS_LDm] = "mirrored LD",
    229 	[TRANS_LBr] = "rotation LB",
    230 	[TRANS_LBm] = "mirrored LB",
    231 	[TRANS_FUr] = "rotation FU",
    232 	[TRANS_FUm] = "mirrored FU",
    233 	[TRANS_FRr] = "rotation FR",
    234 	[TRANS_FRm] = "mirrored FR",
    235 	[TRANS_FDr] = "rotation FD",
    236 	[TRANS_FDm] = "mirrored FD",
    237 	[TRANS_FLr] = "rotation FL",
    238 	[TRANS_FLm] = "mirrored FL",
    239 	[TRANS_BUr] = "rotation BU",
    240 	[TRANS_BUm] = "mirrored BU",
    241 	[TRANS_BRr] = "rotation BR",
    242 	[TRANS_BRm] = "mirrored BR",
    243 	[TRANS_BDr] = "rotation BD",
    244 	[TRANS_BDm] = "mirrored BD",
    245 	[TRANS_BLr] = "rotation BL",
    246 	[TRANS_BLm] = "mirrored BL",
    247 };
    248 
    249 static uint8_t inverse_trans_table[48] = {
    250 	[TRANS_UFr] = TRANS_UFr,
    251 	[TRANS_UFm] = TRANS_UFm,
    252 	[TRANS_ULr] = TRANS_URr,
    253 	[TRANS_ULm] = TRANS_ULm,
    254 	[TRANS_UBr] = TRANS_UBr,
    255 	[TRANS_UBm] = TRANS_UBm,
    256 	[TRANS_URr] = TRANS_ULr,
    257 	[TRANS_URm] = TRANS_URm,
    258 	[TRANS_DFr] = TRANS_DFr,
    259 	[TRANS_DFm] = TRANS_DFm,
    260 	[TRANS_DLr] = TRANS_DLr,
    261 	[TRANS_DLm] = TRANS_DRm,
    262 	[TRANS_DBr] = TRANS_DBr,
    263 	[TRANS_DBm] = TRANS_DBm,
    264 	[TRANS_DRr] = TRANS_DRr,
    265 	[TRANS_DRm] = TRANS_DLm,
    266 	[TRANS_RUr] = TRANS_FRr,
    267 	[TRANS_RUm] = TRANS_FLm,
    268 	[TRANS_RFr] = TRANS_LFr,
    269 	[TRANS_RFm] = TRANS_RFm,
    270 	[TRANS_RDr] = TRANS_BLr,
    271 	[TRANS_RDm] = TRANS_BRm,
    272 	[TRANS_RBr] = TRANS_RBr,
    273 	[TRANS_RBm] = TRANS_LBm,
    274 	[TRANS_LUr] = TRANS_FLr,
    275 	[TRANS_LUm] = TRANS_FRm,
    276 	[TRANS_LFr] = TRANS_RFr,
    277 	[TRANS_LFm] = TRANS_LFm,
    278 	[TRANS_LDr] = TRANS_BRr,
    279 	[TRANS_LDm] = TRANS_BLm,
    280 	[TRANS_LBr] = TRANS_LBr,
    281 	[TRANS_LBm] = TRANS_RBm,
    282 	[TRANS_FUr] = TRANS_FUr,
    283 	[TRANS_FUm] = TRANS_FUm,
    284 	[TRANS_FRr] = TRANS_RUr,
    285 	[TRANS_FRm] = TRANS_LUm,
    286 	[TRANS_FDr] = TRANS_BUr,
    287 	[TRANS_FDm] = TRANS_BUm,
    288 	[TRANS_FLr] = TRANS_LUr,
    289 	[TRANS_FLm] = TRANS_RUm,
    290 	[TRANS_BUr] = TRANS_FDr,
    291 	[TRANS_BUm] = TRANS_FDm,
    292 	[TRANS_BRr] = TRANS_LDr,
    293 	[TRANS_BRm] = TRANS_RDm,
    294 	[TRANS_BDr] = TRANS_BDr,
    295 	[TRANS_BDm] = TRANS_BDm,
    296 	[TRANS_BLr] = TRANS_RDr,
    297 	[TRANS_BLm] = TRANS_LDm,
    298 };