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 238702e7dd860af59d22f33cbfe163f28c3beb4e
parent e1690a427040f710de5643643d7c6226c1b2364f
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sun, 25 May 2025 12:11:34 +0200

Cleanup

Diffstat:
M.gitignore | 3+--
MREADME.md | 7-------
Mcpp/examples/solve_h48h3k2.cpp | 5++---
Mcpp/nissy.cpp | 23+++++++++--------------
Mcpp/nissy.h | 3+--
Mweb/adapter.cpp | 16++++++----------
Dweb/examples/solve.mjs | 12------------
Mweb/storage.cpp | 46+++++++++++++++++++++++-----------------------
8 files changed, 42 insertions(+), 73 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -22,8 +22,7 @@ runcpp runtest.js runtest.wasm web/*.wasm -web/http/*.wasm -web/http/*.mjs +web/http/nissy_web_module.* web/nissy_web_module.* runtool tools/.DS_Store diff --git a/README.md b/README.md @@ -244,13 +244,6 @@ The JavaScript module can be built with $ ./build web ``` -Some examples can be found in the `web/examples` folder. They can be run -using [nodejs](https://nodejs.org): - -``` -$ node web/examples/[filename] -``` - An example web app running nissy can be found in the `web/http` folder. You can run a web server in that folder to check it out, but you need to set some extra headers to make it work. For example, if you are using diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp @@ -80,10 +80,9 @@ int main() { if (solve_result.solutions.size() == 0) { std::cout << "No solution found!" << std::endl; } else { - auto& sol = solve_result.solutions[0]; - auto len = nissy::count_moves(sol).value; + auto len = nissy::count_moves(solve_result.solutions).value; std::cout << "Solution (" << len << " moves): " - << sol << std::endl; + << solve_result.solutions << std::endl; } return 0; diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp @@ -56,6 +56,7 @@ namespace nissy { namespace size { constexpr size_t CUBE = 24; constexpr size_t TRANSFORMATION = 12; + constexpr size_t SOLVE_STATS = 10; constexpr size_t DATAID = 255; } @@ -163,34 +164,28 @@ namespace nissy { unsigned threads, int (*poll_status)(void *), void *poll_status_data) const { + long long stats[size::SOLVE_STATS]; solver::solve_result result; if (maxsols == 0) { - result.solutions = {}; + result.solutions = ""; result.err = error::OK; return result; } const size_t len = 3 * (maxmoves+1) * maxsols; - std::vector<char> csols(len); + result.solutions.resize(len); auto err = nissy_solve(cube.to_string().c_str(), name.c_str(), niss.value, minmoves, maxmoves, maxsols, optimal, threads, data.size(), reinterpret_cast<const unsigned char *>(data.data()), len, - csols.data(), result.stats.data(), poll_status, - poll_status_data); - result.err = error{err}; + result.solutions.data(), stats, + poll_status, poll_status_data); - if (err < 0) - return result; - - std::string_view strsols(csols.data()); - for (auto r : strsols | std::views::split('\n')) - if (r.begin() != r.end() || - r.begin() == strsols.begin()) - result.solutions.push_back( - std::string{r.begin(), r.end()}); + int size = result.solutions.find_first_of('\0') + 1; + result.solutions.resize(size); + result.err = error{err}; return result; } diff --git a/cpp/nissy.h b/cpp/nissy.h @@ -79,8 +79,7 @@ namespace nissy { public: struct solve_result { error err; - std::vector<std::string> solutions; - std::array<long long, 10> stats; + std::string solutions; }; const std::string name; diff --git a/web/adapter.cpp b/web/adapter.cpp @@ -108,17 +108,13 @@ bool solver_valid(const std::string& name) int poll_status(void *arg) { - return nissy::status::RUN.value; -/* -TODO: reintroduce poll status - int id = *(int *)arg; - if (id == -1) + if (arg == NULL || *(int *)arg == -1) return nissy::status::RUN.value; - return callFunctionInt(id); -*/ + + return callFunctionInt(*(int *)arg); } -#if 0 +#if 1 nissy::solver::solve_result solve(std::string name, nissy::cube cube, nissy::nissflag nissflag, unsigned minmoves, @@ -212,17 +208,17 @@ 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) ; -*/ emscripten::function("countMoves", &nissy::count_moves); emscripten::function("solve", &solve, diff --git a/web/examples/solve.mjs b/web/examples/solve.mjs @@ -1,12 +0,0 @@ -import Nissy from '../nissy_web_module.mjs' - -const nissy = await Nissy(); - -var log = process.stdout.write.bind(process.stdout); -//var log = console.log -nissy.setLogger(nissy._addCallbackFunction(log)) - -var cube = new nissy.Cube(); -cube.move('R\' U\' F'); - -nissy.solve('h48h0k4', cube, nissy.NissFlag.normal, 0, 8, 2, 99, 4, -1); diff --git a/web/storage.cpp b/web/storage.cpp @@ -13,29 +13,29 @@ std::string getprefix() { } EM_ASYNC_JS(int, loadfs, (), { - const dir = '/tables'; - const inBrowser = typeof window !== 'undefined'; - const inWorker = typeof WorkerGlobalScope !== 'undefined' && - self instanceof WorkerGlobalScope; - - if (!(inBrowser || inWorker)) return; - - if (!FS.analyzePath(dir).exists) - FS.mkdir(dir); - - if (FS.analyzePath(dir).object.mount.mountpoint != dir) { - FS.mount(IDBFS, { autoPersist: true }, dir); - - await new Promise((resolve, reject) => { - FS.syncfs(true, function (err) { - if (err) { - reject(err); - } else { - resolve(true); - } - }); - }); - } + const dir = '/tables'; + const inBrowser = typeof window !== 'undefined'; + const inWorker = typeof WorkerGlobalScope !== 'undefined' && + self instanceof WorkerGlobalScope; + + if (!(inBrowser || inWorker)) + return; + + if (!FS.analyzePath(dir).exists) + FS.mkdir(dir); + + if (FS.analyzePath(dir).object.mount.mountpoint != dir) { + FS.mount(IDBFS, { autoPersist: true }, dir); + + await new Promise((resolve, reject) => { + FS.syncfs(true, function (err) { + if (err) + reject(err); + else + resolve(true); + }); + }); + } }); bool storage::read(std::string key, size_t data_size, char *data)