From 70f32b1827402971ced26e901fef3fb6dc6cb2d4 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 10 Apr 2023 16:01:12 +0800 Subject: [PATCH] feat: add `GROUP_ALL_CASES_SIZE` --- src/klotski_core/ffi/tmain.cc | 41 ++++++++++++++++++++--------- src/klotski_core/group/block_num.cc | 1 - src/klotski_core/group/group.cc | 4 ++- src/klotski_core/group/size.h | 34 ++++++++++++++++++++++++ test/group/group.cc | 9 +++++++ 5 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 src/klotski_core/group/size.h diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index bc349fe..ad21b0f 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -31,23 +31,40 @@ void tmain() { // } // std::cout << "sum = " << sum << std::endl; - for (uint32_t type_id = 0; type_id < 204; ++type_id) { +// 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 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()); + std::vector ret; - if (codes != codes_) { - std::cout << type_id << std::endl; - } -// std::cout << (codes == codes_) << std::endl; + 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) { diff --git a/src/klotski_core/group/block_num.cc b/src/klotski_core/group/block_num.cc index 140c384..0ff4796 100644 --- a/src/klotski_core/group/block_num.cc +++ b/src/klotski_core/group/block_num.cc @@ -70,4 +70,3 @@ Group::block_num_t Group::block_num(const CommonCode &common_code) { } } // namespace klotski - diff --git a/src/klotski_core/group/group.cc b/src/klotski_core/group/group.cc index e316f1f..e26ea33 100644 --- a/src/klotski_core/group/group.cc +++ b/src/klotski_core/group/group.cc @@ -5,6 +5,8 @@ #include "absl/container/flat_hash_map.h" #include "common.h" +#include "size.h" + namespace klotski { using klotski::AllCases; @@ -27,7 +29,7 @@ std::vector Group::all_cases(uint32_t type_id) { } std::vector all_cases; - // TODO: all_cases pre-allocated + all_cases.reserve(GROUP_ALL_CASES_SIZE[type_id]); for (uint64_t head = 0; head < 15; ++head) { // address of 2x2 block /// head -> 0/1/2 / 4/5/6 / 8/9/10 / 12/13/14 if ((head & 0b11) == 0b11) { diff --git a/src/klotski_core/group/size.h b/src/klotski_core/group/size.h new file mode 100644 index 0000000..152c6da --- /dev/null +++ b/src/klotski_core/group/size.h @@ -0,0 +1,34 @@ +#pragma once + +namespace klotski { + +const uint32_t GROUP_ALL_CASES_SIZE[204] = { + 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, 11284, 132, 1848, 12012, 48048, + 132132, 264264, 396396, 453024, 396396, 264264, 132132, 48048, + 12012, 512, 6144, 33792, 112640, 253440, 405504, 473088, + 405504, 253440, 112640, 33792, 1044, 12528, 68904, 229680, + 516780, 826848, 964656, 826848, 516780, 229680, 68904, 582, + 6984, 38412, 128040, 288090, 460944, 537768, 460944, 288090, + 128040, 38412, 1092, 10920, 49140, 131040, 229320, 275184, + 229320, 131040, 49140, 3180, 31800, 143100, 381600, 667800, + 801360, 667800, 381600, 143100, 3382, 33820, 152190, 405840, + 710220, 852264, 710220, 405840, 152190, 1320, 13200, 59400, + 158400, 277200, 332640, 277200, 158400, 59400, 1320, 10560, + 36960, 73920, 92400, 73920, 36960, 4680, 37440, 131040, + 262080, 327600, 262080, 131040, 7248, 57984, 202944, 405888, + 507360, 405888, 202944, 5344, 42752, 149632, 299264, 374080, + 299264, 149632, 1632, 13056, 45696, 91392, 114240, 91392, + 45696, 948, 5688, 14220, 18960, 14220, 3444, 20664, + 51660, 68880, 51660, 7120, 42720, 106800, 142400, 106800, + 7284, 43704, 109260, 145680, 109260, 4392, 26352, 65880, + 87840, 65880, 1044, 6264, 15660, 20880, 15660, 396, + 1584, 2376, 1260, 5040, 7560, 3084, 12336, 18504, + 4288, 17152, 25728, 3196, 12784, 19176, 1836, 7344, + 11016, 270, 1080, 1620, 88, 180, 626, 772, + 1036, 464, 342, 0, +}; + +} // namespace klotski diff --git a/test/group/group.cc b/test/group/group.cc index 16adb10..e82bed7 100644 --- a/test/group/group.cc +++ b/test/group/group.cc @@ -60,3 +60,12 @@ TEST(Group, block_num) { auto block_num_md5 = md5(block_num_data.c_str(), block_num_data.size()); EXPECT_STREQ(block_num_md5.c_str(), BLOCK_NUM_MD5); } + +TEST(Group, all_cases) { + + // TODO: all_cases number + // TODO: combine test + // TODO: data order + // TODO: test every cases (type_id) + +}