From 9b01ffd5aec49faa824860c4c64c3783deb504ef Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 6 Jan 2023 16:53:57 +0800 Subject: [PATCH] feat: short code function verify --- klotski/main.cc | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/klotski/main.cc b/klotski/main.cc index 5e1b229..911e9c2 100644 --- a/klotski/main.cc +++ b/klotski/main.cc @@ -1,7 +1,7 @@ #include -//#include "all_cases.h" +#include "all_cases.h" #include "short_code.h" -#include "common_code.h" +//#include "common_code.h" int main() { @@ -19,15 +19,47 @@ int main() { // } - auto s = ShortCode(); +// auto s = ShortCode(); // auto s = ShortCode(ShortCode::Mode::NORMAL); // auto s = ShortCode(ShortCode::Mode::FAST); // s.speed_up(ShortCode::Mode::NORMAL); - s.speed_up(ShortCode::Mode::FAST); +// s.speed_up(ShortCode::Mode::FAST); - printf("%d\n", s.zip_short_code(0x6EC0F8800)); - printf("%09lX\n", s.unzip_short_code(14323231)); +// printf("%d\n", s.zip_short_code(0x6EC0F8800)); +// printf("%09lX\n", s.unzip_short_code(14323231)); + + + std::cout << "preparing..." << std::endl; + std::vector all_cases; + auto a = AllCases(AllCases::ALL_CASES); + for (int head = 0; head < 16; ++head) { + uint64_t prefix = (uint64_t)head << 32; + for (const auto &range : (*a.get_all_cases())[head]) { + all_cases.emplace_back(prefix | range); + } + } + +// auto s = ShortCode(ShortCode::Mode::NORMAL); + auto s = ShortCode(ShortCode::Mode::FAST); + std::cout << "start working" << std::endl; + + for (auto short_code = 0; short_code < all_cases.size(); ++short_code) { + uint64_t common_code = all_cases[short_code]; + + if (short_code != s.zip_short_code(common_code)) { + printf("ERROR: zip %d\n", short_code); + } + if (common_code != s.unzip_short_code(short_code)) { + printf("ERROR: unzip %09lX\n", common_code); + } + + if (short_code % 2000000 == 0) { +// if (short_code % 10000 == 0) { + std::cout << ((float)short_code / (float)all_cases.size() * 100) << "%" << std::endl; + } + } + std::cout << "complete verify" << std::endl; return 0; }