diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-15 09:30:23 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-15 09:30:23 +0200 |
| commit | ad1e483787cbc3aeb62c9afb9e31520df5a4b559 (patch) | |
| tree | 89ef2ed15791bfd227ac3c97f6669fd4c6cbf801 | |
| parent | 6b3f40ac441fede250b9c381952fafd8aac28bd5 (diff) | |
| download | nissy-core-ad1e483787cbc3aeb62c9afb9e31520df5a4b559.tar.gz nissy-core-ad1e483787cbc3aeb62c9afb9e31520df5a4b559.zip | |
Simplified count_moves() in cpp api
Diffstat (limited to '')
| -rw-r--r-- | cpp/examples/solve_h48h3k2.cpp | 11 | ||||
| -rw-r--r-- | cpp/nissy.cpp | 7 | ||||
| -rw-r--r-- | cpp/nissy.h | 2 |
3 files changed, 10 insertions, 10 deletions
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() { | |||
| 81 | return 1; | 81 | return 1; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | if (solve_result.solutions.size() == 0) | 84 | if (solve_result.solutions.size() == 0) { |
| 85 | std::cout << "No solution found!" << std::endl; | 85 | std::cout << "No solution found!" << std::endl; |
| 86 | else | 86 | } else { |
| 87 | std::cout << "Solution: " << | 87 | auto& sol = solve_result.solutions[0]; |
| 88 | solve_result.solutions[0] << std::endl; | 88 | auto len = nissy::count_moves(sol).value; |
| 89 | std::cout << "Solution (" << len << " moves): " | ||
| 90 | << sol << std::endl; | ||
| 91 | } | ||
| 89 | 92 | ||
| 90 | return 0; | 93 | return 0; |
| 91 | } | 94 | } |
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 { | |||
| 221 | 221 | ||
| 222 | solver::solver(const std::string& str) : name{str} {} | 222 | solver::solver(const std::string& str) : name{str} {} |
| 223 | 223 | ||
| 224 | std::variant<unsigned, error> | 224 | error count_moves(const std::string& moves) |
| 225 | count_moves(const std::string& moves) | ||
| 226 | { | 225 | { |
| 227 | auto err = nissy_countmoves(moves.c_str()); | 226 | auto err = nissy_countmoves(moves.c_str()); |
| 228 | if (err < 0) | 227 | return error{err}; |
| 229 | return error{err}; | ||
| 230 | return (unsigned)err; | ||
| 231 | } | 228 | } |
| 232 | 229 | ||
| 233 | void set_logger(const std::function<void(const char *)>& log) | 230 | void set_logger(const std::function<void(const char *)>& 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 { | |||
| 99 | solver(const std::string& name); | 99 | solver(const std::string& name); |
| 100 | }; | 100 | }; |
| 101 | 101 | ||
| 102 | std::variant<unsigned, error> count_moves(const std::string&); | 102 | error count_moves(const std::string&); |
| 103 | void set_logger(const std::function<void(const char*)>&); | 103 | void set_logger(const std::function<void(const char*)>&); |
| 104 | } | 104 | } |
| 105 | 105 | ||
