Browse Source

feat: add `GROUP_ALL_CASES_SIZE`

legacy
Dnomd343 2 years ago
parent
commit
70f32b1827
  1. 39
      src/klotski_core/ffi/tmain.cc
  2. 1
      src/klotski_core/group/block_num.cc
  3. 4
      src/klotski_core/group/group.cc
  4. 34
      src/klotski_core/group/size.h
  5. 9
      test/group/group.cc

39
src/klotski_core/ffi/tmain.cc

@ -31,22 +31,39 @@ 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<uint64_t> codes;
// std::vector<uint64_t> 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<uint64_t> codes;
std::vector<uint64_t> 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<uint32_t> ret;
if (codes != codes_) {
std::cout << type_id << 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());
}
// std::cout << (codes == codes_) << std::endl;
for (uint32_t i = 0; i < ret.size(); ++i) {
printf("%06d, ", ret[i]);
if (i % 8 == 7) {
printf("\n");
}
}
// auto cases = std::vector<RawCode>();
// auto common_codes = AllCases::release();

1
src/klotski_core/group/block_num.cc

@ -70,4 +70,3 @@ Group::block_num_t Group::block_num(const CommonCode &common_code) {
}
} // namespace klotski

4
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<CommonCode> Group::all_cases(uint32_t type_id) {
}
std::vector<CommonCode> 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) {

34
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

9
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)
}

Loading…
Cancel
Save