diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/solvers/coord/common.h | 20 | ||||
| -rw-r--r-- | src/solvers/coord/coord_solve.h | 3 | ||||
| -rw-r--r-- | src/solvers/coord/coord_types_macros.h | 13 | ||||
| -rw-r--r-- | src/solvers/coord/eo.h | 33 | ||||
| -rw-r--r-- | src/solvers/coord/gendata_coord.h | 134 | ||||
| -rw-r--r-- | src/solvers/solvers.h | 1 | ||||
| -rw-r--r-- | src/utils/constants.h | 2 |
7 files changed, 206 insertions, 0 deletions
diff --git a/src/solvers/coord/common.h b/src/solvers/coord/common.h new file mode 100644 index 0000000..b54e5e2 --- /dev/null +++ b/src/solvers/coord/common.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #include "eo.h" | ||
| 2 | |||
| 3 | coord_t *all_coordinates[] = { | ||
| 4 | &coordinate_eo, | ||
| 5 | NULL | ||
| 6 | }; | ||
| 7 | |||
| 8 | STATIC void append_coord_name(const coord_t *, char *); | ||
| 9 | |||
| 10 | STATIC void | ||
| 11 | append_coord_name(const coord_t *coord, char *str) | ||
| 12 | { | ||
| 13 | int i, j; | ||
| 14 | |||
| 15 | i = 0; | ||
| 16 | j = strlen(str); | ||
| 17 | while (coord->name[i]) str[j++] = coord->name[i++]; | ||
| 18 | |||
| 19 | str[j] = '\0'; | ||
| 20 | } | ||
diff --git a/src/solvers/coord/coord_solve.h b/src/solvers/coord/coord_solve.h new file mode 100644 index 0000000..1d7c036 --- /dev/null +++ b/src/solvers/coord/coord_solve.h | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | #include "coord_types_macros.h" | ||
| 2 | #include "common.h" | ||
| 3 | #include "gendata_coord.h" | ||
diff --git a/src/solvers/coord/coord_types_macros.h b/src/solvers/coord/coord_types_macros.h new file mode 100644 index 0000000..4f2877c --- /dev/null +++ b/src/solvers/coord/coord_types_macros.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #define COORD_INDEX(i) ((i)/2) | ||
| 2 | #define COORD_SHIFT(i) (UINT8_C(4) * (uint8_t)((i) % 2)) | ||
| 3 | #define COORD_MASK(i) (UINT8_C(0xF) << COORD_SHIFT(i)) | ||
| 4 | |||
| 5 | typedef struct { | ||
| 6 | char name[255]; | ||
| 7 | uint64_t (*coord)(cube_t, const void *); | ||
| 8 | cube_t (*cube)(uint64_t, const void *); | ||
| 9 | size_t (*gendata)(void *); | ||
| 10 | uint64_t max; | ||
| 11 | uint32_t moves_mask; | ||
| 12 | uint64_t trans_mask; | ||
| 13 | } coord_t; | ||
diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h new file mode 100644 index 0000000..d6604d9 --- /dev/null +++ b/src/solvers/coord/eo.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | STATIC uint64_t coordinate_eo_coord(cube_t, const void *); | ||
| 2 | STATIC cube_t coordinate_eo_cube(uint64_t, const void *); | ||
| 3 | STATIC uint64_t coordinate_eo_gendata(void *); | ||
| 4 | |||
| 5 | STATIC coord_t coordinate_eo = { | ||
| 6 | .name = "EO", | ||
| 7 | .coord = &coordinate_eo_coord, | ||
| 8 | .cube = &coordinate_eo_cube, | ||
| 9 | .gendata = coordinate_eo_gendata, | ||
| 10 | .max = POW_2_11, | ||
| 11 | .trans_mask = TM_ALLTRANS, | ||
| 12 | .moves_mask = MM_ALLMOVES, | ||
| 13 | }; | ||
| 14 | |||
| 15 | STATIC uint64_t | ||
| 16 | coordinate_eo_coord(cube_t c, const void *data) | ||
| 17 | { | ||
| 18 | return (uint64_t)coord_eo(c); | ||
| 19 | } | ||
| 20 | |||
| 21 | STATIC cube_t | ||
| 22 | coordinate_eo_cube(uint64_t c, const void *data) | ||
| 23 | { | ||
| 24 | cube_t cube = SOLVED_CUBE; | ||
| 25 | set_eo(&cube, (int64_t)c); | ||
| 26 | return cube; | ||
| 27 | } | ||
| 28 | |||
| 29 | STATIC size_t | ||
| 30 | coordinate_eo_gendata(void *data) | ||
| 31 | { | ||
| 32 | return 0; | ||
| 33 | } | ||
diff --git a/src/solvers/coord/gendata_coord.h b/src/solvers/coord/gendata_coord.h new file mode 100644 index 0000000..b3932cd --- /dev/null +++ b/src/solvers/coord/gendata_coord.h | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | STATIC size_t gendata_coordinate(const coord_t *, void *); | ||
| 2 | STATIC size_t gendata_coordinate_name(const char *, void *); | ||
| 3 | STATIC tableinfo_t genptable_coordinate(const coord_t *, const void *, uint8_t *); | ||
| 4 | STATIC uint8_t get_coord_pval(const coord_t *, const uint8_t *, uint64_t); | ||
| 5 | STATIC void set_coord_pval(const coord_t *, uint8_t *, uint64_t, uint8_t); | ||
| 6 | |||
| 7 | STATIC size_t | ||
| 8 | gendata_coordinate_name(const char *name, void *buf) | ||
| 9 | { | ||
| 10 | int i; | ||
| 11 | |||
| 12 | for (i = 0; all_coordinates[i] != NULL; i++) | ||
| 13 | if (strcmp(all_coordinates[i]->name, name) == 0) | ||
| 14 | return gendata_coordinate(all_coordinates[i], buf); | ||
| 15 | |||
| 16 | LOG("Cannot generate data for coordinate '%s': not found\n", name); | ||
| 17 | return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | STATIC size_t | ||
| 21 | gendata_coordinate(const coord_t *coord, void *buf) | ||
| 22 | { | ||
| 23 | uint64_t coord_dsize, tablesize, ninfo; | ||
| 24 | void *pruningbuf, *coord_data; | ||
| 25 | uint8_t *table; | ||
| 26 | tableinfo_t coord_data_info, pruning_info; | ||
| 27 | |||
| 28 | coord_data = buf == NULL ? NULL : ((uint8_t *)buf) + INFOSIZE; | ||
| 29 | coord_dsize = coord->gendata(coord_data); | ||
| 30 | ninfo = coord_dsize == 0 ? 1 : 2; | ||
| 31 | tablesize = DIV_ROUND_UP(coord->max, 2); | ||
| 32 | |||
| 33 | if (buf == NULL) | ||
| 34 | goto gendata_coordinate_return_size; | ||
| 35 | |||
| 36 | if (ninfo == 2) { | ||
| 37 | coord_data_info = (tableinfo_t) { | ||
| 38 | .solver = "coord helper table for ", | ||
| 39 | .type = TABLETYPE_SPECIAL, | ||
| 40 | .infosize = INFOSIZE, | ||
| 41 | .fullsize = INFOSIZE + coord_dsize, | ||
| 42 | .hash = 0, /* TODO */ | ||
| 43 | .next = INFOSIZE + coord_dsize, | ||
| 44 | |||
| 45 | /* Unknown / non-applicable values */ | ||
| 46 | .entries = 0, | ||
| 47 | .classes = 0, | ||
| 48 | .bits = 0, | ||
| 49 | .base = 0, | ||
| 50 | .maxvalue = 0, | ||
| 51 | }; | ||
| 52 | |||
| 53 | append_coord_name(coord, coord_data_info.solver); | ||
| 54 | |||
| 55 | writetableinfo(&coord_data_info, INFOSIZE + coord_dsize, buf); | ||
| 56 | |||
| 57 | pruningbuf = ((uint8_t *)buf) + INFOSIZE + coord_dsize; | ||
| 58 | } else { | ||
| 59 | pruningbuf = buf; | ||
| 60 | } | ||
| 61 | |||
| 62 | table = ((uint8_t *)pruningbuf) + INFOSIZE; | ||
| 63 | pruning_info = genptable_coordinate(coord, coord_data, table); | ||
| 64 | writetableinfo(&pruning_info, INFOSIZE + tablesize, pruningbuf); | ||
| 65 | |||
| 66 | gendata_coordinate_return_size: | ||
| 67 | return ninfo * INFOSIZE + coord_dsize + tablesize; | ||
| 68 | } | ||
| 69 | |||
| 70 | STATIC tableinfo_t | ||
| 71 | genptable_coordinate(const coord_t *coord, const void *data, uint8_t *table) | ||
| 72 | { | ||
| 73 | uint64_t tablesize, i, j, d, tot; | ||
| 74 | tableinfo_t info; | ||
| 75 | uint8_t m; | ||
| 76 | cube_t c, cc; | ||
| 77 | |||
| 78 | tablesize = DIV_ROUND_UP(coord->max, 2); | ||
| 79 | |||
| 80 | memset(table, 0xFF, tablesize); | ||
| 81 | |||
| 82 | info = (tableinfo_t) { | ||
| 83 | .solver = "coordinate solver for ", | ||
| 84 | .type = TABLETYPE_PRUNING, | ||
| 85 | .infosize = INFOSIZE, | ||
| 86 | .fullsize = INFOSIZE + tablesize, | ||
| 87 | .hash = 0, /* TODO */ | ||
| 88 | .entries = coord->max, | ||
| 89 | .classes = 0, | ||
| 90 | .bits = 4, | ||
| 91 | .base = 0, | ||
| 92 | .maxvalue = 0, | ||
| 93 | .next = 0 | ||
| 94 | }; | ||
| 95 | |||
| 96 | memset(info.distribution, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 97 | append_coord_name(coord, info.solver); | ||
| 98 | |||
| 99 | i = coord->coord(SOLVED_CUBE, data); | ||
| 100 | set_coord_pval(coord, table, i, 0); | ||
| 101 | info.distribution[0] = 1; | ||
| 102 | for (d = 1, tot = 1; tot < coord->max; d++) { | ||
| 103 | for (i = 0; i < coord->max; i++) { | ||
| 104 | if (get_coord_pval(coord, table, i) == d-1) { | ||
| 105 | c = coord->cube(i, data); | ||
| 106 | for (m = 0; m < 18; m++) { | ||
| 107 | cc = move(c, m); | ||
| 108 | j = coord->coord(cc, data); | ||
| 109 | if (get_coord_pval(coord, table, j) > d) { | ||
| 110 | set_coord_pval(coord, table, j, d); | ||
| 111 | tot++; | ||
| 112 | info.distribution[d]++; | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | info.maxvalue = d-1; | ||
| 119 | |||
| 120 | return info; | ||
| 121 | } | ||
| 122 | |||
| 123 | STATIC uint8_t | ||
| 124 | get_coord_pval(const coord_t *coord, const uint8_t *table, uint64_t i) | ||
| 125 | { | ||
| 126 | return (table[COORD_INDEX(i)] & COORD_MASK(i)) >> COORD_SHIFT(i); | ||
| 127 | } | ||
| 128 | |||
| 129 | STATIC void | ||
| 130 | set_coord_pval(const coord_t *coord, uint8_t *table, uint64_t i, uint8_t val) | ||
| 131 | { | ||
| 132 | table[COORD_INDEX(i)] = (table[COORD_INDEX(i)] & (~COORD_MASK(i))) | ||
| 133 | | (val << COORD_SHIFT(i)); | ||
| 134 | } | ||
diff --git a/src/solvers/solvers.h b/src/solvers/solvers.h index 7b7f355..154f8cc 100644 --- a/src/solvers/solvers.h +++ b/src/solvers/solvers.h | |||
| @@ -1,2 +1,3 @@ | |||
| 1 | #include "tables.h" | 1 | #include "tables.h" |
| 2 | #include "h48/h48.h" | 2 | #include "h48/h48.h" |
| 3 | #include "coord/coord_solve.h" | ||
diff --git a/src/utils/constants.h b/src/utils/constants.h index 1e4a630..3d8bf5e 100644 --- a/src/utils/constants.h +++ b/src/utils/constants.h | |||
| @@ -99,6 +99,8 @@ STATIC int64_t binomial[12][12] = { | |||
| 99 | #define MM_ALLMOVES UINT32_C(0x3FFFF) | 99 | #define MM_ALLMOVES UINT32_C(0x3FFFF) |
| 100 | #define MM_NOHALFTURNS UINT32_C(0x2DB6D) | 100 | #define MM_NOHALFTURNS UINT32_C(0x2DB6D) |
| 101 | 101 | ||
| 102 | #define TM_ALLTRANS UINT64_C(0xFFFFFFFFFFFF) | ||
| 103 | |||
| 102 | #define CORNER_UFR UINT8_C(0) | 104 | #define CORNER_UFR UINT8_C(0) |
| 103 | #define CORNER_UBL UINT8_C(1) | 105 | #define CORNER_UBL UINT8_C(1) |
| 104 | #define CORNER_DFL UINT8_C(2) | 106 | #define CORNER_DFL UINT8_C(2) |
