aboutsummaryrefslogtreecommitdiff
path: root/src/nissy.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-29 10:08:04 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-29 10:08:04 +0200
commit8d3fc9f5f9c0593fcae9c451efe6c89c64dcbe84 (patch)
tree8c0182f9bf94aaa8afe5126988e07af82c4409fd /src/nissy.c
parentcdf46d85efe7fa54e8c302a255214341c567b4af (diff)
downloadnissy-core-8d3fc9f5f9c0593fcae9c451efe6c89c64dcbe84.tar.gz
nissy-core-8d3fc9f5f9c0593fcae9c451efe6c89c64dcbe84.zip
Added stop / pause / resume solve to API
Diffstat (limited to 'src/nissy.c')
-rw-r--r--src/nissy.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/nissy.c b/src/nissy.c
index 2dd5a41..acf6ebe 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -460,7 +460,9 @@ nissy_solve(
460 const unsigned char data[data_size], 460 const unsigned char data[data_size],
461 unsigned sols_size, 461 unsigned sols_size,
462 char sols[sols_size], 462 char sols[sols_size],
463 long long stats[static NISSY_SIZE_SOLVE_STATS] 463 long long stats[static NISSY_SIZE_SOLVE_STATS],
464 int (*poll_status)(void *),
465 void *poll_status_data
464) 466)
465{ 467{
466 oriented_cube_t oc; 468 oriented_cube_t oc;
@@ -475,14 +477,23 @@ nissy_solve(
475 477
476 oc = readcube(cube); 478 oc = readcube(cube);
477 479
478/* TODO: solve should handle oriented cubes */
479
480 if (!isconsistent(oc)) { 480 if (!isconsistent(oc)) {
481 LOG("[solve] Error: cube is invalid\n"); 481 LOG("[solve] Error: cube is invalid\n");
482 return NISSY_ERROR_INVALID_CUBE; 482 return NISSY_ERROR_INVALID_CUBE;
483 } 483 }
484 484
485/* TODO: checks for minmoves, maxmoves, nissflag */ 485 if (maxmoves > 20) {
486 LOG("[solve] 'maxmoves' larger than 20 not supported yet, "
487 "setting it to 20\n");
488 maxmoves = 20;
489 }
490
491 if (minmoves > maxmoves) {
492 LOG("[solve] value provided for 'minmoves' (%u) is larger "
493 "than that provided for 'maxmoves' (%u), setting "
494 "'minmoves' to %u\n", minmoves, maxmoves, maxmoves);
495 minmoves = maxmoves;
496 }
486 497
487 if (maxsols == 0) { 498 if (maxsols == 0) {
488 LOG("[solve] 'maxsols' is 0, returning no solution\n"); 499 LOG("[solve] 'maxsols' is 0, returning no solution\n");
@@ -505,11 +516,12 @@ nissy_solve(
505 if (parse_ret != NISSY_OK) 516 if (parse_ret != NISSY_OK)
506 return parse_ret; 517 return parse_ret;
507 return solve_h48(oc, minmoves, maxmoves, maxsols, 518 return solve_h48(oc, minmoves, maxmoves, maxsols,
508 optimal, t, data_size, data, sols_size, sols, stats); 519 optimal, t, data_size, data, sols_size, sols, stats,
520 poll_status, poll_status_data);
509 } else if (!strncmp(solver, "coord_", 6)) { 521 } else if (!strncmp(solver, "coord_", 6)) {
510 return solve_coord_dispatch(oc, solver + 6, nissflag, 522 return solve_coord_dispatch(oc, solver + 6, nissflag,
511 minmoves, maxmoves, maxsols, optimal, t, data_size, data, 523 minmoves, maxmoves, maxsols, optimal, t, data_size, data,
512 sols_size, sols); 524 sols_size, sols, poll_status, poll_status_data);
513 } else { 525 } else {
514 LOG("[solve] Error: unknown solver '%s'\n", solver); 526 LOG("[solve] Error: unknown solver '%s'\n", solver);
515 return NISSY_ERROR_INVALID_SOLVER; 527 return NISSY_ERROR_INVALID_SOLVER;

Generated with cgit - Back to sebastiano.tronto.net