diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-01 11:26:49 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-01 11:26:49 +0200 |
| commit | 10632e9fa6e8037cd584a29536e6ab1be9ca359b (patch) | |
| tree | 56109926836991279a86eee054f260549e41ca7a /src | |
| parent | a107b58dc4c34c187e31065293124e722158b919 (diff) | |
| download | nissy-core-10632e9fa6e8037cd584a29536e6ab1be9ca359b.tar.gz nissy-core-10632e9fa6e8037cd584a29536e6ab1be9ca359b.zip | |
Reworked coordinate solver axis specification
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/transform.h | 13 | ||||
| -rw-r--r-- | src/solvers/coord/checkdata.h | 2 | ||||
| -rw-r--r-- | src/solvers/coord/dr.h | 5 | ||||
| -rw-r--r-- | src/solvers/coord/dreo.h | 5 | ||||
| -rw-r--r-- | src/solvers/coord/drfinnoe.h | 5 | ||||
| -rw-r--r-- | src/solvers/coord/drslice.h | 5 | ||||
| -rw-r--r-- | src/solvers/coord/eo.h | 5 | ||||
| -rw-r--r-- | src/solvers/coord/gendata.h | 2 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 23 | ||||
| -rw-r--r-- | src/solvers/coord/types_macros.h | 1 | ||||
| -rw-r--r-- | src/solvers/coord/utils.h | 32 |
11 files changed, 37 insertions, 61 deletions
diff --git a/src/core/transform.h b/src/core/transform.h index 91d4893..f19c44f 100644 --- a/src/core/transform.h +++ b/src/core/transform.h | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | TRANS_CUBE_ ## T ## _INVERSE)) | 18 | TRANS_CUBE_ ## T ## _INVERSE)) |
| 19 | 19 | ||
| 20 | STATIC uint8_t readtrans(const char [static NISSY_SIZE_TRANSFORMATION]); | 20 | STATIC uint8_t readtrans(const char [static NISSY_SIZE_TRANSFORMATION]); |
| 21 | STATIC uint8_t readrotation(const char [static 2]); | ||
| 21 | STATIC void writetrans(uint8_t, char [static NISSY_SIZE_TRANSFORMATION]); | 22 | STATIC void writetrans(uint8_t, char [static NISSY_SIZE_TRANSFORMATION]); |
| 22 | 23 | ||
| 23 | STATIC cube_t transform_edges(cube_t, uint8_t); | 24 | STATIC cube_t transform_edges(cube_t, uint8_t); |
| @@ -39,6 +40,18 @@ readtrans(const char buf[static NISSY_SIZE_TRANSFORMATION]) | |||
| 39 | return UINT8_ERROR; | 40 | return UINT8_ERROR; |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 43 | STATIC uint8_t | ||
| 44 | readrotation(const char buf[static 2]) | ||
| 45 | { | ||
| 46 | char trans_str[NISSY_SIZE_TRANSFORMATION]; | ||
| 47 | |||
| 48 | strcpy(trans_str, "rotation xx"); | ||
| 49 | trans_str[9] = buf[0]; | ||
| 50 | trans_str[10] = buf[1]; | ||
| 51 | |||
| 52 | return readtrans(trans_str); | ||
| 53 | } | ||
| 54 | |||
| 42 | STATIC void | 55 | STATIC void |
| 43 | writetrans(uint8_t t, char buf[static NISSY_SIZE_TRANSFORMATION]) | 56 | writetrans(uint8_t t, char buf[static NISSY_SIZE_TRANSFORMATION]) |
| 44 | { | 57 | { |
diff --git a/src/solvers/coord/checkdata.h b/src/solvers/coord/checkdata.h index 791761f..e448e8f 100644 --- a/src/solvers/coord/checkdata.h +++ b/src/solvers/coord/checkdata.h | |||
| @@ -19,7 +19,7 @@ checkdata_coord( | |||
| 19 | return NISSY_ERROR_DATA; | 19 | return NISSY_ERROR_DATA; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | parse_coord_and_axis(solver, &coord, NULL); | 22 | parse_coord_and_trans(solver, &coord, NULL); |
| 23 | if (coord == NULL) { | 23 | if (coord == NULL) { |
| 24 | LOG("[cehckdata] Unknown coordinate solver '%s'\n", solver); | 24 | LOG("[cehckdata] Unknown coordinate solver '%s'\n", solver); |
| 25 | return NISSY_ERROR_DATA; | 25 | return NISSY_ERROR_DATA; |
diff --git a/src/solvers/coord/dr.h b/src/solvers/coord/dr.h index 487e79c..03473df 100644 --- a/src/solvers/coord/dr.h +++ b/src/solvers/coord/dr.h | |||
| @@ -22,11 +22,6 @@ STATIC coord_t coordinate_dr = { | |||
| 22 | .trans_mask = TM_UDFIX, | 22 | .trans_mask = TM_UDFIX, |
| 23 | .moves_mask_gendata = MM18_ALLMOVES, | 23 | .moves_mask_gendata = MM18_ALLMOVES, |
| 24 | .moves_mask_solve = MM18_ALLMOVES, | 24 | .moves_mask_solve = MM18_ALLMOVES, |
| 25 | .axistrans = { | ||
| 26 | [AXIS_UD] = TRANS_UFr, | ||
| 27 | [AXIS_RL] = TRANS_RFr, | ||
| 28 | [AXIS_FB] = TRANS_FDr, | ||
| 29 | }, | ||
| 30 | .is_admissible = &solution_lastqt_cw, | 25 | .is_admissible = &solution_lastqt_cw, |
| 31 | .is_solvable = &is_eoco_solvable, | 26 | .is_solvable = &is_eoco_solvable, |
| 32 | .is_solved = NULL, | 27 | .is_solved = NULL, |
diff --git a/src/solvers/coord/dreo.h b/src/solvers/coord/dreo.h index 8780807..f563129 100644 --- a/src/solvers/coord/dreo.h +++ b/src/solvers/coord/dreo.h | |||
| @@ -21,11 +21,6 @@ STATIC coord_t coordinate_dreo = { | |||
| 21 | .trans_mask = TM_UDRLFIX, | 21 | .trans_mask = TM_UDRLFIX, |
| 22 | .moves_mask_gendata = MM18_EO, | 22 | .moves_mask_gendata = MM18_EO, |
| 23 | .moves_mask_solve = MM18_EO, | 23 | .moves_mask_solve = MM18_EO, |
| 24 | .axistrans = { | ||
| 25 | [AXIS_UD] = TRANS_UFr, | ||
| 26 | [AXIS_RL] = TRANS_RFr, | ||
| 27 | [AXIS_FB] = TRANS_FDr, | ||
| 28 | }, | ||
| 29 | .is_admissible = &solution_lastqt_cw, | 24 | .is_admissible = &solution_lastqt_cw, |
| 30 | .is_solvable = &is_dreo_solvable, | 25 | .is_solvable = &is_dreo_solvable, |
| 31 | .is_solved = NULL, | 26 | .is_solved = NULL, |
diff --git a/src/solvers/coord/drfinnoe.h b/src/solvers/coord/drfinnoe.h index c088ac4..4370779 100644 --- a/src/solvers/coord/drfinnoe.h +++ b/src/solvers/coord/drfinnoe.h | |||
| @@ -31,11 +31,6 @@ STATIC coord_t coordinate_drfinnoe = { | |||
| 31 | .trans_mask = TM_UDFIX, | 31 | .trans_mask = TM_UDFIX, |
| 32 | .moves_mask_gendata = MM18_DR, | 32 | .moves_mask_gendata = MM18_DR, |
| 33 | .moves_mask_solve = MM18_DR, | 33 | .moves_mask_solve = MM18_DR, |
| 34 | .axistrans = { | ||
| 35 | [AXIS_UD] = TRANS_UFr, | ||
| 36 | [AXIS_RL] = TRANS_RFr, | ||
| 37 | [AXIS_FB] = TRANS_FDr, | ||
| 38 | }, | ||
| 39 | .is_admissible = &solution_always_valid, | 34 | .is_admissible = &solution_always_valid, |
| 40 | .is_solvable = &is_drfinnoe_solvable, | 35 | .is_solvable = &is_drfinnoe_solvable, |
| 41 | .is_solved = NULL, | 36 | .is_solved = NULL, |
diff --git a/src/solvers/coord/drslice.h b/src/solvers/coord/drslice.h index 01bc346..c9403f8 100644 --- a/src/solvers/coord/drslice.h +++ b/src/solvers/coord/drslice.h | |||
| @@ -23,11 +23,6 @@ STATIC coord_t coordinate_drslice = { | |||
| 23 | .trans_mask = TM_UDFIX, | 23 | .trans_mask = TM_UDFIX, |
| 24 | .moves_mask_gendata = MM18_DR, | 24 | .moves_mask_gendata = MM18_DR, |
| 25 | .moves_mask_solve = MM18_DR_NOD, | 25 | .moves_mask_solve = MM18_DR_NOD, |
| 26 | .axistrans = { | ||
| 27 | [AXIS_UD] = TRANS_UFr, | ||
| 28 | [AXIS_RL] = TRANS_LFr, | ||
| 29 | [AXIS_FB] = TRANS_FUr, | ||
| 30 | }, | ||
| 31 | .is_admissible = &solution_always_valid, | 26 | .is_admissible = &solution_always_valid, |
| 32 | .is_solvable = &is_drslice_solvable, | 27 | .is_solvable = &is_drslice_solvable, |
| 33 | .is_solved = &is_drslice_solved, | 28 | .is_solved = &is_drslice_solved, |
diff --git a/src/solvers/coord/eo.h b/src/solvers/coord/eo.h index 86e09e9..2d45a4f 100644 --- a/src/solvers/coord/eo.h +++ b/src/solvers/coord/eo.h | |||
| @@ -14,11 +14,6 @@ STATIC coord_t coordinate_eo = { | |||
| 14 | .trans_mask = TM_SINGLE(TRANS_UFr), | 14 | .trans_mask = TM_SINGLE(TRANS_UFr), |
| 15 | .moves_mask_gendata = MM18_ALLMOVES, | 15 | .moves_mask_gendata = MM18_ALLMOVES, |
| 16 | .moves_mask_solve = MM18_ALLMOVES, | 16 | .moves_mask_solve = MM18_ALLMOVES, |
| 17 | .axistrans = { | ||
| 18 | [AXIS_UD] = TRANS_FDr, | ||
| 19 | [AXIS_RL] = TRANS_URr, | ||
| 20 | [AXIS_FB] = TRANS_UFr, | ||
| 21 | }, | ||
| 22 | .is_admissible = &solution_lastqt_cw, | 17 | .is_admissible = &solution_lastqt_cw, |
| 23 | .is_solvable = &is_eo_even, | 18 | .is_solvable = &is_eo_even, |
| 24 | .is_solved = NULL, | 19 | .is_solved = NULL, |
diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h index 75c57e4..0b108cd 100644 --- a/src/solvers/coord/gendata.h +++ b/src/solvers/coord/gendata.h | |||
| @@ -24,7 +24,7 @@ gendata_coord_dispatch( | |||
| 24 | { | 24 | { |
| 25 | coord_t *coord; | 25 | coord_t *coord; |
| 26 | 26 | ||
| 27 | parse_coord_and_axis(coordstr, &coord, NULL); | 27 | parse_coord_and_trans(coordstr, &coord, NULL); |
| 28 | 28 | ||
| 29 | if (coord == NULL) { | 29 | if (coord == NULL) { |
| 30 | LOG("Error: could not parse coordinate '%s'\n", coordstr); | 30 | LOG("Error: could not parse coordinate '%s'\n", coordstr); |
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index b372257..036c4bf 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -240,7 +240,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | |||
| 240 | STATIC long long | 240 | STATIC long long |
| 241 | solve_coord_dispatch( | 241 | solve_coord_dispatch( |
| 242 | oriented_cube_t oc, | 242 | oriented_cube_t oc, |
| 243 | const char *coord_and_axis, | 243 | const char *coord_and_trans, |
| 244 | unsigned nissflag, | 244 | unsigned nissflag, |
| 245 | unsigned minmoves, | 245 | unsigned minmoves, |
| 246 | unsigned maxmoves, | 246 | unsigned maxmoves, |
| @@ -257,22 +257,23 @@ solve_coord_dispatch( | |||
| 257 | ) | 257 | ) |
| 258 | { | 258 | { |
| 259 | coord_t *coord; | 259 | coord_t *coord; |
| 260 | uint8_t axis; | 260 | uint8_t trans; |
| 261 | 261 | ||
| 262 | parse_coord_and_axis(coord_and_axis, &coord, &axis); | 262 | parse_coord_and_trans(coord_and_trans, &coord, &trans); |
| 263 | 263 | ||
| 264 | if (coord == NULL) { | 264 | if (coord == NULL) { |
| 265 | LOG("Error: could not parse coordinate from '%s'\n", | 265 | LOG("Error: could not parse coordinate from '%s'\n", |
| 266 | coord_and_axis); | 266 | coord_and_trans); |
| 267 | return NISSY_ERROR_INVALID_SOLVER; | 267 | return NISSY_ERROR_INVALID_SOLVER; |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | if (axis == UINT8_ERROR) { | 270 | if (trans == UINT8_ERROR) { |
| 271 | LOG("Error: could not parse axis from '%s'\n", coord_and_axis); | 271 | LOG("Error: could not parse transformation from '%s'\n", |
| 272 | coord_and_trans); | ||
| 272 | return NISSY_ERROR_INVALID_SOLVER; | 273 | return NISSY_ERROR_INVALID_SOLVER; |
| 273 | } | 274 | } |
| 274 | 275 | ||
| 275 | return solve_coord(oc, coord, axis, nissflag, minmoves, maxmoves, | 276 | return solve_coord(oc, coord, trans, nissflag, minmoves, maxmoves, |
| 276 | maxsolutions, optimal, threads, data_size, data, | 277 | maxsolutions, optimal, threads, data_size, data, |
| 277 | solutions_size, sols, poll_status, poll_status_data); | 278 | solutions_size, sols, poll_status, poll_status_data); |
| 278 | } | 279 | } |
| @@ -281,7 +282,7 @@ STATIC int64_t | |||
| 281 | solve_coord( | 282 | solve_coord( |
| 282 | oriented_cube_t oc, | 283 | oriented_cube_t oc, |
| 283 | coord_t coord [static 1], | 284 | coord_t coord [static 1], |
| 284 | uint8_t axis, | 285 | uint8_t trans, |
| 285 | uint8_t nissflag, | 286 | uint8_t nissflag, |
| 286 | uint8_t minmoves, | 287 | uint8_t minmoves, |
| 287 | uint8_t maxmoves, | 288 | uint8_t maxmoves, |
| @@ -297,7 +298,6 @@ solve_coord( | |||
| 297 | ) | 298 | ) |
| 298 | { | 299 | { |
| 299 | int8_t d; | 300 | int8_t d; |
| 300 | uint8_t t; | ||
| 301 | uint64_t i; | 301 | uint64_t i; |
| 302 | int64_t err; | 302 | int64_t err; |
| 303 | cube_t c; | 303 | cube_t c; |
| @@ -309,8 +309,7 @@ solve_coord( | |||
| 309 | solution_settings_t solution_settings; | 309 | solution_settings_t solution_settings; |
| 310 | solution_list_t solution_list; | 310 | solution_list_t solution_list; |
| 311 | 311 | ||
| 312 | t = coord->axistrans[axis]; | 312 | c = transform(oc.cube, trans); |
| 313 | c = transform(oc.cube, t); | ||
| 314 | 313 | ||
| 315 | if (!coord->is_solvable(c)) | 314 | if (!coord->is_solvable(c)) |
| 316 | goto solve_coord_error_unsolvable; | 315 | goto solve_coord_error_unsolvable; |
| @@ -334,7 +333,7 @@ solve_coord( | |||
| 334 | solution_moves_reset(&solution_moves); | 333 | solution_moves_reset(&solution_moves); |
| 335 | 334 | ||
| 336 | solution_settings = (solution_settings_t) { | 335 | solution_settings = (solution_settings_t) { |
| 337 | .tmask = TM_SINGLE(inverse_trans(t)), | 336 | .tmask = TM_SINGLE(inverse_trans(trans)), |
| 338 | .unniss = false, | 337 | .unniss = false, |
| 339 | .maxmoves = maxmoves, | 338 | .maxmoves = maxmoves, |
| 340 | .maxsolutions = maxsolutions, | 339 | .maxsolutions = maxsolutions, |
diff --git a/src/solvers/coord/types_macros.h b/src/solvers/coord/types_macros.h index 2acf146..f36ecaf 100644 --- a/src/solvers/coord/types_macros.h +++ b/src/solvers/coord/types_macros.h | |||
| @@ -25,7 +25,6 @@ typedef struct { | |||
| 25 | uint64_t moves_mask_gendata; | 25 | uint64_t moves_mask_gendata; |
| 26 | uint64_t moves_mask_solve; | 26 | uint64_t moves_mask_solve; |
| 27 | uint64_t trans_mask; | 27 | uint64_t trans_mask; |
| 28 | uint8_t axistrans[3]; | ||
| 29 | bool (*is_admissible)(const solution_moves_t[static 1]); | 28 | bool (*is_admissible)(const solution_moves_t[static 1]); |
| 30 | bool (*is_solvable)(cube_t); | 29 | bool (*is_solvable)(cube_t); |
| 31 | bool (*is_solved)(uint64_t, const unsigned char *); | 30 | bool (*is_solved)(uint64_t, const unsigned char *); |
diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h index 5b8f538..93704cc 100644 --- a/src/solvers/coord/utils.h +++ b/src/solvers/coord/utils.h | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | STATIC coord_t *parse_coord(size_t, const char *); | 1 | STATIC coord_t *parse_coord(size_t, const char *); |
| 2 | STATIC uint8_t parse_axis(const char [static 2]); | 2 | STATIC void parse_coord_and_trans(const char *, coord_t **, uint8_t *); |
| 3 | STATIC void parse_coord_and_axis(const char *, coord_t **, uint8_t *); | ||
| 4 | STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); | 3 | STATIC long long dataid_coord(const char *, char [static NISSY_SIZE_DATAID]); |
| 5 | 4 | ||
| 6 | STATIC coord_t * | 5 | STATIC coord_t * |
| @@ -8,6 +7,10 @@ parse_coord(size_t n, const char *coord) | |||
| 8 | { | 7 | { |
| 9 | int i; | 8 | int i; |
| 10 | 9 | ||
| 10 | /* | ||
| 11 | TODO Some coordinates are parsed incorrectly, e.g. DRFINNOE | ||
| 12 | TODO is matched by DRFIN. Check that strncmp is used correctly. | ||
| 13 | */ | ||
| 11 | for (i = 0; all_coordinates[i] != NULL; i++) | 14 | for (i = 0; all_coordinates[i] != NULL; i++) |
| 12 | if (!strncmp(all_coordinates[i]->name, coord, n)) | 15 | if (!strncmp(all_coordinates[i]->name, coord, n)) |
| 13 | return all_coordinates[i]; | 16 | return all_coordinates[i]; |
| @@ -15,25 +18,11 @@ parse_coord(size_t n, const char *coord) | |||
| 15 | return NULL; | 18 | return NULL; |
| 16 | } | 19 | } |
| 17 | 20 | ||
| 18 | STATIC uint8_t | ||
| 19 | parse_axis(const char axis[static 2]) | ||
| 20 | { | ||
| 21 | if (!strcmp(axis, "UD") || !strcmp(axis, "DU")) { | ||
| 22 | return AXIS_UD; | ||
| 23 | } else if (!strcmp(axis, "RL") || !strcmp(axis, "LR")) { | ||
| 24 | return AXIS_RL; | ||
| 25 | } else if (!strcmp(axis, "FB") || !strcmp(axis, "BF")) { | ||
| 26 | return AXIS_FB; | ||
| 27 | } | ||
| 28 | |||
| 29 | return UINT8_ERROR; | ||
| 30 | } | ||
| 31 | |||
| 32 | STATIC void | 21 | STATIC void |
| 33 | parse_coord_and_axis( | 22 | parse_coord_and_trans( |
| 34 | const char *str, | 23 | const char *str, |
| 35 | coord_t **coord, | 24 | coord_t **coord, |
| 36 | uint8_t *axis | 25 | uint8_t *trans |
| 37 | ) | 26 | ) |
| 38 | { | 27 | { |
| 39 | size_t i; | 28 | size_t i; |
| @@ -45,8 +34,9 @@ parse_coord_and_axis( | |||
| 45 | if (coord != NULL) | 34 | if (coord != NULL) |
| 46 | *coord = parse_coord(i-6, str+6); | 35 | *coord = parse_coord(i-6, str+6); |
| 47 | 36 | ||
| 48 | if (axis != NULL) | 37 | if (trans != NULL) |
| 49 | *axis = i == strlen(str) ? UINT8_ERROR : parse_axis(str+i+1); | 38 | *trans = i == strlen(str) ? |
| 39 | UINT8_ERROR : readrotation(str+i+1); | ||
| 50 | } | 40 | } |
| 51 | 41 | ||
| 52 | STATIC long long | 42 | STATIC long long |
| @@ -54,7 +44,7 @@ dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) | |||
| 54 | { | 44 | { |
| 55 | coord_t *c; | 45 | coord_t *c; |
| 56 | 46 | ||
| 57 | parse_coord_and_axis(ca, &c, NULL); | 47 | parse_coord_and_trans(ca, &c, NULL); |
| 58 | 48 | ||
| 59 | if (c == NULL) { | 49 | if (c == NULL) { |
| 60 | LOG("Error: cannot parse coordinate from '%s'\n", ca); | 50 | LOG("Error: cannot parse coordinate from '%s'\n", ca); |
