diff options
Diffstat (limited to 'src/solvers/coord')
| -rw-r--r-- | src/solvers/coord/checkdata.h | 65 | ||||
| -rw-r--r-- | src/solvers/coord/coord.h | 1 | ||||
| -rw-r--r-- | src/solvers/coord/dr.h | 16 | ||||
| -rw-r--r-- | src/solvers/coord/dreo.h | 14 | ||||
| -rw-r--r-- | src/solvers/coord/eo.h | 11 | ||||
| -rw-r--r-- | src/solvers/coord/gendata.h | 2 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 3 | ||||
| -rw-r--r-- | src/solvers/coord/types_macros.h | 2 | ||||
| -rw-r--r-- | src/solvers/coord/utils.h | 28 |
9 files changed, 123 insertions, 19 deletions
diff --git a/src/solvers/coord/checkdata.h b/src/solvers/coord/checkdata.h new file mode 100644 index 0000000..81394c7 --- /dev/null +++ b/src/solvers/coord/checkdata.h | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | STATIC long long checkdata_coord( | ||
| 2 | const char *, unsigned long long n, const unsigned char [n]); | ||
| 3 | |||
| 4 | STATIC long long | ||
| 5 | checkdata_coord( | ||
| 6 | const char *solver, | ||
| 7 | unsigned long long data_size, | ||
| 8 | const unsigned char data[data_size] | ||
| 9 | ) | ||
| 10 | { | ||
| 11 | coord_t *coord; | ||
| 12 | const unsigned char *table; | ||
| 13 | tableinfo_t info; | ||
| 14 | int64_t err; | ||
| 15 | uint64_t actual_distribution[INFO_DISTRIBUTION_LEN]; | ||
| 16 | |||
| 17 | if ((size_t)data % 8 != 0) { | ||
| 18 | LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); | ||
| 19 | return NISSY_ERROR_DATA; | ||
| 20 | } | ||
| 21 | |||
| 22 | parse_coord_and_axis(solver, &coord, NULL); | ||
| 23 | if (coord == NULL) { | ||
| 24 | LOG("[cehckdata] Unknown coordinate solver '%s'\n", solver); | ||
| 25 | return NISSY_ERROR_DATA; | ||
| 26 | } | ||
| 27 | |||
| 28 | table = data + INFOSIZE; | ||
| 29 | err = readtableinfo(data_size, data, &info); | ||
| 30 | if (err != NISSY_OK) { | ||
| 31 | LOG("[checkdata] Data is corrupt\n"); | ||
| 32 | return err; | ||
| 33 | } | ||
| 34 | |||
| 35 | if (info.type != TABLETYPE_PRUNING) { | ||
| 36 | LOG("[checkdata] Skipping '%s'\n", info.solver); | ||
| 37 | table += info.next; | ||
| 38 | err = readtableinfo_n(data_size, data, 2, &info); | ||
| 39 | if (err != NISSY_OK) { | ||
| 40 | LOG("[checkdata] Data is corrupt\n"); | ||
| 41 | return err; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | LOG("[checkdata] Checking distribution for '%s' from " | ||
| 46 | "table preamble\n", info.solver); | ||
| 47 | if (!distribution_equal(coord->pruning_distribution, | ||
| 48 | info.distribution, coord->pruning_max)) { | ||
| 49 | LOG("[checkdata] Distribution from the table preamble does " | ||
| 50 | "not match the expected one\n"); | ||
| 51 | return NISSY_ERROR_DATA; | ||
| 52 | } | ||
| 53 | |||
| 54 | LOG("\n[checkdata] Checking distribution for '%s' from " | ||
| 55 | "actual table\n", info.solver); | ||
| 56 | getdistribution(table, actual_distribution, &info); | ||
| 57 | if (!distribution_equal(coord->pruning_distribution, | ||
| 58 | actual_distribution, coord->pruning_max)) { | ||
| 59 | LOG("[checkdata] Distribution from the actual table does " | ||
| 60 | "not match the expected one\n"); | ||
| 61 | return NISSY_ERROR_DATA; | ||
| 62 | } | ||
| 63 | |||
| 64 | return NISSY_OK; | ||
| 65 | } | ||
diff --git a/src/solvers/coord/coord.h b/src/solvers/coord/coord.h index 2f24035..da93439 100644 --- a/src/solvers/coord/coord.h +++ b/src/solvers/coord/coord.h | |||
| @@ -6,4 +6,5 @@ | |||
| 6 | #include "list.h" | 6 | #include "list.h" |
| 7 | #include "utils.h" | 7 | #include "utils.h" |
| 8 | #include "gendata.h" | 8 | #include "gendata.h" |
| 9 | #include "checkdata.h" | ||
| 9 | #include "solve.h" | 10 | #include "solve.h" |
diff --git a/src/solvers/coord/dr.h b/src/solvers/coord/dr.h index 607cc39..d986742 100644 --- a/src/solvers/coord/dr.h +++ b/src/solvers/coord/dr.h | |||
| @@ -32,6 +32,22 @@ STATIC coord_t coordinate_dr = { | |||
| 32 | }, | 32 | }, |
| 33 | .is_admissible = &solution_lastqt_cw, | 33 | .is_admissible = &solution_lastqt_cw, |
| 34 | .is_solvable = &is_eoco_solvable, | 34 | .is_solvable = &is_eoco_solvable, |
| 35 | .pruning_distribution = { | ||
| 36 | [0] = 1, | ||
| 37 | [1] = 1, | ||
| 38 | [2] = 5, | ||
| 39 | [3] = 44, | ||
| 40 | [4] = 487, | ||
| 41 | [5] = 5841, | ||
| 42 | [6] = 68364, | ||
| 43 | [7] = 776568, | ||
| 44 | [8] = 7950748, | ||
| 45 | [9] = 52098876, | ||
| 46 | [10] = 76236234, | ||
| 47 | [11] = 3771112, | ||
| 48 | [12] = 129, | ||
| 49 | }, | ||
| 50 | .pruning_max = 12, | ||
| 35 | .sym = { | 51 | .sym = { |
| 36 | .classes = DREOESEP_CLASSES, | 52 | .classes = DREOESEP_CLASSES, |
| 37 | .max = DREOESEP_MAX, | 53 | .max = DREOESEP_MAX, |
diff --git a/src/solvers/coord/dreo.h b/src/solvers/coord/dreo.h index 1cce4e2..f6fa3e9 100644 --- a/src/solvers/coord/dreo.h +++ b/src/solvers/coord/dreo.h | |||
| @@ -27,6 +27,20 @@ STATIC coord_t coordinate_dreo = { | |||
| 27 | }, | 27 | }, |
| 28 | .is_admissible = &solution_lastqt_cw, | 28 | .is_admissible = &solution_lastqt_cw, |
| 29 | .is_solvable = &is_dreo_solvable, | 29 | .is_solvable = &is_dreo_solvable, |
| 30 | .pruning_distribution = { | ||
| 31 | [0] = 1, | ||
| 32 | [1] = 1, | ||
| 33 | [2] = 4, | ||
| 34 | [3] = 22, | ||
| 35 | [4] = 160, | ||
| 36 | [5] = 1286, | ||
| 37 | [6] = 8550, | ||
| 38 | [7] = 42152, | ||
| 39 | [8] = 90748, | ||
| 40 | [9] = 33466, | ||
| 41 | [10] = 757, | ||
| 42 | }, | ||
| 43 | .pruning_max = 10, | ||
| 30 | .sym = { | 44 | .sym = { |
| 31 | .classes = DRESEP_CLASSES, | 45 | .classes = DRESEP_CLASSES, |
| 32 | .max = COMB_12_4, | 46 | .max = COMB_12_4, |
diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h index 51dfb29..7735319 100644 --- a/src/solvers/coord/eo.h +++ b/src/solvers/coord/eo.h | |||
| @@ -20,6 +20,17 @@ STATIC coord_t coordinate_eo = { | |||
| 20 | }, | 20 | }, |
| 21 | .is_admissible = &solution_lastqt_cw, | 21 | .is_admissible = &solution_lastqt_cw, |
| 22 | .is_solvable = &is_eo_even, | 22 | .is_solvable = &is_eo_even, |
| 23 | .pruning_distribution = { | ||
| 24 | [0] = 1, | ||
| 25 | [1] = 2, | ||
| 26 | [2] = 25, | ||
| 27 | [3] = 202, | ||
| 28 | [4] = 620, | ||
| 29 | [5] = 900, | ||
| 30 | [6] = 285, | ||
| 31 | [7] = 13, | ||
| 32 | }, | ||
| 33 | .pruning_max = 7, | ||
| 23 | .sym = {0}, | 34 | .sym = {0}, |
| 24 | }; | 35 | }; |
| 25 | 36 | ||
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index 1b65f49..0cc012e 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h | |||
| @@ -22,7 +22,7 @@ gendata_coord_dispatch( | |||
| 22 | { | 22 | { |
| 23 | coord_t *coord; | 23 | coord_t *coord; |
| 24 | 24 | ||
| 25 | parse_coord_and_axis(strlen(coordstr), coordstr, &coord, NULL); | 25 | parse_coord_and_axis(coordstr, &coord, NULL); |
| 26 | 26 | ||
| 27 | if (coord == NULL) { | 27 | if (coord == NULL) { |
| 28 | LOG("Error: could not parse coordinate '%s'\n", coordstr); | 28 | LOG("Error: could not parse coordinate '%s'\n", coordstr); |
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index df0f6ff..659040c 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -222,8 +222,7 @@ solve_coord_dispatch( | |||
| 222 | coord_t *coord; | 222 | coord_t *coord; |
| 223 | uint8_t axis; | 223 | uint8_t axis; |
| 224 | 224 | ||
| 225 | parse_coord_and_axis( | 225 | parse_coord_and_axis(coord_and_axis, &coord, &axis); |
| 226 | strlen(coord_and_axis), coord_and_axis, &coord, &axis); | ||
| 227 | 226 | ||
| 228 | if (coord == NULL) { | 227 | if (coord == NULL) { |
| 229 | LOG("Error: could not parse coordinate from '%s'\n", | 228 | LOG("Error: could not parse coordinate from '%s'\n", |
diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h index a5ac7f3..0c7a3a2 100644 --- a/src/solvers/coord/types_macros.h +++ b/src/solvers/coord/types_macros.h | |||
| @@ -26,6 +26,8 @@ typedef struct { | |||
| 26 | uint8_t axistrans[3]; | 26 | uint8_t axistrans[3]; |
| 27 | bool (*is_admissible)(const solution_moves_t[static 1]); | 27 | bool (*is_admissible)(const solution_moves_t[static 1]); |
| 28 | bool (*is_solvable)(cube_t); | 28 | bool (*is_solvable)(cube_t); |
| 29 | uint64_t pruning_distribution[INFO_DISTRIBUTION_LEN]; | ||
| 30 | uint8_t pruning_max; | ||
| 29 | struct { | 31 | struct { |
| 30 | size_t classes; | 32 | size_t classes; |
| 31 | uint64_t max; | 33 | uint64_t max; |
diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h index aa4d74c..6066049 100644 --- a/src/solvers/coord/utils.h +++ b/src/solvers/coord/utils.h | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | STATIC coord_t *parse_coord(size_t n, const char [n]); | 1 | STATIC coord_t *parse_coord(size_t n, const char [n]); |
| 2 | STATIC uint8_t parse_axis(size_t n, const char [n]); | 2 | STATIC uint8_t parse_axis(const char [static 2]); |
| 3 | STATIC void parse_coord_and_axis( | 3 | STATIC void parse_coord_and_axis(const char *, coord_t **, uint8_t *); |
| 4 | size_t n, const char [n], coord_t **, uint8_t *); | ||
| 5 | STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); | 4 | STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); |
| 6 | 5 | ||
| 7 | STATIC coord_t * | 6 | STATIC coord_t * |
| @@ -17,13 +16,13 @@ parse_coord(size_t n, const char coord[n]) | |||
| 17 | } | 16 | } |
| 18 | 17 | ||
| 19 | STATIC uint8_t | 18 | STATIC uint8_t |
| 20 | parse_axis(size_t n, const char axis[n]) | 19 | parse_axis(const char axis[static 2]) |
| 21 | { | 20 | { |
| 22 | if (!strncmp(axis, "UD", n) || !strncmp(axis, "DU", n)) { | 21 | if (!strcmp(axis, "UD") || !strcmp(axis, "DU")) { |
| 23 | return AXIS_UD; | 22 | return AXIS_UD; |
| 24 | } else if (!strncmp(axis, "RL", n) || !strncmp(axis, "LR", n)) { | 23 | } else if (!strcmp(axis, "RL") || !strcmp(axis, "LR")) { |
| 25 | return AXIS_RL; | 24 | return AXIS_RL; |
| 26 | } else if (!strncmp(axis, "FB", n) || !strncmp(axis, "BF", n)) { | 25 | } else if (!strcmp(axis, "FB") || !strcmp(axis, "BF")) { |
| 27 | return AXIS_FB; | 26 | return AXIS_FB; |
| 28 | } | 27 | } |
| 29 | 28 | ||
| @@ -32,25 +31,22 @@ parse_axis(size_t n, const char axis[n]) | |||
| 32 | 31 | ||
| 33 | STATIC void | 32 | STATIC void |
| 34 | parse_coord_and_axis( | 33 | parse_coord_and_axis( |
| 35 | size_t n, | 34 | const char *str, |
| 36 | const char str[n], | ||
| 37 | coord_t **coord, | 35 | coord_t **coord, |
| 38 | uint8_t *axis | 36 | uint8_t *axis |
| 39 | ) | 37 | ) |
| 40 | { | 38 | { |
| 41 | const char *s; | ||
| 42 | size_t i; | 39 | size_t i; |
| 43 | 40 | ||
| 44 | s = str + 6; | 41 | for (i = 6; i < strlen(str); i++) |
| 45 | for (i = 0; i < n; i++) | 42 | if (str[i] == '_') |
| 46 | if (s[i] == '_') | ||
| 47 | break; | 43 | break; |
| 48 | 44 | ||
| 49 | if (coord != NULL) | 45 | if (coord != NULL) |
| 50 | *coord = parse_coord(i, s); | 46 | *coord = parse_coord(i-6, str+6); |
| 51 | 47 | ||
| 52 | if (axis != NULL) | 48 | if (axis != NULL) |
| 53 | *axis = i == n ? UINT8_ERROR : parse_axis(n-i-1, s+i+1); | 49 | *axis = i == strlen(str) ? UINT8_ERROR : parse_axis(str+i+1); |
| 54 | } | 50 | } |
| 55 | 51 | ||
| 56 | STATIC long long | 52 | STATIC long long |
| @@ -58,7 +54,7 @@ dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) | |||
| 58 | { | 54 | { |
| 59 | coord_t *c; | 55 | coord_t *c; |
| 60 | 56 | ||
| 61 | parse_coord_and_axis(strlen(ca), ca, &c, NULL); | 57 | parse_coord_and_axis(ca, &c, NULL); |
| 62 | 58 | ||
| 63 | if (c == NULL) { | 59 | if (c == NULL) { |
| 64 | LOG("Error: cannot parse coordinate from '%s'\n", ca); | 60 | LOG("Error: cannot parse coordinate from '%s'\n", ca); |
