From 992de12cc081e7dde16c3c231f83bfa77c67825a Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 31 Jul 2025 09:47:57 +0200 Subject: Added move sequence comparison function --- cpp/nissy.cpp | 14 ++++++++++++++ cpp/nissy.h | 10 ++++++++++ 2 files changed, 24 insertions(+) (limited to 'cpp') diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp index 2c290a6..90fcf20 100644 --- a/cpp/nissy.cpp +++ b/cpp/nissy.cpp @@ -24,6 +24,7 @@ extern "C" { const unsigned char *, unsigned, char *, long long *, int (*)(void *), void *); long long nissy_countmoves(const char *); + long long nissy_comparemoves(const char *, const char *); long long nissy_setlogger(void (*)(const char *, void *), void *); } @@ -53,6 +54,9 @@ namespace nissy { const status status::STOP{1}; const status status::PAUSE{2}; + const compare_result compare_result::EQUAL{0}; + const compare_result compare_result::DIFFERENT{99}; + namespace size { constexpr size_t CUBE = 24; constexpr size_t TRANSFORMATION = 12; @@ -210,6 +214,16 @@ namespace nissy { return error{err}; } + std::variant + compare_moves(const std::string& m1, const std::string& m2) + { + auto cmp = nissy_comparemoves(m1.c_str(), m2.c_str()); + if (cmp < 0) + return error{cmp}; + else + return compare_result{cmp}; + } + void set_logger(void (*log)(const char *, void *), void *data) { nissy_setlogger(log, data); diff --git a/cpp/nissy.h b/cpp/nissy.h index 817307c..199af10 100644 --- a/cpp/nissy.h +++ b/cpp/nissy.h @@ -55,6 +55,14 @@ namespace nissy { static const status PAUSE; }; + class compare_result { + public: + long long value; + + static const compare_result EQUAL; + static const compare_result DIFFERENT; + }; + class cube { public: cube(); @@ -103,6 +111,8 @@ namespace nissy { }; error count_moves(const std::string&); + std::variant compare_moves( + const std::string&, const std::string&); void set_logger(void (*)(const char *, void *), void *); } -- cgit v1.3