From 48e9cd59411100c5fdfb8213c517d248de187d58 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 10 Apr 2023 16:54:16 +0800 Subject: [PATCH] remove: legacy code --- legacy/main.cc | 116 --------------------- src/klotski_core/ffi/tmain.cc | 185 +--------------------------------- src/main.c | 59 ----------- 3 files changed, 1 insertion(+), 359 deletions(-) diff --git a/legacy/main.cc b/legacy/main.cc index 1bf658c..5ac2340 100644 --- a/legacy/main.cc +++ b/legacy/main.cc @@ -2,51 +2,8 @@ #include "ffi/klotski.h" -//#include "utils/common.h" -//#include "all_cases/all_cases.h" -// -//#include "raw_code/raw_code.h" -//#include "short_code/short_code.h" -//#include "common_code/common_code.h" -// -//#include "core/core.h" -//#include "analyse/analyse.h" -//#include "fast_cal/fast_cal.h" - -//#include "graph.h" - -//#include "benchmark.h" - -//#include - int main() { -// std::cout << "start test" << std::endl; - -// std::cout << (uint32_t)Common::check_range(1, Common::range_reverse(0xA9BF0C00)) << std::endl; -// -// AllCases::build(); -// for (const auto &a : AllCases::fetch()) { -// std::cout << a.size() << std::endl; -// } -// -// std::cout << RawCode::from_common_code("1a9bf0c") << std::endl; -// std::cout << RawCode::create(0x0603EDF5CAFFF5E2) << std::endl; -// -// std::cout << CommonCode::create(0x1A9BF0C00) << std::endl; -// std::cout << CommonCode::from_string("1a9bf0c") << std::endl; -// std::cout << CommonCode::from_short_code(4091296) << std::endl; -// std::cout << CommonCode::from_raw_code(0x0603EDF5CAFFF5E2) << std::endl; -// -// std::cout << ShortCode::create(4091296) << std::endl; -// std::cout << ShortCode::from_string("4WVE1") << std::endl; -// std::cout << ShortCode::from_common_code(0x1A9BF0C00) << std::endl; -// -// auto core = Core([](uint64_t code, uint64_t mask) { -// printf("new case -> code = %015lX | mask = %015lX\n", code, mask); -// }); -// core.next_cases(RawCode::from_common_code("1a9bf0c").unwrap(), 0); -// // for (const auto &c : FastCal::resolve(RawCode::from_common_code("1a9bf0c"))) { // std::cout << c << std::endl; // } @@ -56,57 +13,9 @@ int main() { // std::cout << s << std::endl; // } -// Benchmark::basic_ranges(std::cout); - - auto start = clock(); - - _tmain(); - - std::cerr << (clock() - start) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; - -// std::cout << "end test" << std::endl; - -// BasicRanges::build(); - -// Benchmark::basic_ranges(std::cout); -// std::cout << std::endl; -// Benchmark::all_cases(std::cout); - -// std::cout << std::endl; -// Benchmark::basic_ranges(std::cout); - return 0; -// BasicRanges::build(); -// AllCases::build(); - - -// std::vector test_cases; -// { -// AllCases::build(); -// std::vector all_cases; -// for (uint64_t head = 0; head < 16; ++head) { -// for (const auto &range : AllCases::fetch()[head]) { -// all_cases.emplace_back(head << 32 | range); -// } -// } -// for (uint32_t i = 0; i < 100; ++i) { -// test_cases.emplace_back( -// RawCode::from_common_code(all_cases.at(i * 293344)) -// ); -// } -// } -// std::cout << "test size -> " << test_cases.size() << std::endl; - - -// std::cout << "wait 3s" << std::endl; -// sleep(3); - -// std::cout << "start benchmark" << std::endl; -// auto start_time = clock(); - - // auto fc = FastCal(RawCode::from_common_code("1a9bf0c")); // fc.solve(); @@ -119,8 +28,6 @@ int main() { // } -// auto start_time = clock(); - // auto a = Analyse(RawCode::from_common_code("1a9bf0c")); // auto a = Analyse(RawCode::from_common_code("4fea134")); // auto a = Analyse(RawCode::from_common_code("A5D3AF")); @@ -136,10 +43,6 @@ int main() { // } // std::cout << ret.size() << std::endl; - -// std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; - - // start_time = clock(); // auto svg_ret = a.backtrack(ret); // std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; @@ -150,7 +53,6 @@ int main() { // std::cout << svg_data << std::endl; - // std::cout << a.layer_export(81).size() << std::endl; // std::cout << a.layer_export()[81].size() << std::endl; @@ -175,23 +77,5 @@ int main() { // TODO: FATAL ERROR -> don't using mask in Analyse // a.backtrack(raw_codes); - -// std::cout << ShortCode("EP4HZ") << std::endl; -// std::cout << ShortCode(14323231) << std::endl; - -// std::cout << RawCode::from_common_code("4fea134") << std::endl; -// std::cout << CommonCode::from_raw_code(0xE58FC85FFEBC4DB) << std::endl; -// std::cout << ShortCode::from_common_code("4fea134") << std::endl; -// std::cout << CommonCode::from_short_code("AXCZN") << std::endl; - - -// std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl; -// std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; -// std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; - -// std::cout << "complete benchmark" << std::endl; - -// pause(); - return 0; } diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index ad21b0f..4d89df2 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -20,195 +20,12 @@ using klotski::RawCode; using klotski::CommonCode; using klotski::Benchmark; - using klotski::BasicRanges; void tmain() { - -// uint32_t sum = 0; -// for (uint32_t type_id = 0; type_id < 204; ++type_id) { -// sum += Group::all_cases(type_id).size(); -// } -// std::cout << "sum = " << sum << std::endl; - -// for (uint32_t type_id = 0; type_id < 204; ++type_id) { -// -// std::vector codes; -// std::vector codes_; -// for (auto &&t : Group::all_cases(type_id)) { -// codes.emplace_back(t.unwrap()); -// codes_.emplace_back(t.unwrap()); -// } -// std::sort(codes.begin(), codes.end()); -// -// if (codes != codes_) { -// std::cout << type_id << std::endl; -// } -// } - - std::vector ret; - - for (uint32_t type_id = 0; type_id < 204; ++type_id) { -// auto tmp = Group::block_num(type_id); -// std::cout << int(tmp.n_2x1 + tmp.n_1x2) << " "; -// std::cout << (int)tmp.n_1x1 << " "; -// std::cout << (int)tmp.n_1x2 << " "; -// std::cout << Group::all_cases(type_id).size() << std::endl; - ret.emplace_back(Group::all_cases(type_id).size()); - } - - for (uint32_t i = 0; i < ret.size(); ++i) { - printf("%06d, ", ret[i]); - if (i % 8 == 7) { - printf("\n"); - } - } - - -// auto cases = std::vector(); -// auto common_codes = AllCases::release(); -// for (uint64_t i = 0; i < common_codes.size(); i += 293345 * 2) { -// cases.emplace_back(common_codes[i].to_raw_code()); -// } -// -// std::cout << "select " << cases.size() << " cases" << std::endl; - - auto start = clock(); - -// for (auto &&raw_code : cases) { -// std::cout << Group::demo(raw_code) << std::endl; -// } - -// Group::demo(RawCode::from_common_code(0x1A9BF0C00)); -// Group::demo(RawCode::from_common_code(0x4FEA13400)); - -// auto ret = Group::group_cases(RawCode::from_common_code(0x1A9BF0C00)); -// std::cout << ret.size() << std::endl; -// std::cout << ret[0] << std::endl; -// std::cout << ret[1] << std::endl; - -// auto tmp = RawCode::from_common_code(0x1A9BF0C00); -// for (int i = 0; i < 100; ++i) { -// Group::group_cases(tmp); -// } - -// std::cout << ((clock() - start) * 1000 / CLOCKS_PER_SEC) << "ms" << std::endl; - - return; - // printf("tmain start\n"); -// std::cout << "warm up: " << Benchmark::warm_up(1000000) << "us" << std::endl; - - std::cout << "range flip: " << - Benchmark::range_flip() << "ns" << std::endl; - - std::cout << "basic ranges: " << - Benchmark::basic_ranges() << "ms" << std::endl; - std::cout << "all cases: " << - Benchmark::all_cases() << "ms" << std::endl; - - Benchmark::data_initialize(); - - std::cout << "raw code check: " << - Benchmark::raw_code_check() << "ns" << std::endl; - std::cout << "short code check: " << - Benchmark::short_code_check() << "ns" << std::endl; - std::cout << "common code check: " << - Benchmark::common_code_check() << "ns" << std::endl; - - std::cout << "raw code check random: " << - Benchmark::raw_code_check_random() << "ns" << std::endl; - std::cout << "short code check random: " << - Benchmark::short_code_check_random() << "ns" << std::endl; - std::cout << "common code check random: " << - Benchmark::common_code_check_random() << "ns" << std::endl; - - std::cout << "short code to string: " << - Benchmark::short_code_to_string() << "ns" << std::endl; - std::cout << "short code from string: " << - Benchmark::short_code_from_string() << "ns" << std::endl; - - std::cout << "common code to string: " << - Benchmark::common_code_to_string() << "ns" << std::endl; - std::cout << "common code from string: " << - Benchmark::common_code_from_string() << "ns" << std::endl; - - std::cout << "common code to raw code: " << - Benchmark::common_code_to_raw_code() << "ns" << std::endl; - std::cout << "raw code to common code: " << - Benchmark::raw_code_to_common_code() << "ns" << std::endl; - - std::cout << "common code to short code: " << - Benchmark::common_code_to_short_code() << "us" << std::endl; - std::cout << "short code to common code: " << - Benchmark::short_code_to_common_code() << "us" << std::endl; - - std::cout << "common code to short code fast: " << - Benchmark::common_code_to_short_code_fast() << "ns" << std::endl; - std::cout << "short code to common code fast: " << - Benchmark::short_code_to_common_code_fast() << "ns" << std::endl; - - std::cout << "vertical mirror check: " << - Benchmark::vertical_mirror_check() << "ns" << std::endl; - std::cout << "horizontal mirror check: " << - Benchmark::horizontal_mirror_check() << "ns" << std::endl; - std::cout << "vertical mirror convert: " << - Benchmark::vertical_mirror_convert() << "ns" << std::endl; - std::cout << "horizontal mirror convert: " << - Benchmark::horizontal_mirror_convert() << "ns" << std::endl; - - return; - - std::vector next; - - auto core = klotski::Core([&next](uint64_t code, uint64_t) { - next.emplace_back(code); - }); - - auto next_num = [&core, &next](uint64_t raw_code) -> uint32_t { - next.clear(); - core.next_cases(raw_code, 0); - return next.size(); - }; - - std::vector all_cases; - - for (uint64_t head = 0; head < 16; ++head) { - - for (const auto &range : klotski::AllCases::fetch()[head]) { - - uint64_t raw_code = klotski::RawCode::from_common_code(head << 32 | range).unwrap(); - - all_cases.emplace_back(raw_code); - - } - - } - - std::vector next_size; - - std::cout << "start search" << std::endl; - -// auto start = clock(); - - for (const auto &c : all_cases) { - - next_size.emplace_back(next_num(c)); - - } - -// std::cout << ((clock() - start) * 1000 / CLOCKS_PER_SEC) << "ms" << std::endl; - -// std::sort(next_size.begin(), next_size.end()); -// std::cout << next_size[0] << std::endl; -// std::cout << next_size[next_size.size() - 1] << std::endl; - - for (uint32_t i = 0; i < 69; ++i) { - - std::cout << i << ": " << std::count(next_size.begin(), next_size.end(), i) << std::endl; - } - printf("tmain exit\n"); +// printf("tmain exit\n"); } diff --git a/src/main.c b/src/main.c index 3d27c09..1f26c8e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,65 +1,6 @@ -#include #include "klotski.h" int main() { -// printf("cli boot\n"); - tmain(); return 0; - -// bool ret = common_code_check(0x1A9BF0C00); -// printf("result -> %d\n", ret); - - uint64_t raw_code; - uint32_t short_code; -// uint64_t common_code = 0x1A9BF0C00; - uint64_t common_code = 0x4FEA13400; - - short_code_enable_fast(); - - if (!common_code_to_raw_code(common_code, &raw_code)) { - printf("error\n"); - } else { - printf("raw code -> %015lX\n", raw_code); - } - - if (!common_code_to_short_code(common_code, &short_code)) { - printf("error\n"); - } else { - printf("short code -> %d\n", short_code); - } - - char common_code_str[COMMON_CODE_STR_SIZE]; - if (!common_code_to_string(common_code, common_code_str)) { - printf("error\n"); - } else { - printf("string -> %s\n", common_code_str); - } - if (!common_code_to_string_shorten(common_code, common_code_str)) { - printf("error\n"); - } else { - printf("string shorten -> %s\n", common_code_str); - } - if (!common_code_from_string(common_code_str, &common_code)) { - printf("error\n"); - } else { - printf("common code -> %09lX\n", common_code); - } - - char short_code_str[SHORT_CODE_STR_SIZE]; - if (!short_code_to_string(short_code, short_code_str)) { - printf("error\n"); - } else { - printf("string -> %s\n", short_code_str); - } - if (!short_code_from_string(short_code_str, &short_code)) { - printf("error\n"); - } else { - printf("short code -> %d\n", short_code); - } - - printf("version -> %d.%d.%d\n", get_version_major(), get_version_minor(), get_version_patch()); - -// printf("cli exit\n"); - return 0; }