From 12710d3f08020ca97982277fa99555008d0a4be4 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 26 Jan 2023 16:11:19 +0800 Subject: [PATCH] chore: update compile structure --- .gitignore | 1 + legacy/main-old.cc | 70 ++++++ legacy/main.cc | 225 +++++++++++++++---- src/CMakeLists.txt | 9 +- src/benchmark/CMakeLists.txt | 6 - src/klotski/CMakeLists.txt | 36 +-- src/klotski/all_cases/CMakeLists.txt | 4 +- src/klotski/analyse/CMakeLists.txt | 4 +- src/klotski/benchmark/CMakeLists.txt | 4 + src/{ => klotski}/benchmark/benchmark.cc | 0 src/{ => klotski}/benchmark/benchmark.h | 0 src/{ => klotski}/benchmark/chore.cc | 2 + src/klotski/common_code/CMakeLists.txt | 4 +- src/klotski/core/CMakeLists.txt | 2 +- src/klotski/fast_cal/CMakeLists.txt | 4 +- src/klotski/ffi/{klotski_ffi.cc => codec.cc} | 1 - src/klotski/ffi/klotski.h | 17 +- src/klotski/ffi/tmain.cc | 18 +- src/klotski/graph/CMakeLists.txt | 4 +- src/klotski/raw_code/CMakeLists.txt | 4 +- src/klotski/short_code/CMakeLists.txt | 4 +- src/klotski/utils/CMakeLists.txt | 2 +- src/main.c | 10 + src/main.cc | 197 ---------------- test/CMakeLists.txt | 6 +- 25 files changed, 330 insertions(+), 304 deletions(-) create mode 100644 legacy/main-old.cc delete mode 100644 src/benchmark/CMakeLists.txt create mode 100644 src/klotski/benchmark/CMakeLists.txt rename src/{ => klotski}/benchmark/benchmark.cc (100%) rename src/{ => klotski}/benchmark/benchmark.h (100%) rename src/{ => klotski}/benchmark/chore.cc (94%) rename src/klotski/ffi/{klotski_ffi.cc => codec.cc} (99%) create mode 100644 src/main.c delete mode 100644 src/main.cc diff --git a/.gitignore b/.gitignore index 8cc57cd..2b9d3d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/bin/ /.idea/ /cmake-build-debug/ /cmake-build-release/ diff --git a/legacy/main-old.cc b/legacy/main-old.cc new file mode 100644 index 0000000..14a817c --- /dev/null +++ b/legacy/main-old.cc @@ -0,0 +1,70 @@ +#include + +/* + + uint64_t -> 0000 + [xxx] * 20 + + 2x2 2x1 1x2 1x1 + # # # # # # + # # # + + 00 01 02 03 + 04 05 06 07 + 08 09 10 11 + 12 13 14 15 + 16 17 18 19 + + x1 (%4) => 0 1 2 3 + x3 (%4) => 0 3 2 1 + +*/ + +/* +====================================================== + + 1x1 -> 011 000 000 000 -> 0000 0000 0011 -> 0x3 + + 1x2 -> 001 111 000 000 -> 0000 0011 1001 -> 0x39 + + 2x1 -> 010 000 000 000 -> 0000 0000 0010 -> 0x7002 + 111 000 000 000 -> 0000 0000 0111 + + 2x2 -> 100 111 000 000 -> 0000 0011 1100 -> 0x3F03C + 111 111 000 000 -> 0000 0011 1111 + +====================================================== + + 1x1 -> 111 000 000 000 -> 0000 0000 0111 -> 0x7 + + 1x2 -> 111 111 000 000 -> 0000 0011 1111 -> 0x3F + + 2x1 -> 111 000 000 000 -> 0000 0000 0111 -> 0x7007 + 111 000 000 000 -> 0000 0000 0111 + + 2x2 -> 111 111 000 000 -> 0000 0011 1111 -> 0x3F03F + 111 111 000 000 -> 0000 0011 1111 + +====================================================== +*/ + +int main() { + printf("Klotski engine\n"); + + // 0x4FEA13400 + // # # # @ | 011 011 011 010 => 0100 1101 1011 -> 4DB + // * * & @ | 100 111 010 111 => 1110 1011 1100 -> EBC + // * * & $ | 111 111 111 010 => 0101 1111 1111 -> 5FF + // . + + $ | 000 001 111 111 => 1111 1100 1000 -> FC8 + // . # ~ ~ | 000 011 001 111 => 1110 0101 1000 -> E58 + // 0x0E58FC85FFEBC4DB + + // 0x1A9BF0C00 + // @ * * @ | 010 100 111 010 => 0101 1110 0010 -> 5E2 + // @ * * @ | 111 111 111 111 => 1111 1111 1111 -> FFF + // $ ~ ~ $ | 010 001 111 010 => 0101 1100 1010 -> 5CA + // $ # # $ | 111 011 011 111 => 1110 1101 1111 -> EDF + // # . . # | 011 000 000 011 => 0110 0000 0011 -> 603 + // 0x0603EDF5CAFFF5E2 + + return 0; +} diff --git a/legacy/main.cc b/legacy/main.cc index 14a817c..1bf658c 100644 --- a/legacy/main.cc +++ b/legacy/main.cc @@ -1,70 +1,197 @@ -#include +#include -/* +#include "ffi/klotski.h" - uint64_t -> 0000 + [xxx] * 20 +//#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" - 2x2 2x1 1x2 1x1 - # # # # # # - # # # +//#include "graph.h" - 00 01 02 03 - 04 05 06 07 - 08 09 10 11 - 12 13 14 15 - 16 17 18 19 +//#include "benchmark.h" - x1 (%4) => 0 1 2 3 - x3 (%4) => 0 3 2 1 +//#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; +// } +// +// auto a = Analyse(RawCode::from_common_code("1a9bf0c")); +// for (const auto &s : a.build_resolve()) { +// 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; - 1x1 -> 011 000 000 000 -> 0000 0000 0011 -> 0x3 - 1x2 -> 001 111 000 000 -> 0000 0011 1001 -> 0x39 +// BasicRanges::build(); +// AllCases::build(); - 2x1 -> 010 000 000 000 -> 0000 0000 0010 -> 0x7002 - 111 000 000 000 -> 0000 0000 0111 - 2x2 -> 100 111 000 000 -> 0000 0011 1100 -> 0x3F03C - 111 111 000 000 -> 0000 0011 1111 +// 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; -====================================================== - 1x1 -> 111 000 000 000 -> 0000 0000 0111 -> 0x7 +// std::cout << "wait 3s" << std::endl; +// sleep(3); - 1x2 -> 111 111 000 000 -> 0000 0011 1111 -> 0x3F +// std::cout << "start benchmark" << std::endl; +// auto start_time = clock(); - 2x1 -> 111 000 000 000 -> 0000 0000 0111 -> 0x7007 - 111 000 000 000 -> 0000 0000 0111 - 2x2 -> 111 111 000 000 -> 0000 0011 1111 -> 0x3F03F - 111 111 000 000 -> 0000 0011 1111 +// auto fc = FastCal(RawCode::from_common_code("1a9bf0c")); +// fc.solve(); -====================================================== -*/ +// { +// auto fc = FastCal(RawCode::unsafe_create(0)); +// for (auto code : test_cases) { +// fc.set_root(code); +// fc.solve(); +// } +// } -int main() { - printf("Klotski engine\n"); - - // 0x4FEA13400 - // # # # @ | 011 011 011 010 => 0100 1101 1011 -> 4DB - // * * & @ | 100 111 010 111 => 1110 1011 1100 -> EBC - // * * & $ | 111 111 111 010 => 0101 1111 1111 -> 5FF - // . + + $ | 000 001 111 111 => 1111 1100 1000 -> FC8 - // . # ~ ~ | 000 011 001 111 => 1110 0101 1000 -> E58 - // 0x0E58FC85FFEBC4DB - - // 0x1A9BF0C00 - // @ * * @ | 010 100 111 010 => 0101 1110 0010 -> 5E2 - // @ * * @ | 111 111 111 111 => 1111 1111 1111 -> FFF - // $ ~ ~ $ | 010 001 111 010 => 0101 1100 1010 -> 5CA - // $ # # $ | 111 011 011 111 => 1110 1101 1111 -> EDF - // # . . # | 011 000 000 011 => 0110 0000 0011 -> 603 - // 0x0603EDF5CAFFF5E2 + +// 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")); + + +// a.build(); +// auto ret = a.build_until([](uint64_t code) { +// return ((code >> (3 * 0xD)) & 0b111) == B_2x2; +// }); +// auto ret = a.build_resolve(); +// for (const auto &r : ret) { +// std::cout << r << std::endl; +// } +// 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; + + +// auto g = Graph(); +// auto svg_data = g.svg_demo(svg_ret); + +// std::cout << svg_data << std::endl; + + +// std::cout << a.layer_export(81).size() << std::endl; +// std::cout << a.layer_export()[81].size() << std::endl; + + +// std::vector raw_codes = { +// CommonCode(0xDAAF4CC00).to_raw_code().unwrap(), +// CommonCode(0xDAA7F3000).to_raw_code().unwrap(), +// }; +// a.backtrack(raw_codes); + +// std::vector raw_codes = { +// CommonCode("DE77D80").to_raw_code().unwrap(), +// CommonCode("DF6DD80").to_raw_code().unwrap(), +// CommonCode("DF69730").to_raw_code().unwrap(), +// CommonCode("DE76D30").to_raw_code().unwrap(), +// CommonCode("D5AF730").to_raw_code().unwrap(), +// CommonCode("D5B43BC").to_raw_code().unwrap(), +// }; +// std::vector raw_codes = { +// CommonCode("EF697C0").to_raw_code().unwrap(), +// }; + // 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/CMakeLists.txt b/src/CMakeLists.txt index e610752..1ee3004 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,8 @@ cmake_minimum_required(VERSION 3.0) -include_directories(klotski) -include_directories(benchmark) +include_directories(klotski/ffi) add_subdirectory(klotski) -add_subdirectory(benchmark) -add_executable(klotski_bin main.cc) -target_link_libraries(klotski_bin benchmark) -#target_link_libraries(klotski_bin klotski) +add_executable(demo main.c) +target_link_libraries(demo PUBLIC klotski) diff --git a/src/benchmark/CMakeLists.txt b/src/benchmark/CMakeLists.txt deleted file mode 100644 index d1dc82c..0000000 --- a/src/benchmark/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.0) - -include_directories(../klotski/all_cases) - -add_library(benchmark chore.cc benchmark.cc) -target_link_libraries(benchmark klotski) diff --git a/src/klotski/CMakeLists.txt b/src/klotski/CMakeLists.txt index 6605b0b..1484086 100644 --- a/src/klotski/CMakeLists.txt +++ b/src/klotski/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 3.0) -################################################ +project(klotski-core LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 14) + +################################################################ include_directories(utils) include_directories(all_cases) @@ -13,7 +17,7 @@ include_directories(core) include_directories(analyse) include_directories(fast_cal) -################################################ +################################################################ add_subdirectory(utils) add_subdirectory(all_cases) @@ -26,22 +30,24 @@ add_subdirectory(core) add_subdirectory(analyse) add_subdirectory(fast_cal) -################################################ +################################################################ + +add_library(klotski-core OBJECT ffi/codec.cc ffi/tmain.cc) -#add_library(klotski STATIC klotski_ffi.cc) -add_library(klotski SHARED ffi/klotski_ffi.cc ffi/tmain.cc) +target_link_libraries(klotski-core utils) +target_link_libraries(klotski-core all_cases) -################################################ +target_link_libraries(klotski-core raw_code) +target_link_libraries(klotski-core short_code) +target_link_libraries(klotski-core common_code) -target_link_libraries(klotski utils) -target_link_libraries(klotski all_cases) +target_link_libraries(klotski-core core) +target_link_libraries(klotski-core analyse) +target_link_libraries(klotski-core fast_cal) -target_link_libraries(klotski raw_code) -target_link_libraries(klotski short_code) -target_link_libraries(klotski common_code) +################################################################ -target_link_libraries(klotski core) -target_link_libraries(klotski analyse) -target_link_libraries(klotski fast_cal) +#add_library(klotski SHARED $) +add_library(klotski STATIC $) -################################################ +################################################################ diff --git a/src/klotski/all_cases/CMakeLists.txt b/src/klotski/all_cases/CMakeLists.txt index 29a672f..3fcf4da 100644 --- a/src/klotski/all_cases/CMakeLists.txt +++ b/src/klotski/all_cases/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.0) -add_library(all_cases all_cases.cc basic_ranges.cc) -target_link_libraries(all_cases utils) +add_library(all_cases STATIC all_cases.cc basic_ranges.cc) +target_link_libraries(all_cases PUBLIC utils) diff --git a/src/klotski/analyse/CMakeLists.txt b/src/klotski/analyse/CMakeLists.txt index 3dadefd..839307f 100644 --- a/src/klotski/analyse/CMakeLists.txt +++ b/src/klotski/analyse/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.0) -add_library(analyse analyse.cc backtrack.cc) -target_link_libraries(analyse core) +add_library(analyse STATIC analyse.cc backtrack.cc) +target_link_libraries(analyse PUBLIC core) diff --git a/src/klotski/benchmark/CMakeLists.txt b/src/klotski/benchmark/CMakeLists.txt new file mode 100644 index 0000000..b7e7f2a --- /dev/null +++ b/src/klotski/benchmark/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.0) + +add_library(benchmark STATIC chore.cc benchmark.cc) +target_link_libraries(benchmark PUBLIC all_cases) diff --git a/src/benchmark/benchmark.cc b/src/klotski/benchmark/benchmark.cc similarity index 100% rename from src/benchmark/benchmark.cc rename to src/klotski/benchmark/benchmark.cc diff --git a/src/benchmark/benchmark.h b/src/klotski/benchmark/benchmark.h similarity index 100% rename from src/benchmark/benchmark.h rename to src/klotski/benchmark/benchmark.h diff --git a/src/benchmark/chore.cc b/src/klotski/benchmark/chore.cc similarity index 94% rename from src/benchmark/chore.cc rename to src/klotski/benchmark/chore.cc index 195d516..9badc44 100644 --- a/src/benchmark/chore.cc +++ b/src/klotski/benchmark/chore.cc @@ -1,5 +1,7 @@ #include "benchmark.h" +// TODO: remove std::cout output -> only return benchmark status + /// colorful string std::string Benchmark::color_red(const std::string &str) { return std::string("\033[31m") + str + "\033[0m"; diff --git a/src/klotski/common_code/CMakeLists.txt b/src/klotski/common_code/CMakeLists.txt index f4e40fd..dd52c5f 100644 --- a/src/klotski/common_code/CMakeLists.txt +++ b/src/klotski/common_code/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.0) -add_library(common_code convert.cc serialize.cc common_code.cc) -target_link_libraries(common_code utils) +add_library(common_code STATIC convert.cc serialize.cc common_code.cc) +target_link_libraries(common_code PUBLIC utils) diff --git a/src/klotski/core/CMakeLists.txt b/src/klotski/core/CMakeLists.txt index fae268d..71314f0 100644 --- a/src/klotski/core/CMakeLists.txt +++ b/src/klotski/core/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 3.0) -add_library(core core.cc) +add_library(core STATIC core.cc) diff --git a/src/klotski/fast_cal/CMakeLists.txt b/src/klotski/fast_cal/CMakeLists.txt index 7a0967c..a2da0e3 100644 --- a/src/klotski/fast_cal/CMakeLists.txt +++ b/src/klotski/fast_cal/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.0) -add_library(fast_cal cal_core.cc fast_cal.cc) -target_link_libraries(fast_cal core) +add_library(fast_cal STATIC cal_core.cc fast_cal.cc) +target_link_libraries(fast_cal PUBLIC core) diff --git a/src/klotski/ffi/klotski_ffi.cc b/src/klotski/ffi/codec.cc similarity index 99% rename from src/klotski/ffi/klotski_ffi.cc rename to src/klotski/ffi/codec.cc index a57dbb9..d75f61e 100644 --- a/src/klotski/ffi/klotski_ffi.cc +++ b/src/klotski/ffi/codec.cc @@ -1,5 +1,4 @@ #include "klotski.h" - #include "short_code.h" void short_code_speed_up() { diff --git a/src/klotski/ffi/klotski.h b/src/klotski/ffi/klotski.h index 8de902b..b8e6360 100644 --- a/src/klotski/ffi/klotski.h +++ b/src/klotski/ffi/klotski.h @@ -1,12 +1,23 @@ #pragma once +#ifdef __cplusplus extern "C" { - void _tmain(); +#endif + +void tmain(); + +#ifdef __cplusplus } +#endif + +#ifdef __cplusplus extern "C" { +#endif - void short_code_speed_up(); - void short_code_speed_up_fast(); +void short_code_speed_up(); +void short_code_speed_up_fast(); +#ifdef __cplusplus } +#endif diff --git a/src/klotski/ffi/tmain.cc b/src/klotski/ffi/tmain.cc index a400622..f90b38e 100644 --- a/src/klotski/ffi/tmain.cc +++ b/src/klotski/ffi/tmain.cc @@ -3,17 +3,17 @@ #include "core.h" -void _tmain() { -// std::cout << "test" << std::endl; +void tmain() { + std::cout << "tmain start" << std::endl; - uint64_t raw_code = 0x0603EDF5CAFFF5E2; +// uint64_t raw_code = 0x0603EDF5CAFFF5E2; - auto core = Core([](uint64_t code, uint64_t mask) { - return; - }); +// auto core = Core([](uint64_t code, uint64_t mask) { +// return; +// }); - for (uint32_t i = 0; i < 1000000; ++i) { - core.next_cases(raw_code, 0); - } +// for (uint32_t i = 0; i < 1000000; ++i) { +// core.next_cases(raw_code, 0); +// } } diff --git a/src/klotski/graph/CMakeLists.txt b/src/klotski/graph/CMakeLists.txt index 2678952..a12af74 100644 --- a/src/klotski/graph/CMakeLists.txt +++ b/src/klotski/graph/CMakeLists.txt @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.0) include_directories(svg) +# TODO: svg compile together add_subdirectory(svg) +# TODO: STATIC flag add_library(graph case.cc graph.cc) -target_link_libraries(graph analyse svg) +target_link_libraries(graph PUBLIC analyse svg) diff --git a/src/klotski/raw_code/CMakeLists.txt b/src/klotski/raw_code/CMakeLists.txt index 10f0b62..c850338 100644 --- a/src/klotski/raw_code/CMakeLists.txt +++ b/src/klotski/raw_code/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.0) -add_library(raw_code convert.cc raw_code.cc) -target_link_libraries(raw_code utils) +add_library(raw_code STATIC convert.cc raw_code.cc) +target_link_libraries(raw_code PUBLIC utils) diff --git a/src/klotski/short_code/CMakeLists.txt b/src/klotski/short_code/CMakeLists.txt index eb192d7..ad24a2d 100644 --- a/src/klotski/short_code/CMakeLists.txt +++ b/src/klotski/short_code/CMakeLists.txt @@ -2,5 +2,5 @@ cmake_minimum_required(VERSION 3.0) include_directories(offset) -add_library(short_code convert.cc serialize.cc short_code.cc) -target_link_libraries(short_code utils all_cases) +add_library(short_code STATIC convert.cc serialize.cc short_code.cc) +target_link_libraries(short_code PUBLIC utils all_cases) diff --git a/src/klotski/utils/CMakeLists.txt b/src/klotski/utils/CMakeLists.txt index 8686549..da9333e 100644 --- a/src/klotski/utils/CMakeLists.txt +++ b/src/klotski/utils/CMakeLists.txt @@ -1,3 +1,3 @@ cmake_minimum_required(VERSION 3.0) -add_library(utils common.cc) +add_library(utils STATIC common.cc) diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..0e89689 --- /dev/null +++ b/src/main.c @@ -0,0 +1,10 @@ +#include +#include "klotski.h" + +int main() { +// printf("interface test\n"); + + tmain(); + + return 0; +} diff --git a/src/main.cc b/src/main.cc deleted file mode 100644 index 1bf658c..0000000 --- a/src/main.cc +++ /dev/null @@ -1,197 +0,0 @@ -#include - -#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; -// } -// -// auto a = Analyse(RawCode::from_common_code("1a9bf0c")); -// for (const auto &s : a.build_resolve()) { -// 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(); - -// { -// auto fc = FastCal(RawCode::unsafe_create(0)); -// for (auto code : test_cases) { -// fc.set_root(code); -// fc.solve(); -// } -// } - - -// 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")); - - -// a.build(); -// auto ret = a.build_until([](uint64_t code) { -// return ((code >> (3 * 0xD)) & 0b111) == B_2x2; -// }); -// auto ret = a.build_resolve(); -// for (const auto &r : ret) { -// std::cout << r << std::endl; -// } -// 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; - - -// auto g = Graph(); -// auto svg_data = g.svg_demo(svg_ret); - -// std::cout << svg_data << std::endl; - - -// std::cout << a.layer_export(81).size() << std::endl; -// std::cout << a.layer_export()[81].size() << std::endl; - - -// std::vector raw_codes = { -// CommonCode(0xDAAF4CC00).to_raw_code().unwrap(), -// CommonCode(0xDAA7F3000).to_raw_code().unwrap(), -// }; -// a.backtrack(raw_codes); - -// std::vector raw_codes = { -// CommonCode("DE77D80").to_raw_code().unwrap(), -// CommonCode("DF6DD80").to_raw_code().unwrap(), -// CommonCode("DF69730").to_raw_code().unwrap(), -// CommonCode("DE76D30").to_raw_code().unwrap(), -// CommonCode("D5AF730").to_raw_code().unwrap(), -// CommonCode("D5B43BC").to_raw_code().unwrap(), -// }; -// std::vector raw_codes = { -// CommonCode("EF697C0").to_raw_code().unwrap(), -// }; - // 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/test/CMakeLists.txt b/test/CMakeLists.txt index 23e1bc2..7891023 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,14 +7,14 @@ enable_testing() ################################################################ include_directories(../third_party/md5) -add_library(md5 ../third_party/md5/md5.cpp) +add_library(md5 STATIC ../third_party/md5/md5.cpp) ################################################################ include_directories(../src/klotski/all_cases) add_executable(test_all_cases all_cases.cc) -target_link_libraries(test_all_cases gtest gtest_main) -target_link_libraries(test_all_cases md5 all_cases) +target_link_libraries(test_all_cases PUBLIC gtest gtest_main) +target_link_libraries(test_all_cases PUBLIC md5 all_cases) add_test(NAME all_cases COMMAND test_all_cases) ################################################################