nissy-core

The "engine" of nissy, including the H48 optimal solver.
git clone https://git.tronto.net/nissy-core
Download | Log | Files | Refs | README | LICENSE

commit 87852933851674cacbc8b2295d046831db27ab81
parent 2852d47c0e7b0da72259ddcec693270d52110578
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 25 May 2025 12:38:39 +0200

Cleanup

Diffstat:
Msrc/solvers/h48/solve.h | 3++-
Mweb/adapter.cpp | 38--------------------------------------
Mweb/http/worker.mjs | 8+++++++-
3 files changed, 9 insertions(+), 40 deletions(-)

diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -567,7 +567,8 @@ solve_h48( if (poll_status != NULL) { status = poll_status(poll_status_data); - if (status == NISSY_STATUS_PAUSE && fp) { + if (status == NISSY_STATUS_PAUSE && fp) + { LOG("[H48 solve] Paused\n"); fp = false; } diff --git a/web/adapter.cpp b/web/adapter.cpp @@ -114,8 +114,6 @@ int poll_status(void *arg) return callFunctionInt(*(int *)arg); } -#if 1 - nissy::solver::solve_result solve(std::string name, nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, @@ -137,35 +135,6 @@ nissy::solver::solve_result solve(std::string name, maxmoves, maxsols, optimal, threads, NULL, &poll_status_id); } -#else - -std::string solve(std::string name, - nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, - unsigned maxmoves, unsigned maxsols, unsigned optimal, unsigned threads, - int poll_status_id) -{ - // Here we use a dirty trick to make this function always return the - // same kind of JavaScript object. If we did not do this, the returned - // object would be a Promise on the first run of the solver for each - // session (because when loading the table some async JS code is - // called), and a regular object otherwise. - // TODO figure out if there is a better way to do this. - fake_async(); - - if (!solver_valid(name)) - return ""; -/* - return nissy::solver::solve_result - {.err = nissy::error::INVALID_SOLVER}; -*/ - - return loaded_solvers.at(name).solve(cube, nissflag, minmoves, - maxmoves, maxsols, optimal, threads, NULL, &poll_status_id) - .solutions[0]; -} - -#endif - EMSCRIPTEN_BINDINGS(Nissy) { emscripten::class_<nissy::nissflag>("NissFlag") @@ -208,13 +177,6 @@ EMSCRIPTEN_BINDINGS(Nissy) .function("toString", &nissy::cube::to_string) ; -/* - emscripten::register_vector<std::string>("StringVector"); - emscripten::value_array<nissy::solver::solve_result>("SolveResult") - .element(&nissy::solver::solve_result::err) - .element(&nissy::solver::solve_result::solutions) - ; -*/ emscripten::class_<nissy::solver::solve_result>("SolveResult") .property("err", &nissy::solver::solve_result::err) .property("solutions", &nissy::solver::solve_result::solutions) diff --git a/web/http/worker.mjs b/web/http/worker.mjs @@ -7,5 +7,11 @@ onmessage = (e) => { var cube = new nissy.Cube(); cube.move(e.data.scramble); nissy.solve(e.data.solver, cube, nissy.NissFlag.normal, 0, 17, 1, 99, 4, -1) - .then((sol) => postMessage(sol)) + .then((solve_result) => { + if (!solve_result.err.ok()) + posMessage("Error while solving (solve returned " + + solve_result.err.value + ")"); + else + postMessage(solve_result.solutions) + }); };