From 21e3e29e22388528c002530874c1e0f422c9e02e Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 13 Apr 2023 19:50:23 +0800 Subject: [PATCH] feat: add `TYPE_ID_MAX_GROUP_SIZE` --- src/klotski_core/ffi/tmain.cc | 101 ++++--------------------------- src/klotski_core/group/group.h | 6 ++ src/klotski_core/group/type_id.h | 21 ++++++- 3 files changed, 37 insertions(+), 91 deletions(-) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index aa69fcf..1a4707b 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -33,101 +33,22 @@ using klotski::TYPE_ID_LIMIT; void tmain() { // printf("tmain start\n"); - - auto ret = Group::build_group(123, 0); - - std::cout << ret.size() << std::endl; - - std::cout << ret[0] << std::endl; - std::cout << ret[1] << std::endl; - std::cout << ret[2] << std::endl; - std::cout << ret[3] << std::endl; - - return; - -// struct group_info_t { -// uint16_t type_id; -// uint16_t group_id; -// uint32_t group_index; -// }; -// -// std::vector data; -// data.resize(klotski::SHORT_CODE_LIMIT); -// ShortCode::speed_up(ShortCode::FAST); -// -// for (uint16_t type_id = 0; type_id < klotski::TYPE_ID_LIMIT; ++type_id) { -// auto groups = Group::build_groups(type_id); -// for (uint32_t id = 0; id < groups.size(); ++id) { -// -// std::sort(groups[id].begin(), groups[id].end()); -// -// for (uint32_t index = 0; index < groups[id].size(); ++index) { -// data[groups[id][index].to_short_code().unwrap()] = { -// .type_id = type_id, -// .group_id = static_cast(id), -// .group_index = index, -// }; -// } -// } -// std::cerr << type_id << std::endl; -// } -// -// for (auto &&tmp : data) { -// std::cout << tmp.group_index << std::endl; -// } - -// std::vector group_num; -// for (uint16_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { -// group_num.emplace_back(Group::build_groups(type_id).size()); -// } -// for (auto &&tmp : group_num) { -// std::cout << tmp << std::endl; -// } - - std::vector group_id_index; - std::vector group_id_index_rev; - - for (uint16_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { - auto groups = Group::build_groups(type_id); - std::map seeds; - for (uint32_t group_id = 0; group_id < groups.size(); ++group_id) { - auto seed = *std::min_element(groups[group_id].begin(), groups[group_id].end()); - seeds.emplace(std::pair(seed, group_id)); - } - -// std::cout << seeds.size() << std::endl; - -// for (auto &&tmp: seeds) { -// std::cout << tmp.first << " -> " << tmp.second << std::endl; -// std::cout << tmp.first << std::endl; -// std::cout << tmp.second << std::endl; -// group_id_index.emplace_back(tmp.second); -// } - - uint32_t index = 0; - std::map seeds_index_rev; - for (auto &&tmp : seeds) { - seeds_index_rev[tmp.second] = index; - ++index; - } - - for (auto &&tmp : seeds_index_rev) { - group_id_index_rev.emplace_back(tmp.second); -// std::cout << tmp.first << " -> " << tmp.second << std::endl; - } - + std::vector max_group_size; + max_group_size.reserve(TYPE_ID_LIMIT); + for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { +// std::cout << Group::build_groups(type_id)[0].size() << std::endl; + max_group_size.emplace_back(Group::build_groups(type_id)[0].size()); std::cerr << type_id << std::endl; - } - printf(" "); - for (uint32_t i = 0; i < group_id_index_rev.size(); ++i) { - printf("%4d, ", group_id_index_rev[i]); - if (i % 16 == 15) { - printf("\n "); + for (uint32_t i = 0; i < max_group_size.size(); ++i) { + + printf("%6d, ", max_group_size[i]); + if (i % 12 == 11) { + printf("\n"); } + } - printf("\n"); // printf("tmain exit\n"); } diff --git a/src/klotski_core/group/group.h b/src/klotski_core/group/group.h index a540c8e..81bccff 100644 --- a/src/klotski_core/group/group.h +++ b/src/klotski_core/group/group.h @@ -41,6 +41,8 @@ public: /// Calculate all groups in the specified type_id. static std::vector> build_groups(uint32_t type_id); + // TODO: refactor build_group -> using GROUP_SEEDS + /// Calculate the specified group using type_id and group_id. static std::vector build_group(uint32_t type_id, uint32_t group_id); @@ -61,6 +63,8 @@ public: /// Get the CommonCode according to the group info. static CommonCode group_case(const group_info_t &group_info); + // TODO: group_size + /// -------------------------------- xxxxxxxxxxxxxxxxx -------------------------------- // TODO: update max_group_size in TYPE_ID_MAX_GROUP @@ -73,6 +77,8 @@ public: // static uint32_t max_group_size(const CommonCode &common_code); + // TODO: group_num + }; inline bool operator==(const Group::block_num_t &b1, const Group::block_num_t &b2) { diff --git a/src/klotski_core/group/type_id.h b/src/klotski_core/group/type_id.h index 1478e98..5c4848b 100644 --- a/src/klotski_core/group/type_id.h +++ b/src/klotski_core/group/type_id.h @@ -47,7 +47,26 @@ const uint32_t TYPE_ID_SIZE[203] = { 1036, 464, 342, }; -// TODO: TYPE_ID_MAX_GROUP_SIZE +const uint32_t TYPE_ID_MAX_GROUP_SIZE[203] = { + 12, 192, 1440, 6720, 21840, 52416, 96096, 137280, 154440, 137280, 96096, 52416, + 21840, 6720, 1440, 124, 1736, 11284, 45136, 124124, 248248, 372372, 425568, 372372, + 248248, 124124, 45136, 10836, 132, 1848, 12012, 48048, 132132, 264264, 396396, 453024, + 396396, 264264, 132132, 48048, 11916, 512, 6144, 33792, 112640, 253440, 405504, 473088, + 405504, 253440, 112576, 30104, 1044, 12528, 68904, 229680, 516780, 826848, 964656, 826848, + 516780, 228848, 65848, 582, 6984, 38412, 128040, 288090, 460944, 537768, 460944, 288090, + 128040, 37740, 1092, 10920, 49140, 131040, 229320, 275184, 229320, 130032, 38672, 3180, + 31800, 143100, 381600, 667800, 801360, 667544, 377408, 127676, 3382, 33820, 152190, 405840, + 710220, 852264, 709388, 403056, 143462, 1320, 13200, 59400, 158400, 277200, 332640, 277200, + 158272, 57524, 1320, 10560, 36960, 73920, 92400, 71944, 23704, 4680, 37440, 131040, + 262080, 327120, 253968, 105064, 7248, 57984, 202944, 405440, 504616, 396284, 175580, 5344, + 42752, 149632, 299136, 373184, 296520, 136040, 1632, 13056, 45696, 91392, 114240, 91264, + 43704, 948, 5688, 14220, 17696, 7888, 3444, 20664, 51044, 61204, 28832, 7048, + 42288, 104540, 132556, 81462, 7284, 42728, 104960, 135192, 81340, 4392, 26352, 65688, + 86968, 25955, 522, 3132, 7830, 10440, 7462, 396, 792, 508, 240, 768, + 742, 1804, 2348, 1398, 1504, 5372, 1192, 2984, 4376, 453, 350, 1380, + 1532, 45, 66, 38, 44, 5, 82, 21, 23, 24, 21, +}; + // TODO: TYPE_ID_GROUP_NUM } // namespace klotski