Browse Source

feat: add `TYPE_ID_MAX_GROUP_SIZE`

legacy
Dnomd343 2 years ago
parent
commit
21e3e29e22
  1. 99
      src/klotski_core/ffi/tmain.cc
  2. 6
      src/klotski_core/group/group.h
  3. 21
      src/klotski_core/group/type_id.h

99
src/klotski_core/ffi/tmain.cc

@ -33,101 +33,22 @@ using klotski::TYPE_ID_LIMIT;
void tmain() { void tmain() {
// printf("tmain start\n"); // printf("tmain start\n");
std::vector<uint32_t> max_group_size;
auto ret = Group::build_group(123, 0); max_group_size.reserve(TYPE_ID_LIMIT);
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
std::cout << ret.size() << std::endl; // std::cout << Group::build_groups(type_id)[0].size() << std::endl;
max_group_size.emplace_back(Group::build_groups(type_id)[0].size());
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<group_info_t> 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<uint16_t>(id),
// .group_index = index,
// };
// }
// }
// std::cerr << type_id << std::endl;
// }
//
// for (auto &&tmp : data) {
// std::cout << tmp.group_index << std::endl;
// }
// std::vector<uint32_t> 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<uint32_t> group_id_index;
std::vector<uint32_t> 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<CommonCode, uint32_t> 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<CommonCode, uint32_t>(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<uint32_t, uint32_t> 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::cerr << type_id << std::endl; std::cerr << type_id << std::endl;
} }
printf(" "); for (uint32_t i = 0; i < max_group_size.size(); ++i) {
for (uint32_t i = 0; i < group_id_index_rev.size(); ++i) {
printf("%4d, ", group_id_index_rev[i]); printf("%6d, ", max_group_size[i]);
if (i % 16 == 15) { if (i % 12 == 11) {
printf("\n"); printf("\n");
} }
} }
printf("\n");
// printf("tmain exit\n"); // printf("tmain exit\n");
} }

6
src/klotski_core/group/group.h

@ -41,6 +41,8 @@ public:
/// Calculate all groups in the specified type_id. /// Calculate all groups in the specified type_id.
static std::vector<std::vector<CommonCode>> build_groups(uint32_t type_id); static std::vector<std::vector<CommonCode>> build_groups(uint32_t type_id);
// TODO: refactor build_group -> using GROUP_SEEDS
/// Calculate the specified group using type_id and group_id. /// Calculate the specified group using type_id and group_id.
static std::vector<CommonCode> build_group(uint32_t type_id, uint32_t group_id); static std::vector<CommonCode> build_group(uint32_t type_id, uint32_t group_id);
@ -61,6 +63,8 @@ public:
/// Get the CommonCode according to the group info. /// Get the CommonCode according to the group info.
static CommonCode group_case(const group_info_t &group_info); static CommonCode group_case(const group_info_t &group_info);
// TODO: group_size
/// -------------------------------- xxxxxxxxxxxxxxxxx -------------------------------- /// -------------------------------- xxxxxxxxxxxxxxxxx --------------------------------
// TODO: update max_group_size in TYPE_ID_MAX_GROUP // 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); // 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) { inline bool operator==(const Group::block_num_t &b1, const Group::block_num_t &b2) {

21
src/klotski_core/group/type_id.h

@ -47,7 +47,26 @@ const uint32_t TYPE_ID_SIZE[203] = {
1036, 464, 342, 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 // TODO: TYPE_ID_GROUP_NUM
} // namespace klotski } // namespace klotski

Loading…
Cancel
Save