diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-03 21:52:16 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-03 21:52:16 +0200 |
| commit | c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8 (patch) | |
| tree | f4f569fcbd4d6704fb5dd44892911ce808f03332 /src/core/moves.h | |
| parent | ff4bde84872ec0b93f0f097f5a56bd5e7cbb0311 (diff) | |
| download | nissy-core-c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8.tar.gz nissy-core-c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8.zip | |
Moved stuff around
Diffstat (limited to 'src/core/moves.h')
| -rw-r--r-- | src/core/moves.h | 88 |
1 files changed, 43 insertions, 45 deletions
diff --git a/src/core/moves.h b/src/core/moves.h index 8f9c8f5..71ef470 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -1,13 +1,7 @@ | |||
| 1 | /* probably these can be placed in constants file */ | 1 | #define _move(M, c) compose(c, _move_cube_ ## M) |
| 2 | #define NORMAL 0x00 | 2 | #define _premove(M, c) compose(_move_cube_ ## M, c) |
| 3 | #define INVERSE 0x01 | ||
| 4 | #define INVERSEBRANCH 0x03 | ||
| 5 | #define NORMALBRANCH 0x02 | ||
| 6 | #define ALLMOVES 0x3FFFF | ||
| 7 | #define NOHALFTURNS 0x2DB6D | ||
| 8 | 3 | ||
| 9 | _static_inline bool allowednextmove(uint8_t *, uint8_t); | 4 | _static_inline bool allowednextmove(uint8_t *, uint8_t); |
| 10 | _static uint32_t allowednextmoveH48(uint8_t *, uint8_t, uint32_t); | ||
| 11 | 5 | ||
| 12 | _static_inline uint8_t inverse_trans(uint8_t); | 6 | _static_inline uint8_t inverse_trans(uint8_t); |
| 13 | _static_inline uint8_t movebase(uint8_t); | 7 | _static_inline uint8_t movebase(uint8_t); |
| @@ -17,7 +11,10 @@ _static_inline uint32_t disable_moves(uint32_t, uint8_t); | |||
| 17 | _static cube_t move(cube_t, uint8_t); | 11 | _static cube_t move(cube_t, uint8_t); |
| 18 | _static cube_t premove(cube_t, uint8_t); | 12 | _static cube_t premove(cube_t, uint8_t); |
| 19 | _static uint8_t inverse_move(uint8_t); | 13 | _static uint8_t inverse_move(uint8_t); |
| 20 | _static uint8_t* invertpremoves(uint8_t *, uint8_t); | 14 | _static void invertmoves(uint8_t *, uint8_t, uint8_t *); |
| 15 | |||
| 16 | _static cube_t applymoves(cube_t, const char *); | ||
| 17 | _static cube_t frommoves(const char *); | ||
| 21 | 18 | ||
| 22 | _static bool | 19 | _static bool |
| 23 | allowednextmove(uint8_t *moves, uint8_t n) | 20 | allowednextmove(uint8_t *moves, uint8_t n) |
| @@ -50,34 +47,6 @@ disable_moves(uint32_t current_result, uint8_t base_index) | |||
| 50 | return current_result & ~(7 << base_index); | 47 | return current_result & ~(7 << base_index); |
| 51 | } | 48 | } |
| 52 | 49 | ||
| 53 | _static uint32_t | ||
| 54 | allowednextmoveH48(uint8_t *moves, uint8_t n, uint32_t h48branch) | ||
| 55 | { | ||
| 56 | uint32_t result = ALLMOVES; | ||
| 57 | if (h48branch & NORMALBRANCH) | ||
| 58 | result &= NOHALFTURNS; | ||
| 59 | if (n < 1) | ||
| 60 | return result; | ||
| 61 | |||
| 62 | uint8_t base1 = movebase(moves[n-1]); | ||
| 63 | uint8_t axis1 = moveaxis(moves[n-1]); | ||
| 64 | |||
| 65 | result = disable_moves(result, base1 * 3); | ||
| 66 | if (base1 % 2) | ||
| 67 | result = disable_moves(result, (base1 - 1) * 3); | ||
| 68 | |||
| 69 | if (n == 1) | ||
| 70 | return result; | ||
| 71 | |||
| 72 | uint8_t base2 = movebase(moves[n-2]); | ||
| 73 | uint8_t axis2 = moveaxis(moves[n-2]); | ||
| 74 | |||
| 75 | if(axis1 == axis2) | ||
| 76 | result = disable_moves(result, base2 * 3); | ||
| 77 | |||
| 78 | return result; | ||
| 79 | } | ||
| 80 | |||
| 81 | _static_inline uint8_t | 50 | _static_inline uint8_t |
| 82 | inverse_trans(uint8_t t) | 51 | inverse_trans(uint8_t t) |
| 83 | { | 52 | { |
| @@ -194,17 +163,46 @@ inverse_move(uint8_t m) | |||
| 194 | return m - 2 * (m % 3) + 2; | 163 | return m - 2 * (m % 3) + 2; |
| 195 | } | 164 | } |
| 196 | 165 | ||
| 197 | _static uint8_t* | 166 | _static void |
| 198 | invertpremoves(uint8_t *moves, uint8_t nmoves) | 167 | invertmoves(uint8_t *moves, uint8_t nmoves, uint8_t *ret) |
| 199 | { | 168 | { |
| 200 | uint8_t i; | 169 | uint8_t i; |
| 201 | uint8_t *ret = malloc(nmoves * sizeof(uint8_t)); | ||
| 202 | 170 | ||
| 203 | for (i = 0; i < nmoves; i++) | 171 | for (i = 0; i < nmoves; i++) |
| 204 | ret[i] = inverse_move(moves[i]); | 172 | ret[i] = inverse_move(moves[nmoves - i - 1]); |
| 173 | } | ||
| 205 | 174 | ||
| 206 | // invert elements in the array | 175 | _static cube_t |
| 207 | for (i = 0; i < nmoves / 2; i++) | 176 | applymoves(cube_t cube, const char *buf) |
| 208 | _swap(ret[i], ret[nmoves - i - 1]); | 177 | { |
| 209 | return ret; | 178 | uint8_t r, m; |
| 179 | const char *b; | ||
| 180 | |||
| 181 | DBG_ASSERT(isconsistent(cube), zero, | ||
| 182 | "move error: inconsistent cube\n"); | ||
| 183 | |||
| 184 | for (b = buf; *b != '\0'; b++) { | ||
| 185 | while (*b == ' ' || *b == '\t' || *b == '\n') | ||
| 186 | b++; | ||
| 187 | if (*b == '\0') | ||
| 188 | goto applymoves_finish; | ||
| 189 | if ((r = readmove(*b)) == _error) | ||
| 190 | goto applymoves_error; | ||
| 191 | if ((m = readmodifier(*(b+1))) != 0) | ||
| 192 | b++; | ||
| 193 | cube = move(cube, r + m); | ||
| 194 | } | ||
| 195 | |||
| 196 | applymoves_finish: | ||
| 197 | return cube; | ||
| 198 | |||
| 199 | applymoves_error: | ||
| 200 | LOG("applymoves error\n"); | ||
| 201 | return zero; | ||
| 202 | } | ||
| 203 | |||
| 204 | _static cube_t | ||
| 205 | frommoves(const char *buf) | ||
| 206 | { | ||
| 207 | return applymoves(solved, buf); | ||
| 210 | } | 208 | } |
