diff options
| -rw-r--r-- | TODO.txt | 2 | ||||
| -rw-r--r-- | constants.h (renamed from tables.h) | 66 | ||||
| -rw-r--r-- | cube.c | 318 | ||||
| -rw-r--r-- | cube.h | 3 | ||||
| -rw-r--r-- | debugcube.o | bin | 113064 -> 0 bytes | |||
| -rw-r--r-- | test/001_cube_conversion/00_solved.in | 1 | ||||
| -rw-r--r-- | test/001_cube_conversion/00_solved.out | 1 | ||||
| -rw-r--r-- | test/001_cube_conversion/01_scrambled.in | 1 | ||||
| -rw-r--r-- | test/001_cube_conversion/01_scrambled.out | 1 | ||||
| -rw-r--r-- | test/001_cube_conversion/cube_conversion_tests.c | 27 | ||||
| -rw-r--r-- | test/050_compose/compose_tests.c | 4 | ||||
| -rw-r--r-- | test/071_coord_eo/coord_eo_tests.c | 7 | ||||
| -rw-r--r-- | test/072_coord_co/coord_co_tests.c | 7 | ||||
| -rw-r--r-- | test/last.err | 0 | ||||
| -rw-r--r-- | test/last.out | 1 |
15 files changed, 159 insertions, 280 deletions
diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..e8bf4f7 --- /dev/null +++ b/TODO.txt | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | - add public method apply move inplace | ||
| 2 | - make apply moves work inplace? | ||
| @@ -1,6 +1,72 @@ | |||
| 1 | #define NORMAL 0 | 1 | #define NORMAL 0 |
| 2 | #define INVERSE 1 | 2 | #define INVERSE 1 |
| 3 | 3 | ||
| 4 | #define _2p11 2048U | ||
| 5 | #define _2p12 4096U | ||
| 6 | #define _3p7 2187U | ||
| 7 | #define _3p8 6561U | ||
| 8 | #define _12c4 495U | ||
| 9 | #define _8c4 70U | ||
| 10 | |||
| 11 | #define _c_ufr 0U | ||
| 12 | #define _c_ubl 1U | ||
| 13 | #define _c_dfl 2U | ||
| 14 | #define _c_dbr 3U | ||
| 15 | #define _c_ufl 4U | ||
| 16 | #define _c_ubr 5U | ||
| 17 | #define _c_dfr 6U | ||
| 18 | #define _c_dbl 7U | ||
| 19 | |||
| 20 | #define _e_uf 0U | ||
| 21 | #define _e_ub 1U | ||
| 22 | #define _e_db 2U | ||
| 23 | #define _e_df 3U | ||
| 24 | #define _e_ur 4U | ||
| 25 | #define _e_ul 5U | ||
| 26 | #define _e_dl 6U | ||
| 27 | #define _e_dr 7U | ||
| 28 | #define _e_fr 8U | ||
| 29 | #define _e_fl 9U | ||
| 30 | #define _e_bl 10U | ||
| 31 | #define _e_br 11U | ||
| 32 | |||
| 33 | #define _eoshift 4U | ||
| 34 | #define _coshift 5U | ||
| 35 | |||
| 36 | #define _pbits 0xFU | ||
| 37 | #define _esepbit1 0x4U | ||
| 38 | #define _esepbit2 0x8U | ||
| 39 | #define _csepbit 0x4U | ||
| 40 | #define _eobit 0x10U | ||
| 41 | #define _cobits 0xF0U | ||
| 42 | #define _cobits2 0x60U | ||
| 43 | #define _ctwist_cw 0x20U | ||
| 44 | #define _ctwist_ccw 0x40U | ||
| 45 | #define _eflip 0x10U | ||
| 46 | #define _error 0xFFU | ||
| 47 | |||
| 48 | typedef enum { | ||
| 49 | U, U2, U3, D, D2, D3, | ||
| 50 | R, R2, R3, L, L2, L3, | ||
| 51 | F, F2, F3, B, B2, B3 | ||
| 52 | } move_t; | ||
| 53 | |||
| 54 | typedef enum { | ||
| 55 | UFr, ULr, UBr, URr, DFr, DLr, DBr, DRr, | ||
| 56 | RUr, RFr, RDr, RBr, LUr, LFr, LDr, LBr, | ||
| 57 | FUr, FRr, FDr, FLr, BUr, BRr, BDr, BLr, | ||
| 58 | |||
| 59 | UFm, ULm, UBm, URm, DFm, DLm, DBm, DRm, | ||
| 60 | RUm, RFm, RDm, RBm, LUm, LFm, LDm, LBm, | ||
| 61 | FUm, FRm, FDm, FLm, BUm, BRm, BDm, BLm | ||
| 62 | } trans_t; | ||
| 63 | |||
| 64 | _static cube_t zero = { .corner = {0}, .edge = {0} }; | ||
| 65 | _static cube_t solved = { | ||
| 66 | .corner = {0, 1, 2, 3, 4, 5, 6, 7}, | ||
| 67 | .edge = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} | ||
| 68 | }; | ||
| 69 | |||
| 4 | _static cube_t move_table[] = { | 70 | _static cube_t move_table[] = { |
| 5 | [U] = { | 71 | [U] = { |
| 6 | .corner = {5, 4, 2, 3, 0, 1, 6, 7}, | 72 | .corner = {5, 4, 2, 3, 0, 1, 6, 7}, |
| @@ -27,208 +27,9 @@ | |||
| 27 | 27 | ||
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | #define _2p11 2048U | 30 | #include "constants.h" |
| 31 | #define _2p12 4096U | ||
| 32 | #define _3p7 2187U | ||
| 33 | #define _3p8 6561U | ||
| 34 | #define _12c4 495U | ||
| 35 | #define _8c4 70U | ||
| 36 | |||
| 37 | #define _c_ufr 0U | ||
| 38 | #define _c_ubl 1U | ||
| 39 | #define _c_dfl 2U | ||
| 40 | #define _c_dbr 3U | ||
| 41 | #define _c_ufl 4U | ||
| 42 | #define _c_ubr 5U | ||
| 43 | #define _c_dfr 6U | ||
| 44 | #define _c_dbl 7U | ||
| 45 | |||
| 46 | #define _e_uf 0U | ||
| 47 | #define _e_ub 1U | ||
| 48 | #define _e_db 2U | ||
| 49 | #define _e_df 3U | ||
| 50 | #define _e_ur 4U | ||
| 51 | #define _e_ul 5U | ||
| 52 | #define _e_dl 6U | ||
| 53 | #define _e_dr 7U | ||
| 54 | #define _e_fr 8U | ||
| 55 | #define _e_fl 9U | ||
| 56 | #define _e_bl 10U | ||
| 57 | #define _e_br 11U | ||
| 58 | |||
| 59 | #define _eoshift 4U | ||
| 60 | #define _coshift 5U | ||
| 61 | |||
| 62 | #define _pbits 0xFU | ||
| 63 | #define _esepbit1 0x4U | ||
| 64 | #define _esepbit2 0x8U | ||
| 65 | #define _csepbit 0x4U | ||
| 66 | #define _eobit 0x10U | ||
| 67 | #define _cobits 0xF0U | ||
| 68 | #define _cobits2 0x60U | ||
| 69 | #define _ctwist_cw 0x20U | ||
| 70 | #define _ctwist_ccw 0x40U | ||
| 71 | #define _eflip 0x10U | ||
| 72 | #define _error 0xFFU | ||
| 73 | |||
| 74 | typedef enum { | ||
| 75 | U, U2, U3, D, D2, D3, | ||
| 76 | R, R2, R3, L, L2, L3, | ||
| 77 | F, F2, F3, B, B2, B3 | ||
| 78 | } move_t; | ||
| 79 | |||
| 80 | typedef enum { | ||
| 81 | UFr, ULr, UBr, URr, DFr, DLr, DBr, DRr, | ||
| 82 | RUr, RFr, RDr, RBr, LUr, LFr, LDr, LBr, | ||
| 83 | FUr, FRr, FDr, FLr, BUr, BRr, BDr, BLr, | ||
| 84 | |||
| 85 | UFm, ULm, UBm, URm, DFm, DLm, DBm, DRm, | ||
| 86 | RUm, RFm, RDm, RBm, LUm, LFm, LDm, LBm, | ||
| 87 | FUm, FRm, FDm, FLm, BUm, BRm, BDm, BLm | ||
| 88 | } trans_t; | ||
| 89 | |||
| 90 | _static cube_t zero = { .corner = {0}, .edge = {0} }; | ||
| 91 | _static cube_t solved = { | ||
| 92 | .corner = {0, 1, 2, 3, 4, 5, 6, 7}, | ||
| 93 | .edge = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} | ||
| 94 | }; | ||
| 95 | |||
| 96 | #include "tables.h" | ||
| 97 | |||
| 98 | /****************************************************************************** | ||
| 99 | Section: portable fast methods | ||
| 100 | |||
| 101 | This section contains performance-critical methods that do not use | ||
| 102 | advanced CPU instructions. They are used as an alternative to the ones | ||
| 103 | in the previous section(s) for unsupported architectures. | ||
| 104 | ******************************************************************************/ | ||
| 105 | |||
| 106 | typedef cube_t cube_fast_t; | ||
| 107 | |||
| 108 | _static cube_fast_t cubetofast(cube_t); | ||
| 109 | _static cube_t fasttocube(cube_fast_t); | ||
| 110 | _static_inline bool equal_fast(cube_fast_t, cube_fast_t); | ||
| 111 | _static_inline bool issolved_fast(cube_fast_t); | ||
| 112 | _static_inline cube_fast_t invertco_fast(cube_fast_t); | ||
| 113 | _static_inline cube_fast_t compose_fast(cube_fast_t, cube_fast_t); | ||
| 114 | |||
| 115 | _static_inline int64_t coord_fast_co(cube_fast_t); | ||
| 116 | _static_inline int64_t coord_fast_eo(cube_fast_t); | ||
| 117 | |||
| 118 | _static cube_fast_t | ||
| 119 | cubetofast(cube_t cube) | ||
| 120 | { | ||
| 121 | cube_fast_t fast; | ||
| 122 | memcpy(&fast, &cube, sizeof(cube_fast_t)); | ||
| 123 | return fast; | ||
| 124 | } | ||
| 125 | |||
| 126 | _static cube_t | ||
| 127 | fasttocube(cube_fast_t fast) | ||
| 128 | { | ||
| 129 | cube_t cube; | ||
| 130 | memcpy(&cube, &fast, sizeof(cube_fast_t)); | ||
| 131 | return cube; | ||
| 132 | } | ||
| 133 | |||
| 134 | _static_inline bool | ||
| 135 | equal_fast(cube_fast_t c1, cube_fast_t c2) | ||
| 136 | { | ||
| 137 | uint8_t i; | ||
| 138 | bool ret; | ||
| 139 | |||
| 140 | ret = true; | ||
| 141 | for (i = 0; i < 8; i++) | ||
| 142 | ret = ret && c1.corner[i] == c2.corner[i]; | ||
| 143 | for (i = 0; i < 12; i++) | ||
| 144 | ret = ret && c1.edge[i] == c2.edge[i]; | ||
| 145 | |||
| 146 | return ret; | ||
| 147 | } | ||
| 148 | |||
| 149 | _static_inline bool | ||
| 150 | issolved_fast(cube_fast_t cube) | ||
| 151 | { | ||
| 152 | return equal_fast(cube, solved); | ||
| 153 | } | ||
| 154 | |||
| 155 | _static_inline cube_fast_t | ||
| 156 | invertco_fast(cube_fast_t c) | ||
| 157 | { | ||
| 158 | uint8_t i, piece, orien; | ||
| 159 | cube_fast_t ret; | ||
| 160 | |||
| 161 | ret = c; | ||
| 162 | for (i = 0; i < 8; i++) { | ||
| 163 | piece = c.corner[i]; | ||
| 164 | orien = ((piece << 1) | (piece >> 1)) & _cobits2; | ||
| 165 | ret.corner[i] = (piece & _pbits) | orien; | ||
| 166 | } | ||
| 167 | |||
| 168 | return ret; | ||
| 169 | } | ||
| 170 | |||
| 171 | _static_inline cube_fast_t | ||
| 172 | compose_fast(cube_fast_t c1, cube_fast_t c2) | ||
| 173 | { | ||
| 174 | cube_fast_t ret; | ||
| 175 | uint8_t i, piece1, piece2, p, orien, aux, auy; | ||
| 176 | |||
| 177 | ret = zero; | ||
| 178 | |||
| 179 | for (i = 0; i < 12; i++) { | ||
| 180 | piece2 = c2.edge[i]; | ||
| 181 | p = piece2 & _pbits; | ||
| 182 | piece1 = c1.edge[p]; | ||
| 183 | orien = (piece2 ^ piece1) & _eobit; | ||
| 184 | ret.edge[i] = (piece1 & _pbits) | orien; | ||
| 185 | } | ||
| 186 | |||
| 187 | for (i = 0; i < 8; i++) { | ||
| 188 | piece2 = c2.corner[i]; | ||
| 189 | p = piece2 & _pbits; | ||
| 190 | piece1 = c1.corner[p]; | ||
| 191 | aux = (piece2 & _cobits) + (piece1 & _cobits); | ||
| 192 | auy = (aux + _ctwist_cw) >> 2U; | ||
| 193 | orien = (aux + auy) & _cobits2; | ||
| 194 | ret.corner[i] = (piece1 & _pbits) | orien; | ||
| 195 | } | ||
| 196 | |||
| 197 | return ret; | ||
| 198 | } | ||
| 199 | |||
| 200 | _static_inline int64_t | ||
| 201 | coord_fast_co(cube_fast_t c) | ||
| 202 | { | ||
| 203 | int i, p; | ||
| 204 | int64_t ret; | ||
| 205 | |||
| 206 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) | ||
| 207 | ret += p * (c.corner[i] >> _coshift); | ||
| 208 | |||
| 209 | return ret; | ||
| 210 | } | ||
| 211 | |||
| 212 | _static_inline int64_t | ||
| 213 | coord_fast_eo(cube_fast_t c) | ||
| 214 | { | ||
| 215 | int i, p; | ||
| 216 | int64_t ret; | ||
| 217 | |||
| 218 | for (ret = 0, i = 1, p = 1; i < 12; i++, p *= 2) | ||
| 219 | ret += p * (c.edge[i] >> _eoshift); | ||
| 220 | |||
| 221 | return ret; | ||
| 222 | } | ||
| 223 | |||
| 224 | /****************************************************************************** | ||
| 225 | Section: generic methods | ||
| 226 | |||
| 227 | This section contains generic functionality, including the public functions. | ||
| 228 | Some of these routines depend on the efficient functions implemented in the | ||
| 229 | previous sections, while some other operate directly on the cube. | ||
| 230 | ******************************************************************************/ | ||
| 231 | 31 | ||
| 32 | _static_inline cube_t invertco(cube_t); | ||
| 232 | _static int permsign(uint8_t *, int); | 33 | _static int permsign(uint8_t *, int); |
| 233 | _static uint8_t readco(char *); | 34 | _static uint8_t readco(char *); |
| 234 | _static uint8_t readcp(char *); | 35 | _static uint8_t readcp(char *); |
| @@ -245,8 +46,8 @@ _static uint8_t readmodifier(char); | |||
| 245 | _static uint8_t readtrans(char *); | 46 | _static uint8_t readtrans(char *); |
| 246 | _static int writemoves(uint8_t *, int, char *); | 47 | _static int writemoves(uint8_t *, int, char *); |
| 247 | _static void writetrans(uint8_t, char *); | 48 | _static void writetrans(uint8_t, char *); |
| 248 | _static cube_fast_t move(cube_fast_t, move_t); | 49 | _static cube_t move(cube_t, move_t); |
| 249 | _static cube_fast_t transform(cube_fast_t, trans_t); | 50 | _static cube_t transform(cube_t, trans_t); |
| 250 | 51 | ||
| 251 | cube_t | 52 | cube_t |
| 252 | cube_new(void) | 53 | cube_new(void) |
| @@ -393,10 +194,33 @@ cube_error(cube_t cube) | |||
| 393 | cube_t | 194 | cube_t |
| 394 | cube_compose(cube_t c1, cube_t c2) | 195 | cube_compose(cube_t c1, cube_t c2) |
| 395 | { | 196 | { |
| 197 | cube_t ret; | ||
| 198 | uint8_t i, piece1, piece2, p, orien, aux, auy; | ||
| 199 | |||
| 396 | DBG_ASSERT(cube_consistent(c1) && cube_consistent(c2), | 200 | DBG_ASSERT(cube_consistent(c1) && cube_consistent(c2), |
| 397 | zero, "cube_compose error: inconsistent cube\n") | 201 | zero, "cube_compose error: inconsistent cube\n") |
| 398 | 202 | ||
| 399 | return fasttocube(compose_fast(cubetofast(c1), cubetofast(c2))); | 203 | ret = zero; |
| 204 | |||
| 205 | for (i = 0; i < 12; i++) { | ||
| 206 | piece2 = c2.edge[i]; | ||
| 207 | p = piece2 & _pbits; | ||
| 208 | piece1 = c1.edge[p]; | ||
| 209 | orien = (piece2 ^ piece1) & _eobit; | ||
| 210 | ret.edge[i] = (piece1 & _pbits) | orien; | ||
| 211 | } | ||
| 212 | |||
| 213 | for (i = 0; i < 8; i++) { | ||
| 214 | piece2 = c2.corner[i]; | ||
| 215 | p = piece2 & _pbits; | ||
| 216 | piece1 = c1.corner[p]; | ||
| 217 | aux = (piece2 & _cobits) + (piece1 & _cobits); | ||
| 218 | auy = (aux + _ctwist_cw) >> 2U; | ||
| 219 | orien = (aux + auy) & _cobits2; | ||
| 220 | ret.corner[i] = (piece1 & _pbits) | orien; | ||
| 221 | } | ||
| 222 | |||
| 223 | return ret; | ||
| 400 | } | 224 | } |
| 401 | 225 | ||
| 402 | cube_t | 226 | cube_t |
| @@ -428,14 +252,14 @@ cube_inverse(cube_t cube) | |||
| 428 | cube_t | 252 | cube_t |
| 429 | applymoves(cube_t cube, char *buf) | 253 | applymoves(cube_t cube, char *buf) |
| 430 | { | 254 | { |
| 431 | cube_fast_t fast; | 255 | cube_t ret; |
| 432 | uint8_t r, m; | 256 | uint8_t r, m; |
| 433 | char *b; | 257 | char *b; |
| 434 | 258 | ||
| 435 | DBG_ASSERT(cube_consistent(cube), zero, | 259 | DBG_ASSERT(cube_consistent(cube), zero, |
| 436 | "move error: inconsistent cube\n"); | 260 | "move error: inconsistent cube\n"); |
| 437 | 261 | ||
| 438 | fast = cubetofast(cube); | 262 | ret = cube_clone(cube); |
| 439 | 263 | ||
| 440 | for (b = buf; *b != '\0'; b++) { | 264 | for (b = buf; *b != '\0'; b++) { |
| 441 | while (*b == ' ' || *b == '\t' || *b == '\n') | 265 | while (*b == ' ' || *b == '\t' || *b == '\n') |
| @@ -446,11 +270,11 @@ applymoves(cube_t cube, char *buf) | |||
| 446 | goto applymoves_error; | 270 | goto applymoves_error; |
| 447 | if ((m = readmodifier(*(b+1))) != 0) | 271 | if ((m = readmodifier(*(b+1))) != 0) |
| 448 | b++; | 272 | b++; |
| 449 | fast = move(fast, r + m); | 273 | ret = move(ret, r + m); |
| 450 | } | 274 | } |
| 451 | 275 | ||
| 452 | applymoves_finish: | 276 | applymoves_finish: |
| 453 | return fasttocube(fast); | 277 | return ret; |
| 454 | 278 | ||
| 455 | applymoves_error: | 279 | applymoves_error: |
| 456 | DBG_LOG("applymoves error\n"); | 280 | DBG_LOG("applymoves error\n"); |
| @@ -460,17 +284,41 @@ applymoves_error: | |||
| 460 | cube_t | 284 | cube_t |
| 461 | applytrans(cube_t cube, char *buf) | 285 | applytrans(cube_t cube, char *buf) |
| 462 | { | 286 | { |
| 463 | cube_fast_t fast; | 287 | cube_t ret; |
| 464 | uint8_t t; | 288 | uint8_t t; |
| 465 | 289 | ||
| 466 | DBG_ASSERT(cube_consistent(cube), zero, | 290 | DBG_ASSERT(cube_consistent(cube), zero, |
| 467 | "transformation error: inconsistent cube\n"); | 291 | "transformation error: inconsistent cube\n"); |
| 468 | 292 | ||
| 469 | t = readtrans(buf); | 293 | t = readtrans(buf); |
| 470 | fast = cubetofast(cube); | 294 | ret = cube_clone(cube); |
| 471 | fast = transform(fast, t); | 295 | ret = transform(ret, t); |
| 472 | 296 | ||
| 473 | return fasttocube(fast); | 297 | return cube_clone(ret); |
| 298 | } | ||
| 299 | |||
| 300 | int64_t | ||
| 301 | cube_coord_co(cube_t c) | ||
| 302 | { | ||
| 303 | int i, p; | ||
| 304 | int64_t ret; | ||
| 305 | |||
| 306 | for (ret = 0, i = 0, p = 1; i < 7; i++, p *= 3) | ||
| 307 | ret += p * (c.corner[i] >> _coshift); | ||
| 308 | |||
| 309 | return ret; | ||
| 310 | } | ||
| 311 | |||
| 312 | int64_t | ||
| 313 | cube_coord_eo(cube_t c) | ||
| 314 | { | ||
| 315 | int i, p; | ||
| 316 | int64_t ret; | ||
| 317 | |||
| 318 | for (ret = 0, i = 1, p = 1; i < 12; i++, p *= 2) | ||
| 319 | ret += p * (c.edge[i] >> _eoshift); | ||
| 320 | |||
| 321 | return ret; | ||
| 474 | } | 322 | } |
| 475 | 323 | ||
| 476 | cube_t | 324 | cube_t |
| @@ -808,14 +656,31 @@ writetrans(uint8_t t, char *buf) | |||
| 808 | buf[11] = '\0'; | 656 | buf[11] = '\0'; |
| 809 | } | 657 | } |
| 810 | 658 | ||
| 811 | _static cube_fast_t | 659 | _static cube_t |
| 812 | move(cube_fast_t c, move_t m) | 660 | move(cube_t c, move_t m) |
| 661 | { | ||
| 662 | return cube_compose(c, move_table[m]); | ||
| 663 | } | ||
| 664 | |||
| 665 | _static_inline cube_t | ||
| 666 | invertco(cube_t c) | ||
| 813 | { | 667 | { |
| 814 | return compose_fast(c, move_table[m]); | 668 | uint8_t i, piece, orien; |
| 669 | cube_t ret; | ||
| 670 | |||
| 671 | ret = c; | ||
| 672 | for (i = 0; i < 8; i++) { | ||
| 673 | piece = c.corner[i]; | ||
| 674 | orien = ((piece << 1) | (piece >> 1)) & _cobits2; | ||
| 675 | ret.corner[i] = (piece & _pbits) | orien; | ||
| 676 | } | ||
| 677 | |||
| 678 | return ret; | ||
| 815 | } | 679 | } |
| 816 | 680 | ||
| 817 | _static cube_fast_t | 681 | |
| 818 | transform(cube_fast_t c, trans_t t) | 682 | _static cube_t |
| 683 | transform(cube_t c, trans_t t) | ||
| 819 | { | 684 | { |
| 820 | cube_t tcube, tinv; | 685 | cube_t tcube, tinv; |
| 821 | 686 | ||
| @@ -823,28 +688,15 @@ transform(cube_fast_t c, trans_t t) | |||
| 823 | tinv = trans_table[t][INVERSE]; | 688 | tinv = trans_table[t][INVERSE]; |
| 824 | 689 | ||
| 825 | return t < 24 ? | 690 | return t < 24 ? |
| 826 | compose_fast(compose_fast(tcube, c), tinv) : | 691 | cube_compose(cube_compose(tcube, c), tinv) : |
| 827 | invertco_fast(compose_fast(compose_fast(tcube, c), tinv)); | 692 | invertco(cube_compose(cube_compose(tcube, c), tinv)); |
| 828 | } | 693 | } |
| 829 | 694 | ||
| 695 | /* TODO: expose or remove, maybe add inverse move */ | ||
| 830 | _static_inline uint8_t inverse_trans(uint8_t); | 696 | _static_inline uint8_t inverse_trans(uint8_t); |
| 831 | _static_inline uint8_t movebase(uint8_t); | ||
| 832 | _static_inline uint8_t moveaxis(uint8_t); | ||
| 833 | 697 | ||
| 834 | _static_inline uint8_t | 698 | _static_inline uint8_t |
| 835 | inverse_trans(uint8_t t) | 699 | inverse_trans(uint8_t t) |
| 836 | { | 700 | { |
| 837 | return inverse_trans_table[t]; | 701 | return inverse_trans_table[t]; |
| 838 | } | 702 | } |
| 839 | |||
| 840 | _static_inline uint8_t | ||
| 841 | movebase(uint8_t move) | ||
| 842 | { | ||
| 843 | return move / 3; | ||
| 844 | } | ||
| 845 | |||
| 846 | _static_inline uint8_t | ||
| 847 | moveaxis(uint8_t move) | ||
| 848 | { | ||
| 849 | return move / 6; | ||
| 850 | } | ||
| @@ -33,6 +33,9 @@ bool cube_error(cube_t); | |||
| 33 | cube_t cube_compose(cube_t, cube_t); | 33 | cube_t cube_compose(cube_t, cube_t); |
| 34 | cube_t cube_inverse(cube_t); | 34 | cube_t cube_inverse(cube_t); |
| 35 | 35 | ||
| 36 | int64_t cube_coord_co(cube_t); | ||
| 37 | int64_t cube_coord_eo(cube_t); | ||
| 38 | |||
| 36 | /****************************************************************************** | 39 | /****************************************************************************** |
| 37 | Read / write utilities | 40 | Read / write utilities |
| 38 | 41 | ||
diff --git a/debugcube.o b/debugcube.o deleted file mode 100644 index a37ffff..0000000 --- a/debugcube.o +++ /dev/null | |||
| Binary files differ | |||
diff --git a/test/001_cube_conversion/00_solved.in b/test/001_cube_conversion/00_solved.in deleted file mode 100644 index dff224d..0000000 --- a/test/001_cube_conversion/00_solved.in +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
diff --git a/test/001_cube_conversion/00_solved.out b/test/001_cube_conversion/00_solved.out deleted file mode 100644 index dff224d..0000000 --- a/test/001_cube_conversion/00_solved.out +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | UF0 UB0 DB0 DF0 UR0 UL0 DL0 DR0 FR0 FL0 BL0 BR0 UFR0 UBL0 DFL0 DBR0 UFL0 UBR0 DFR0 DBL0 | ||
diff --git a/test/001_cube_conversion/01_scrambled.in b/test/001_cube_conversion/01_scrambled.in deleted file mode 100644 index 453cc8a..0000000 --- a/test/001_cube_conversion/01_scrambled.in +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | BL1 DB0 UL1 DF0 BR1 UF1 DL0 FL1 UB0 DR1 FR1 UR1 UBR2 UBL1 DFR2 DBL2 DBR0 DFL0 UFR0 UFL2 | ||
diff --git a/test/001_cube_conversion/01_scrambled.out b/test/001_cube_conversion/01_scrambled.out deleted file mode 100644 index 453cc8a..0000000 --- a/test/001_cube_conversion/01_scrambled.out +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | BL1 DB0 UL1 DF0 BR1 UF1 DL0 FL1 UB0 DR1 FR1 UR1 UBR2 UBL1 DFR2 DBL2 DBR0 DFL0 UFR0 UFL2 | ||
diff --git a/test/001_cube_conversion/cube_conversion_tests.c b/test/001_cube_conversion/cube_conversion_tests.c deleted file mode 100644 index fe8a68f..0000000 --- a/test/001_cube_conversion/cube_conversion_tests.c +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | #include "../test.h" | ||
| 2 | |||
| 3 | cube_fast_t cubetofast(cube_t); | ||
| 4 | cube_t fasttocube(cube_fast_t); | ||
| 5 | bool equal(cube_t, cube_t); | ||
| 6 | |||
| 7 | int main(void) { | ||
| 8 | char cubestr[STRLENMAX]; | ||
| 9 | cube_t cube, cube2; | ||
| 10 | cube_fast_t fast; | ||
| 11 | |||
| 12 | fgets(cubestr, STRLENMAX, stdin); | ||
| 13 | cube = readcube("H48", cubestr); | ||
| 14 | fast = cubetofast(cube); | ||
| 15 | cube2 = fasttocube(fast); | ||
| 16 | |||
| 17 | if (cube_error(cube)) { | ||
| 18 | printf("Error reading cube\n"); | ||
| 19 | } else if (cube_error(cube2)) { | ||
| 20 | printf("Error converting cube\n"); | ||
| 21 | } else { | ||
| 22 | writecube("H48", cube2, cubestr); | ||
| 23 | printf("%s\n", cubestr); | ||
| 24 | } | ||
| 25 | |||
| 26 | return 0; | ||
| 27 | } | ||
diff --git a/test/050_compose/compose_tests.c b/test/050_compose/compose_tests.c index c0bbbef..3bf6c34 100644 --- a/test/050_compose/compose_tests.c +++ b/test/050_compose/compose_tests.c | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | #include "../test.h" | 1 | #include "../test.h" |
| 2 | 2 | ||
| 3 | cube_t compose(cube_t, cube_t); | ||
| 4 | |||
| 5 | int main(void) { | 3 | int main(void) { |
| 6 | char str[STRLENMAX]; | 4 | char str[STRLENMAX]; |
| 7 | cube_t c1, c2, c3; | 5 | cube_t c1, c2, c3; |
| @@ -11,7 +9,7 @@ int main(void) { | |||
| 11 | fgets(str, STRLENMAX, stdin); | 9 | fgets(str, STRLENMAX, stdin); |
| 12 | c2 = readcube("H48", str); | 10 | c2 = readcube("H48", str); |
| 13 | 11 | ||
| 14 | c3 = compose(c1, c2); | 12 | c3 = cube_compose(c1, c2); |
| 15 | 13 | ||
| 16 | if (cube_error(c3)) { | 14 | if (cube_error(c3)) { |
| 17 | printf("Error composing cubes\n"); | 15 | printf("Error composing cubes\n"); |
diff --git a/test/071_coord_eo/coord_eo_tests.c b/test/071_coord_eo/coord_eo_tests.c index 85128e0..5951042 100644 --- a/test/071_coord_eo/coord_eo_tests.c +++ b/test/071_coord_eo/coord_eo_tests.c | |||
| @@ -1,19 +1,14 @@ | |||
| 1 | #include "../test.h" | 1 | #include "../test.h" |
| 2 | 2 | ||
| 3 | int64_t coord_fast_eo(cube_fast_t); | ||
| 4 | cube_fast_t cubetofast(cube_t); | ||
| 5 | |||
| 6 | int main(void) { | 3 | int main(void) { |
| 7 | char str[STRLENMAX]; | 4 | char str[STRLENMAX]; |
| 8 | cube_t cube; | 5 | cube_t cube; |
| 9 | cube_fast_t fast; | ||
| 10 | int64_t result; | 6 | int64_t result; |
| 11 | 7 | ||
| 12 | fgets(str, STRLENMAX, stdin); | 8 | fgets(str, STRLENMAX, stdin); |
| 13 | cube = readcube("H48", str); | 9 | cube = readcube("H48", str); |
| 14 | fast = cubetofast(cube); | ||
| 15 | 10 | ||
| 16 | result = coord_fast_eo(fast); | 11 | result = cube_coord_eo(cube); |
| 17 | 12 | ||
| 18 | printf("%" PRId64 "\n", result); | 13 | printf("%" PRId64 "\n", result); |
| 19 | 14 | ||
diff --git a/test/072_coord_co/coord_co_tests.c b/test/072_coord_co/coord_co_tests.c index bb061e5..aa4136b 100644 --- a/test/072_coord_co/coord_co_tests.c +++ b/test/072_coord_co/coord_co_tests.c | |||
| @@ -1,19 +1,14 @@ | |||
| 1 | #include "../test.h" | 1 | #include "../test.h" |
| 2 | 2 | ||
| 3 | int64_t coord_fast_co(cube_fast_t); | ||
| 4 | cube_fast_t cubetofast(cube_t); | ||
| 5 | |||
| 6 | int main(void) { | 3 | int main(void) { |
| 7 | char str[STRLENMAX]; | 4 | char str[STRLENMAX]; |
| 8 | cube_t cube; | 5 | cube_t cube; |
| 9 | cube_fast_t fast; | ||
| 10 | int64_t result; | 6 | int64_t result; |
| 11 | 7 | ||
| 12 | fgets(str, STRLENMAX, stdin); | 8 | fgets(str, STRLENMAX, stdin); |
| 13 | cube = readcube("H48", str); | 9 | cube = readcube("H48", str); |
| 14 | fast = cubetofast(cube); | ||
| 15 | 10 | ||
| 16 | result = coord_fast_co(fast); | 11 | result = cube_coord_co(cube); |
| 17 | 12 | ||
| 18 | printf("%" PRId64 "\n", result); | 13 | printf("%" PRId64 "\n", result); |
| 19 | 14 | ||
diff --git a/test/last.err b/test/last.err deleted file mode 100644 index e69de29..0000000 --- a/test/last.err +++ /dev/null | |||
diff --git a/test/last.out b/test/last.out deleted file mode 100644 index 102ac1b..0000000 --- a/test/last.out +++ /dev/null | |||
| @@ -1 +0,0 @@ | |||
| 1 | UL1 UB0 DL1 UR0 BL1 DR1 BR0 DB0 FL1 UF0 FR1 DF0 DFR2 DFL0 DBL0 UFL0 UBR1 UBL0 UFR2 DBR1 | ||
