diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cube_generic.h | 37 | ||||
| -rw-r--r-- | src/utils.h | 6 |
2 files changed, 28 insertions, 15 deletions
diff --git a/src/cube_generic.h b/src/cube_generic.h index c40844d..fe36f90 100644 --- a/src/cube_generic.h +++ b/src/cube_generic.h | |||
| @@ -185,34 +185,45 @@ frommoves(const char *buf) | |||
| 185 | _static void | 185 | _static void |
| 186 | getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) | 186 | getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) |
| 187 | { | 187 | { |
| 188 | uint8_t e[12], c[8], aux; | 188 | uint8_t e[12], c[8], coarr[8]; |
| 189 | 189 | ||
| 190 | *ep %= _12f; | 190 | *ep = (*ep % _12f + _12f) % _12f; |
| 191 | *eo %= _2p11; | 191 | *eo = (*eo % _2p11 + _2p11) % _2p11; |
| 192 | *cp %= _8f; | 192 | *cp = (*cp % _8f + _8f) % _8f; |
| 193 | *cp %= _3p7; | 193 | *co = (*cp % _3p7 + _3p7) % _3p7; |
| 194 | 194 | ||
| 195 | indextoperm(*ep, 12, e); | 195 | indextoperm(*ep, 12, e); |
| 196 | indextoperm(*cp, 8, c); | 196 | indextoperm(*cp, 8, c); |
| 197 | if (permsign(e, 12) != permsign(c, 8)) { | 197 | if (permsign(e, 12) != permsign(c, 8)) { |
| 198 | aux = c[0]; | 198 | _swap(c[0], c[1]); |
| 199 | c[0] = c[1]; | ||
| 200 | c[1] = aux; | ||
| 201 | *cp = permtoindex(c, 8); | 199 | *cp = permtoindex(c, 8); |
| 200 | |||
| 201 | sumzerotodigits(*co, 8, 3, coarr); | ||
| 202 | _swap(coarr[0], coarr[1]); | ||
| 203 | *co = digitstosumzero(coarr, 8, 3); | ||
| 202 | } | 204 | } |
| 203 | } | 205 | } |
| 204 | 206 | ||
| 205 | _static cube_t | 207 | _static cube_t |
| 206 | getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co) | 208 | getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co) |
| 207 | { | 209 | { |
| 208 | uint8_t e[12], c[8]; | 210 | uint8_t i, earr[12], carr[8], eoarr[12], coarr[8]; |
| 209 | 211 | ||
| 210 | indextoperm(ep, 12, e); | 212 | sumzerotodigits(eo, 12, 2, eoarr); |
| 211 | indextoperm(cp, 8, c); | 213 | DBG_ASSERT(eoarr[0] != _error, zero, "Error making EO"); |
| 214 | indextoperm(ep, 12, earr); | ||
| 215 | DBG_ASSERT(earr[0] != _error, zero, "Error making EP"); | ||
| 216 | for (i = 0; i < 12; i++) | ||
| 217 | earr[i] |= eoarr[i] << _eoshift; | ||
| 212 | 218 | ||
| 213 | /* TODO: orientation */ | 219 | sumzerotodigits(co, 8, 3, coarr); |
| 220 | DBG_ASSERT(coarr[0] != _error, zero, "Error making CO"); | ||
| 221 | indextoperm(cp, 8, carr); | ||
| 222 | DBG_ASSERT(carr[0] != _error, zero, "Error making CP"); | ||
| 223 | for (i = 0; i < 8; i++) | ||
| 224 | carr[i] |= coarr[i] << _coshift; | ||
| 214 | 225 | ||
| 215 | return cubefromarray(c, e); | 226 | return cubefromarray(carr, earr); |
| 216 | } | 227 | } |
| 217 | 228 | ||
| 218 | _static cube_t | 229 | _static cube_t |
diff --git a/src/utils.h b/src/utils.h index 3d35437..021ca75 100644 --- a/src/utils.h +++ b/src/utils.h | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | #define _swap(x, y) do { x ^= y; y ^= x; x ^= y; } while (0) | ||
| 2 | |||
| 1 | _static int64_t factorial(int64_t); | 3 | _static int64_t factorial(int64_t); |
| 2 | _static bool isperm(uint8_t *, int64_t); | 4 | _static bool isperm(uint8_t *, int64_t); |
| 3 | _static int64_t permtoindex(uint8_t *, int64_t); | 5 | _static int64_t permtoindex(uint8_t *, int64_t); |
| @@ -138,7 +140,7 @@ digitstosumzero(uint8_t *a, uint8_t n, uint8_t b) | |||
| 138 | return -1; | 140 | return -1; |
| 139 | } | 141 | } |
| 140 | 142 | ||
| 141 | for (i = 1, ret = 0, p = 1; i < n; i++, p *= (int64_t)b) { | 143 | for (i = 1, ret = 0, p = 1, sum = 0; i < n; i++, p *= (int64_t)b) { |
| 142 | if (a[i] >= b) { | 144 | if (a[i] >= b) { |
| 143 | LOG("Error: digit %" PRIu8 " larger than maximum" | 145 | LOG("Error: digit %" PRIu8 " larger than maximum" |
| 144 | " (b=%" PRIu8 "\n", a[i], b); | 146 | " (b=%" PRIu8 "\n", a[i], b); |
| @@ -168,7 +170,7 @@ sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a) | |||
| 168 | goto digitstosumzero_error; | 170 | goto digitstosumzero_error; |
| 169 | } | 171 | } |
| 170 | 172 | ||
| 171 | for (i = 1; i < n; i++, d /= (int64_t)b) { | 173 | for (i = 1, sum = 0; i < n; i++, d /= (int64_t)b) { |
| 172 | a[i] = (uint8_t)(d % (int64_t)b); | 174 | a[i] = (uint8_t)(d % (int64_t)b); |
| 173 | sum += a[i]; | 175 | sum += a[i]; |
| 174 | } | 176 | } |
