From 5e9124d52341a6d5e0049a7370e16113eae22cd6 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 11 Apr 2023 13:59:12 +0800 Subject: [PATCH] feat: build groups --- src/klotski_core/ffi/tmain.cc | 6 +++ src/klotski_core/group/group.cc | 96 +++++++++++++++++++++++++++++++++ src/klotski_core/group/group.h | 2 + 3 files changed, 104 insertions(+) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index 4d89df2..4a895b5 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -2,6 +2,9 @@ #include #include +#include +#include + #include "klotski.h" #include "core.h" @@ -25,7 +28,10 @@ using klotski::BasicRanges; void tmain() { // printf("tmain start\n"); +// auto ret = Group::build_groups(0); +// std::cout << ret[0].size() << std::endl; + Group::build_groups(123); // printf("tmain exit\n"); } diff --git a/src/klotski_core/group/group.cc b/src/klotski_core/group/group.cc index e26ea33..eaa7e35 100644 --- a/src/klotski_core/group/group.cc +++ b/src/klotski_core/group/group.cc @@ -78,4 +78,100 @@ std::vector Group::group_cases(const RawCode &seed) { return result; } +std::vector> Group::build_groups(uint32_t type_id) { + auto all_cases = Group::all_cases(type_id); + if (all_cases.empty()) { // match type_id TODO: ??? (7-0-0) + return {}; + } + + std::vector> groups; + auto min = std::min_element(all_cases.begin(), all_cases.end()); + auto first_group = Group::group_cases(min->to_raw_code()); + groups.emplace_back(first_group.begin(), first_group.end()); + if (first_group.size() == all_cases.size()) { // only contains one group + +// std::vector rs(k.begin(), k.end()); +// std::vector rs; +// rs.reserve(k.size()); + +// for (auto &&rr : k) { +// +// std::cout << rr.to_common_code() << std::endl; + +// rs.emplace_back(rr.to_common_code()); +// } + +// std::sort(rs.begin(), rs.end()); +// +// for (auto &&rr : rs) { +// std::cout << rr << std::endl; +// } + +// std::cout << r[0] << std::endl; + +// std::cout << k[0].to_common_code() << std::endl; + +// return + + return groups; + } + + + // TODO: reuse first_group + + + + std::set cases(all_cases.begin(), all_cases.end()); + + for (auto &&tmp : groups[0]) { + +// auto c = tmp.to_common_code(); + + cases.erase(tmp); + +// current_group->emplace_back(c); + + } + + +// std::set cases; + +// uint32_t index = 0; +// for (auto &&tmp : all_cases) { +// if +// } + +// std::cout << cases.size() << std::endl; +// std::cout << all_cases.size() << std::endl; + + + while (!cases.empty()) { + auto ret = Group::group_cases(cases.begin()->to_raw_code()); + + groups.emplace_back(); + + auto current_group = groups.end() - 1; + + for (auto &&tmp : ret) { + + auto c = tmp.to_common_code(); + + cases.erase(c); + + current_group->emplace_back(c); + + } + + } + + std::stable_sort(groups.begin(), groups.end(), [](const std::vector &c1, const std::vector &c2) { + return c1.size() < c2.size(); + }); + + std::cout << groups.size() << std::endl; + + + return std::vector>(); +} + } // namespace klotski diff --git a/src/klotski_core/group/group.h b/src/klotski_core/group/group.h index 6273cb8..58ea821 100644 --- a/src/klotski_core/group/group.h +++ b/src/klotski_core/group/group.h @@ -36,6 +36,8 @@ public: static std::vector all_cases(uint32_t type_id); static std::vector group_cases(const RawCode &seed); + static std::vector> build_groups(uint32_t type_id); + }; inline bool operator==(const Group::block_num_t &b1, const Group::block_num_t &b2) {