From ad1e483787cbc3aeb62c9afb9e31520df5a4b559 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 15 Apr 2025 09:30:23 +0200 Subject: Simplified count_moves() in cpp api --- cpp/examples/solve_h48h3k2.cpp | 11 +++++++---- cpp/nissy.cpp | 7 ++----- cpp/nissy.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'cpp') diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp index 6639c55..b747976 100644 --- 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 index 6e1b700..b3bf6c4 100644 --- a/cpp/nissy.cpp +++ b/cpp/nissy.cpp @@ -221,13 +221,10 @@ namespace nissy { solver::solver(const std::string& str) : name{str} {} - std::variant - 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& log) diff --git a/cpp/nissy.h b/cpp/nissy.h index 448704e..1981f1c 100644 --- a/cpp/nissy.h +++ b/cpp/nissy.h @@ -99,7 +99,7 @@ namespace nissy { solver(const std::string& name); }; - std::variant count_moves(const std::string&); + error count_moves(const std::string&); void set_logger(const std::function&); } -- cgit v1.3