h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit ad1e483787cbc3aeb62c9afb9e31520df5a4b559
parent 6b3f40ac441fede250b9c381952fafd8aac28bd5
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Tue, 15 Apr 2025 09:30:23 +0200

Simplified count_moves() in cpp api

Diffstat:
Mcpp/examples/solve_h48h3k2.cpp | 11+++++++----
Mcpp/nissy.cpp | 7++-----
Mcpp/nissy.h | 2+-
3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp @@ -81,11 +81,14 @@ int main() { return 1; } - if (solve_result.solutions.size() == 0) + if (solve_result.solutions.size() == 0) { std::cout << "No solution found!" << std::endl; - else - std::cout << "Solution: " << - solve_result.solutions[0] << std::endl; + } else { + auto& sol = solve_result.solutions[0]; + auto len = nissy::count_moves(sol).value; + std::cout << "Solution (" << len << " moves): " + << sol << std::endl; + } return 0; } diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp @@ -221,13 +221,10 @@ namespace nissy { solver::solver(const std::string& str) : name{str} {} - std::variant<unsigned, error> - count_moves(const std::string& moves) + error count_moves(const std::string& moves) { auto err = nissy_countmoves(moves.c_str()); - if (err < 0) - return error{err}; - return (unsigned)err; + return error{err}; } void set_logger(const std::function<void(const char *)>& log) diff --git a/cpp/nissy.h b/cpp/nissy.h @@ -99,7 +99,7 @@ namespace nissy { solver(const std::string& name); }; - std::variant<unsigned, error> count_moves(const std::string&); + error count_moves(const std::string&); void set_logger(const std::function<void(const char*)>&); }