diff options
Diffstat (limited to 'src/solvers/coord/common.h')
| -rw-r--r-- | src/solvers/coord/common.h | 88 |
1 files changed, 28 insertions, 60 deletions
diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h index 8553658..4cfc36f 100644 --- a/src/solvers/coord/common.h +++ b/src/solvers/coord/common.h | |||
| @@ -1,13 +1,7 @@ | |||
| 1 | coord_t *all_coordinates[] = { | ||
| 2 | &coordinate_eo, | ||
| 3 | NULL | ||
| 4 | }; | ||
| 5 | |||
| 6 | STATIC void append_coord_name(const coord_t *, char *); | 1 | STATIC void append_coord_name(const coord_t *, char *); |
| 7 | STATIC coord_t *parse_coord(size_t n, const char [n]); | 2 | STATIC bool solution_lastqt_cw(const solution_moves_t [static 1]); |
| 8 | STATIC uint8_t parse_axis(size_t n, const char [n]); | 3 | STATIC bool coord_can_switch( |
| 9 | STATIC void parse_coord_and_axis(size_t n, const char [n], coord_t **, uint8_t *); | 4 | const coord_t [static 1], const void *, size_t n, const uint8_t [n]); |
| 10 | STATIC int64_t dataid_coord(const char *, char [static NISSY_DATAID_SIZE]); | ||
| 11 | 5 | ||
| 12 | STATIC void | 6 | STATIC void |
| 13 | append_coord_name(const coord_t *coord, char *str) | 7 | append_coord_name(const coord_t *coord, char *str) |
| @@ -21,66 +15,40 @@ append_coord_name(const coord_t *coord, char *str) | |||
| 21 | str[j] = '\0'; | 15 | str[j] = '\0'; |
| 22 | } | 16 | } |
| 23 | 17 | ||
| 24 | STATIC coord_t * | 18 | STATIC bool |
| 25 | parse_coord(size_t n, const char coord[n]) | 19 | solution_lastqt_cw(const solution_moves_t s[static 1]) |
| 26 | { | 20 | { |
| 27 | int i; | 21 | return are_lastmoves_singlecw(s->nmoves, s->moves) && |
| 28 | 22 | are_lastmoves_singlecw(s->npremoves, s->premoves); | |
| 29 | for (i = 0; all_coordinates[i] != NULL; i++) | ||
| 30 | if (!strncmp(all_coordinates[i]->name, coord, n)) | ||
| 31 | return all_coordinates[i]; | ||
| 32 | |||
| 33 | return NULL; | ||
| 34 | } | ||
| 35 | |||
| 36 | STATIC uint8_t | ||
| 37 | parse_axis(size_t n, const char axis[n]) | ||
| 38 | { | ||
| 39 | if (!strncmp(axis, "UD", n) || !strncmp(axis, "DU", n)) { | ||
| 40 | return AXIS_UD; | ||
| 41 | } else if (!strncmp(axis, "RL", n) || !strncmp(axis, "LR", n)) { | ||
| 42 | return AXIS_RL; | ||
| 43 | } else if (!strncmp(axis, "FB", n) || !strncmp(axis, "BF", n)) { | ||
| 44 | return AXIS_FB; | ||
| 45 | } | ||
| 46 | |||
| 47 | return UINT8_ERROR; | ||
| 48 | } | 23 | } |
| 49 | 24 | ||
| 50 | STATIC void | 25 | STATIC bool |
| 51 | parse_coord_and_axis( | 26 | coord_can_switch( |
| 27 | const coord_t coord[static 1], | ||
| 28 | const void *data, | ||
| 52 | size_t n, | 29 | size_t n, |
| 53 | const char str[n], | 30 | const uint8_t moves[n] |
| 54 | coord_t **coord, | ||
| 55 | uint8_t *axis | ||
| 56 | ) | 31 | ) |
| 57 | { | 32 | { |
| 58 | size_t i; | 33 | /* |
| 59 | 34 | This function checks that the last move (or two moves, if parallel) | |
| 60 | for (i = 0; i < n; i++) | 35 | have a non-trivial effect on the coordinate of the solved cube. This |
| 61 | if (str[i] == '_') | 36 | works in general for all coordinates that have been used so far, but |
| 62 | break; | 37 | in more general cases that have not been considered yet it may fail. |
| 63 | 38 | */ | |
| 64 | if (coord != NULL) | ||
| 65 | *coord = parse_coord(i, str); | ||
| 66 | 39 | ||
| 67 | if (axis != NULL) | 40 | uint64_t i; |
| 68 | *axis = i == n ? UINT8_ERROR : parse_axis(n-i-1, str+i+1); | ||
| 69 | } | ||
| 70 | |||
| 71 | STATIC int64_t | ||
| 72 | dataid_coord(const char *ca, char dataid[static NISSY_DATAID_SIZE]) | ||
| 73 | { | ||
| 74 | coord_t *c; | ||
| 75 | 41 | ||
| 76 | parse_coord_and_axis(strlen(ca), ca, &c, NULL); | 42 | if (n == 0) |
| 43 | return true; | ||
| 77 | 44 | ||
| 78 | if (c == NULL) { | 45 | i = coord->coord(move(SOLVED_CUBE, moves[n-1]), data); |
| 79 | LOG("dataid_coord: cannot parse coordinate from '%s'\n", ca); | 46 | if (i == 0) |
| 80 | return NISSY_ERROR_INVALID_SOLVER; | 47 | return false; |
| 81 | } | ||
| 82 | 48 | ||
| 83 | strcpy(dataid, c->name); | 49 | if (n == 1 || !parallel(moves[n-1], moves[n-2])) |
| 50 | return true; | ||
| 84 | 51 | ||
| 85 | return NISSY_OK; | 52 | i = coord->coord(move(SOLVED_CUBE, moves[n-1]), data); |
| 53 | return i != 0; | ||
| 86 | } | 54 | } |
