diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/constants.h | 8 | ||||
| -rw-r--r-- | src/core/moves.h | 7 | ||||
| -rw-r--r-- | src/nissy.c | 12 | ||||
| -rw-r--r-- | src/nissy.h | 5 | ||||
| -rw-r--r-- | src/solvers/coord/solve.h | 17 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 15 | ||||
| -rw-r--r-- | src/solvers/solutions.h | 18 | ||||
| -rw-r--r-- | src/solvers/solutions_types_macros.h | 1 |
8 files changed, 51 insertions, 32 deletions
diff --git a/src/core/constants.h b/src/core/constants.h index 6505689..2908f28 100644 --- a/src/core/constants.h +++ b/src/core/constants.h | |||
| @@ -696,17 +696,17 @@ STATIC uint8_t orientation_transition_table[][3] = { | |||
| 696 | [ORIENTATION_RB] = { ORIENTATION_BL, ORIENTATION_RU, ORIENTATION_DB }, | 696 | [ORIENTATION_RB] = { ORIENTATION_BL, ORIENTATION_RU, ORIENTATION_DB }, |
| 697 | [ORIENTATION_RU] = { ORIENTATION_UL, ORIENTATION_RF, ORIENTATION_BU }, | 697 | [ORIENTATION_RU] = { ORIENTATION_UL, ORIENTATION_RF, ORIENTATION_BU }, |
| 698 | [ORIENTATION_LF] = { ORIENTATION_FR, ORIENTATION_LU, ORIENTATION_DF }, | 698 | [ORIENTATION_LF] = { ORIENTATION_FR, ORIENTATION_LU, ORIENTATION_DF }, |
| 699 | [ORIENTATION_LD] = { ORIENTATION_DR, ORIENTATION_LB, ORIENTATION_BD }, | 699 | [ORIENTATION_LD] = { ORIENTATION_DR, ORIENTATION_LF, ORIENTATION_BD }, |
| 700 | [ORIENTATION_LB] = { ORIENTATION_BR, ORIENTATION_LD, ORIENTATION_UB }, | 700 | [ORIENTATION_LB] = { ORIENTATION_BR, ORIENTATION_LD, ORIENTATION_UB }, |
| 701 | [ORIENTATION_LU] = { ORIENTATION_UR, ORIENTATION_LF, ORIENTATION_FU }, | 701 | [ORIENTATION_LU] = { ORIENTATION_UR, ORIENTATION_LB, ORIENTATION_FU }, |
| 702 | [ORIENTATION_FD] = { ORIENTATION_DB, ORIENTATION_FR, ORIENTATION_LD }, | 702 | [ORIENTATION_FD] = { ORIENTATION_DB, ORIENTATION_FR, ORIENTATION_LD }, |
| 703 | [ORIENTATION_FR] = { ORIENTATION_RB, ORIENTATION_FU, ORIENTATION_DR }, | 703 | [ORIENTATION_FR] = { ORIENTATION_RB, ORIENTATION_FU, ORIENTATION_DR }, |
| 704 | [ORIENTATION_FU] = { ORIENTATION_UB, ORIENTATION_FL, ORIENTATION_RU }, | 704 | [ORIENTATION_FU] = { ORIENTATION_UB, ORIENTATION_FL, ORIENTATION_RU }, |
| 705 | [ORIENTATION_FL] = { ORIENTATION_LB, ORIENTATION_FD, ORIENTATION_UL }, | 705 | [ORIENTATION_FL] = { ORIENTATION_LB, ORIENTATION_FD, ORIENTATION_UL }, |
| 706 | [ORIENTATION_BD] = { ORIENTATION_DF, ORIENTATION_BL, ORIENTATION_RD }, | 706 | [ORIENTATION_BD] = { ORIENTATION_DF, ORIENTATION_BL, ORIENTATION_RD }, |
| 707 | [ORIENTATION_BR] = { ORIENTATION_RF, ORIENTATION_BU, ORIENTATION_UR }, | 707 | [ORIENTATION_BR] = { ORIENTATION_RF, ORIENTATION_BD, ORIENTATION_UR }, |
| 708 | [ORIENTATION_BU] = { ORIENTATION_UF, ORIENTATION_BR, ORIENTATION_LU }, | 708 | [ORIENTATION_BU] = { ORIENTATION_UF, ORIENTATION_BR, ORIENTATION_LU }, |
| 709 | [ORIENTATION_BL] = { ORIENTATION_LF, ORIENTATION_BD, ORIENTATION_DL }, | 709 | [ORIENTATION_BL] = { ORIENTATION_LF, ORIENTATION_BU, ORIENTATION_DL }, |
| 710 | }; | 710 | }; |
| 711 | 711 | ||
| 712 | STATIC uint8_t orientation_trans[] = { | 712 | STATIC uint8_t orientation_trans[] = { |
diff --git a/src/core/moves.h b/src/core/moves.h index 20544a3..0d97172 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -16,6 +16,7 @@ STATIC_INLINE bool isbase(uint8_t); | |||
| 16 | STATIC_INLINE bool parallel(uint8_t, uint8_t); | 16 | STATIC_INLINE bool parallel(uint8_t, uint8_t); |
| 17 | STATIC_INLINE uint8_t moveopposite(uint8_t); | 17 | STATIC_INLINE uint8_t moveopposite(uint8_t); |
| 18 | STATIC_INLINE uint8_t reorient_move(uint8_t, uint8_t); | 18 | STATIC_INLINE uint8_t reorient_move(uint8_t, uint8_t); |
| 19 | STATIC_INLINE uint8_t inverse_reorient_move(uint8_t, uint8_t); | ||
| 19 | STATIC_INLINE uint8_t movefollow(uint8_t); | 20 | STATIC_INLINE uint8_t movefollow(uint8_t); |
| 20 | STATIC uint8_t transform_move(uint8_t, uint8_t); | 21 | STATIC uint8_t transform_move(uint8_t, uint8_t); |
| 21 | 22 | ||
| @@ -223,6 +224,12 @@ reorient_move(uint8_t m, uint8_t or) | |||
| 223 | return transform_move(m, orientation_trans[or]); | 224 | return transform_move(m, orientation_trans[or]); |
| 224 | } | 225 | } |
| 225 | 226 | ||
| 227 | STATIC_INLINE uint8_t | ||
| 228 | inverse_reorient_move(uint8_t m, uint8_t or) | ||
| 229 | { | ||
| 230 | return transform_move(m, inverse_trans_table[orientation_trans[or]]); | ||
| 231 | } | ||
| 232 | |||
| 226 | /* This is currently unused, but it may turn out to be useful at some point */ | 233 | /* This is currently unused, but it may turn out to be useful at some point */ |
| 227 | STATIC_INLINE uint8_t | 234 | STATIC_INLINE uint8_t |
| 228 | movefollow(uint8_t move) | 235 | movefollow(uint8_t move) |
diff --git a/src/nissy.c b/src/nissy.c index 27f2b35..f1d4cd1 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -461,7 +461,6 @@ nissy_solve( | |||
| 461 | ) | 461 | ) |
| 462 | { | 462 | { |
| 463 | oriented_cube_t oc; | 463 | oriented_cube_t oc; |
| 464 | cube_t c; | ||
| 465 | long long parse_ret; | 464 | long long parse_ret; |
| 466 | uint8_t h, k; | 465 | uint8_t h, k; |
| 467 | int t; | 466 | int t; |
| @@ -472,7 +471,6 @@ nissy_solve( | |||
| 472 | } | 471 | } |
| 473 | 472 | ||
| 474 | oc = readcube(cube); | 473 | oc = readcube(cube); |
| 475 | c = oc.cube; | ||
| 476 | 474 | ||
| 477 | /* TODO: solve should handle oriented cubes */ | 475 | /* TODO: solve should handle oriented cubes */ |
| 478 | 476 | ||
| @@ -481,12 +479,6 @@ nissy_solve( | |||
| 481 | return NISSY_ERROR_INVALID_CUBE; | 479 | return NISSY_ERROR_INVALID_CUBE; |
| 482 | } | 480 | } |
| 483 | 481 | ||
| 484 | if (!issolvable((oriented_cube_t){ .cube = c, .orientation = 0})) { | ||
| 485 | /* TODO: this is step-dependent */ | ||
| 486 | LOG("[solve] Error: cube is not solvable\n"); | ||
| 487 | return NISSY_ERROR_UNSOLVABLE_CUBE; | ||
| 488 | } | ||
| 489 | |||
| 490 | /* TODO: checks for minmoves, maxmoves, nissflag */ | 482 | /* TODO: checks for minmoves, maxmoves, nissflag */ |
| 491 | 483 | ||
| 492 | if (maxsols == 0) { | 484 | if (maxsols == 0) { |
| @@ -509,10 +501,10 @@ nissy_solve( | |||
| 509 | parse_ret = parse_h48_solver(solver, &h, &k); | 501 | parse_ret = parse_h48_solver(solver, &h, &k); |
| 510 | if (parse_ret != NISSY_OK) | 502 | if (parse_ret != NISSY_OK) |
| 511 | return parse_ret; | 503 | return parse_ret; |
| 512 | return solve_h48(c, minmoves, maxmoves, maxsols, | 504 | return solve_h48(oc, minmoves, maxmoves, maxsols, |
| 513 | optimal, t, data_size, data, sols_size, sols, stats); | 505 | optimal, t, data_size, data, sols_size, sols, stats); |
| 514 | } else if (!strncmp(solver, "coord_", 6)) { | 506 | } else if (!strncmp(solver, "coord_", 6)) { |
| 515 | return solve_coord_dispatch(c, solver + 6, nissflag, | 507 | return solve_coord_dispatch(oc, solver + 6, nissflag, |
| 516 | minmoves, maxmoves, maxsols, optimal, t, data_size, data, | 508 | minmoves, maxmoves, maxsols, optimal, t, data_size, data, |
| 517 | sols_size, sols); | 509 | sols_size, sols); |
| 518 | } else { | 510 | } else { |
diff --git a/src/nissy.h b/src/nissy.h index e7ae50e..734487d 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -8,8 +8,9 @@ below for the list of error codes and their meaning. | |||
| 8 | Cubes are passed as strings in the cccccccc=eeeeeeeeeeee=r format, | 8 | Cubes are passed as strings in the cccccccc=eeeeeeeeeeee=r format, |
| 9 | see the README.md file for more information. | 9 | see the README.md file for more information. |
| 10 | 10 | ||
| 11 | Accepted moves are U, D, R, L, F and B, optionally followed by a 2, | 11 | Accepted moves are any of the following: |
| 12 | a ' or a 3. | 12 | U, D, R, L, F, B, Uw, Dw, Rw, Lw, Fw, Bw, M, S, E, x, y, z |
| 13 | optionally followed by a 2, a ' or a 3. | ||
| 13 | 14 | ||
| 14 | A transformation must be given in the format | 15 | A transformation must be given in the format |
| 15 | (rotation|mirrored) (2 letters) | 16 | (rotation|mirrored) (2 letters) |
diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h index fb996ac..48cc704 100644 --- a/src/solvers/coord/solve.h +++ b/src/solvers/coord/solve.h | |||
| @@ -12,12 +12,12 @@ typedef struct { | |||
| 12 | const unsigned char *ptable; | 12 | const unsigned char *ptable; |
| 13 | } dfsarg_solve_coord_t; | 13 | } dfsarg_solve_coord_t; |
| 14 | 14 | ||
| 15 | STATIC int64_t solve_coord(cube_t, coord_t [static 1], uint8_t, uint8_t, | 15 | STATIC int64_t solve_coord(oriented_cube_t, coord_t [static 1], uint8_t, |
| 16 | uint8_t, uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, | ||
| 17 | const unsigned char *, size_t n, char [n]); | ||
| 18 | STATIC int64_t solve_coord_dispatch(oriented_cube_t, const char *, uint8_t, | ||
| 16 | uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, | 19 | uint8_t, uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, |
| 17 | const unsigned char *, size_t n, char [n]); | 20 | const unsigned char *, size_t n, char [n]); |
| 18 | STATIC int64_t solve_coord_dispatch(cube_t, const char *, uint8_t, uint8_t, | ||
| 19 | uint8_t, uint64_t, uint8_t, uint8_t, uint64_t, const unsigned char *, | ||
| 20 | size_t n, char [n]); | ||
| 21 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); | 21 | STATIC bool coord_solution_admissible(const dfsarg_solve_coord_t [static 1]); |
| 22 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); | 22 | STATIC bool solve_coord_dfs_stop(const dfsarg_solve_coord_t [static 1]); |
| 23 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); | 23 | STATIC bool coord_continue_onnormal(const dfsarg_solve_coord_t [static 1]); |
| @@ -200,7 +200,7 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) | |||
| 200 | 200 | ||
| 201 | STATIC int64_t | 201 | STATIC int64_t |
| 202 | solve_coord_dispatch( | 202 | solve_coord_dispatch( |
| 203 | cube_t cube, | 203 | oriented_cube_t oc, |
| 204 | const char *coord_and_axis, | 204 | const char *coord_and_axis, |
| 205 | uint8_t nissflag, | 205 | uint8_t nissflag, |
| 206 | uint8_t minmoves, | 206 | uint8_t minmoves, |
| @@ -231,14 +231,14 @@ solve_coord_dispatch( | |||
| 231 | return NISSY_ERROR_INVALID_SOLVER; | 231 | return NISSY_ERROR_INVALID_SOLVER; |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | return solve_coord(cube, coord, axis, nissflag, minmoves, maxmoves, | 234 | return solve_coord(oc, coord, axis, nissflag, minmoves, maxmoves, |
| 235 | maxsolutions, optimal, threads, data_size, data, | 235 | maxsolutions, optimal, threads, data_size, data, |
| 236 | solutions_size, sols); | 236 | solutions_size, sols); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | STATIC int64_t | 239 | STATIC int64_t |
| 240 | solve_coord( | 240 | solve_coord( |
| 241 | cube_t cube, | 241 | oriented_cube_t oc, |
| 242 | coord_t coord [static 1], | 242 | coord_t coord [static 1], |
| 243 | uint8_t axis, | 243 | uint8_t axis, |
| 244 | uint8_t nissflag, | 244 | uint8_t nissflag, |
| @@ -266,7 +266,7 @@ solve_coord( | |||
| 266 | solution_list_t solution_list; | 266 | solution_list_t solution_list; |
| 267 | 267 | ||
| 268 | t = coord->axistrans[axis]; | 268 | t = coord->axistrans[axis]; |
| 269 | c = transform(cube, t); | 269 | c = transform(oc.cube, t); |
| 270 | 270 | ||
| 271 | if (!coord->is_solvable(c)) | 271 | if (!coord->is_solvable(c)) |
| 272 | goto solve_coord_error_unsolvable; | 272 | goto solve_coord_error_unsolvable; |
| @@ -295,6 +295,7 @@ solve_coord( | |||
| 295 | .maxmoves = maxmoves, | 295 | .maxmoves = maxmoves, |
| 296 | .maxsolutions = maxsolutions, | 296 | .maxsolutions = maxsolutions, |
| 297 | .optimal = optimal, | 297 | .optimal = optimal, |
| 298 | .orientation = oc.orientation, | ||
| 298 | }; | 299 | }; |
| 299 | 300 | ||
| 300 | arg = (dfsarg_solve_coord_t) { | 301 | arg = (dfsarg_solve_coord_t) { |
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index d19309b..86c590a 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -52,8 +52,8 @@ STATIC int64_t solve_h48_maketasks( | |||
| 52 | solve_h48_task_t [static STARTING_CUBES], int [static 1]); | 52 | solve_h48_task_t [static STARTING_CUBES], int [static 1]); |
| 53 | STATIC void *solve_h48_runthread(void *); | 53 | STATIC void *solve_h48_runthread(void *); |
| 54 | STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); | 54 | STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t [static 1]); |
| 55 | STATIC int64_t solve_h48(cube_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, | 55 | STATIC int64_t solve_h48(oriented_cube_t, uint8_t, uint8_t, uint8_t, uint8_t, |
| 56 | uint64_t, const unsigned char *, size_t n, char [n], | 56 | uint8_t, uint64_t, const unsigned char *, size_t n, char [n], |
| 57 | long long [static NISSY_SIZE_SOLVE_STATS]); | 57 | long long [static NISSY_SIZE_SOLVE_STATS]); |
| 58 | 58 | ||
| 59 | STATIC_INLINE bool | 59 | STATIC_INLINE bool |
| @@ -342,7 +342,7 @@ solve_h48_maketasks( | |||
| 342 | 342 | ||
| 343 | STATIC int64_t | 343 | STATIC int64_t |
| 344 | solve_h48( | 344 | solve_h48( |
| 345 | cube_t cube, | 345 | oriented_cube_t oc, |
| 346 | uint8_t minmoves, | 346 | uint8_t minmoves, |
| 347 | uint8_t maxmoves, | 347 | uint8_t maxmoves, |
| 348 | uint8_t maxsolutions, | 348 | uint8_t maxsolutions, |
| @@ -407,17 +407,18 @@ solve_h48( | |||
| 407 | fallback2 = h48data + offset; | 407 | fallback2 = h48data + offset; |
| 408 | 408 | ||
| 409 | settings = (solution_settings_t) { | 409 | settings = (solution_settings_t) { |
| 410 | .tmask = symmetry_mask(cube), | 410 | .tmask = symmetry_mask(oc.cube), |
| 411 | .unniss = true, | 411 | .unniss = true, |
| 412 | .maxmoves = maxmoves, | 412 | .maxmoves = maxmoves, |
| 413 | .maxsolutions = maxsolutions, | 413 | .maxsolutions = maxsolutions, |
| 414 | .optimal = optimal, | 414 | .optimal = optimal, |
| 415 | .orientation = oc.orientation, | ||
| 415 | }; | 416 | }; |
| 416 | 417 | ||
| 417 | for (i = 0; i < threads; i++) { | 418 | for (i = 0; i < threads; i++) { |
| 418 | arg[i] = (dfsarg_solve_h48_t) { | 419 | arg[i] = (dfsarg_solve_h48_t) { |
| 419 | .start_cube = cube, | 420 | .start_cube = oc.cube, |
| 420 | .cube = cube, | 421 | .cube = oc.cube, |
| 421 | .h = info.h48h, | 422 | .h = info.h48h, |
| 422 | .k = info.bits, | 423 | .k = info.bits, |
| 423 | .base = info.base, | 424 | .base = info.base, |
| @@ -441,7 +442,7 @@ solve_h48( | |||
| 441 | pthread_mutex_init(&solutions_mutex, NULL); | 442 | pthread_mutex_init(&solutions_mutex, NULL); |
| 442 | 443 | ||
| 443 | maketasks_arg = (dfsarg_solve_h48_maketasks_t) { | 444 | maketasks_arg = (dfsarg_solve_h48_maketasks_t) { |
| 444 | .cube = cube, | 445 | .cube = oc.cube, |
| 445 | .nmoves = 0, | 446 | .nmoves = 0, |
| 446 | .minmoves = minmoves, | 447 | .minmoves = minmoves, |
| 447 | .maxmoves = maxmoves, | 448 | .maxmoves = maxmoves, |
diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h index 2340a80..75d0804 100644 --- a/src/solvers/solutions.h +++ b/src/solvers/solutions.h | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | STATIC void solution_moves_reset(solution_moves_t [static 1]); | 1 | STATIC void solution_moves_reset(solution_moves_t [static 1]); |
| 2 | STATIC void solution_moves_transform(solution_moves_t [static 1], uint8_t t); | 2 | STATIC void solution_moves_transform(solution_moves_t [static 1], uint8_t); |
| 3 | STATIC void solution_moves_reorient(solution_moves_t [static 1], uint8_t); | ||
| 3 | STATIC bool solution_list_init( | 4 | STATIC bool solution_list_init( |
| 4 | solution_list_t [static 1], size_t n, char [n]); | 5 | solution_list_t [static 1], size_t n, char [n]); |
| 5 | STATIC bool solution_moves_equal( | 6 | STATIC bool solution_moves_equal( |
| @@ -35,6 +36,20 @@ solution_moves_transform(solution_moves_t moves[static 1], uint8_t t) | |||
| 35 | moves->premoves[i] = transform_move(moves->premoves[i], t); | 36 | moves->premoves[i] = transform_move(moves->premoves[i], t); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 39 | STATIC void | ||
| 40 | solution_moves_reorient(solution_moves_t moves[static 1], uint8_t or) | ||
| 41 | { | ||
| 42 | uint8_t i; | ||
| 43 | |||
| 44 | for (i = 0; i < moves->nmoves; i++) | ||
| 45 | moves->moves[i] = | ||
| 46 | inverse_reorient_move(moves->moves[i], or); | ||
| 47 | |||
| 48 | for (i = 0; i < moves->npremoves; i++) | ||
| 49 | moves->premoves[i] = | ||
| 50 | inverse_reorient_move(moves->premoves[i], or); | ||
| 51 | } | ||
| 52 | |||
| 38 | STATIC bool | 53 | STATIC bool |
| 39 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) | 54 | solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) |
| 40 | { | 55 | { |
| @@ -187,6 +202,7 @@ appendsolution( | |||
| 187 | continue; | 202 | continue; |
| 188 | } | 203 | } |
| 189 | solution_moves_transform(&tsol[r], t); | 204 | solution_moves_transform(&tsol[r], t); |
| 205 | solution_moves_reorient(&tsol[r], settings->orientation); | ||
| 190 | sortparallel_moves(tsol[r].nmoves, tsol[r].moves); | 206 | sortparallel_moves(tsol[r].nmoves, tsol[r].moves); |
| 191 | sortparallel_moves(tsol[r].npremoves, tsol[r].premoves); | 207 | sortparallel_moves(tsol[r].npremoves, tsol[r].premoves); |
| 192 | 208 | ||
diff --git a/src/solvers/solutions_types_macros.h b/src/solvers/solutions_types_macros.h index 9b1431f..f1cb517 100644 --- a/src/solvers/solutions_types_macros.h +++ b/src/solvers/solutions_types_macros.h | |||
| @@ -13,6 +13,7 @@ typedef struct { | |||
| 13 | uint8_t maxmoves; | 13 | uint8_t maxmoves; |
| 14 | uint64_t maxsolutions; | 14 | uint64_t maxsolutions; |
| 15 | uint8_t optimal; | 15 | uint8_t optimal; |
| 16 | uint8_t orientation; | ||
| 16 | } solution_settings_t; | 17 | } solution_settings_t; |
| 17 | 18 | ||
| 18 | typedef struct { | 19 | typedef struct { |
