diff --git a/src/klotski_core/core/core.h b/src/klotski_core/core/core.h index 4b770c6..e9529d0 100644 --- a/src/klotski_core/core/core.h +++ b/src/klotski_core/core/core.h @@ -1,5 +1,31 @@ #pragma once +/// The main purpose of klotski calculation is to obtain all the next steps in order to carry +/// out the BFS algorithm. The definition of the next step is the result of moving an arbitrary +/// block in the current layout for a limited number of times, and the resulting layout is +/// different from the original. + +/// Eg1: +/// % # # % % # # % % # # % % # # % % # # % % # # % % # # % % # # % % # # % +/// % # # % % # # % % # # % % # # % % # # % % # # % % # # % % # # % % # # % +/// @ $ $ @ ==> @ $ $ @ @ $ $ @ @ $ $ @ @ $ $ @ @ $ $ @ @ $ $ @ @ $ $ @ @ $ $ @ +/// @ & * @ @ * @ @ * @ @ & @ @ & @ @ & * @ @ & * @ @ & * @ @ & * @ +/// * & * & & * & & * * & * * & * & * & * & * & + +/// Eg2: +/// * @ & % * @ & % * @ & % * @ & % +/// # # $ % # # $ % # # $ % # # $ % +/// # # $ ^ ==> # # $ ^ # # $ ^ # # $ ^ +/// ~ ~ ^ ~ ~ ^ ~ ~ ^ @ ~ ~ ^ +/// @ % % @ % % @ % % % % + +/// In order to achieve the purpose of searching for the next step, we should find out the +/// sub-layout that can be derived from each block. Due to the limited steps of moving, with +/// the help of a sub-BFS search, the target can be obtained. It can be shown that this step +/// produces at most 15 derived layouts, so it can be stored and computed in a queue of length +/// 16. By performing such a search on each block in the layout, we can get all the next-step +/// layouts, which have a minimum of 0 and a maximum of 68. + #include #include #include diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index a6848b7..34e1b6d 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -1,30 +1,76 @@ #include - -//#include +#include +#include #include "klotski.h" -//#include "core.h" +#include "core.h" //#include "common.h" #include "benchmark.h" #include "all_cases.h" +#include "common_code.h" using namespace klotski; void tmain() { printf("tmain start\n"); - printf("%d\n", ALL_CASES_SIZE_SUM); +// printf("%d\n", ALL_CASES_SIZE_SUM); // std::cout << ALL_CASES_SIZE_SUM << std::endl; // uint64_t common_code = 0x1A9BC0C00; // klotski::Common::range_reverse(common_code); - printf("%f\n", Benchmark::basic_ranges(Benchmark::MS)); - printf("%f\n", Benchmark::all_cases(Benchmark::MS)); +// printf("%f\n", Benchmark::basic_ranges(Benchmark::MS)); +// printf("%f\n", Benchmark::all_cases(Benchmark::MS)); // std::cout << Benchmark::basic_ranges(Benchmark::MS) << std::endl; // std::cout << Benchmark::all_cases(Benchmark::MS) << std::endl; + + std::vector next; + + auto core = 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 : AllCases::fetch()[head]) { + + uint64_t raw_code = 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; + printf("tmain exit\n"); } diff --git a/src/main.c b/src/main.c index 2fdcb46..3d27c09 100644 --- a/src/main.c +++ b/src/main.c @@ -4,7 +4,7 @@ int main() { // printf("cli boot\n"); -// tmain(); + tmain(); return 0; // bool ret = common_code_check(0x1A9BF0C00);