Browse Source

update: load group info

legacy
Dnomd343 2 years ago
parent
commit
57904b3801
  1. 38
      src/klotski_core/ffi/tmain.cc
  2. 16
      src/klotski_core/group/build_cases.cc
  3. 6
      src/klotski_core/group/group.h
  4. 30
      src/klotski_core/group/group_info.cc
  5. 54
      src/klotski_core/group/type_id.h

38
src/klotski_core/ffi/tmain.cc

@ -33,21 +33,29 @@ using klotski::TYPE_ID_LIMIT;
void tmain() {
// printf("tmain start\n");
std::vector<uint32_t> group_num;
group_num.reserve(TYPE_ID_LIMIT);
for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
group_num.emplace_back(Group::build_groups(type_id).size());
std::cerr << type_id << std::endl;
}
for (uint32_t i = 0; i < group_num.size(); ++i) {
printf("%4d, ", group_num[i]);
if (i % 16 == 15) {
printf("\n");
}
}
Group::group_info(CommonCode(0x1A9BF0C00));
// std::vector<uint32_t> group_num;
// group_num.reserve(TYPE_ID_LIMIT);
// for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
// group_num.emplace_back(Group::build_groups(type_id).size());
// std::cerr << type_id << std::endl;
// }
//
// uint32_t offset = 0;
// std::vector<uint32_t> group_offset;
// group_offset.reserve(TYPE_ID_LIMIT);
// for (auto &&tmp : group_num) {
// group_offset.emplace_back(offset);
// offset += tmp;
// }
//
// for (uint32_t i = 0; i < group_offset.size(); ++i) {
// printf("%5d, ", group_offset[i]);
// if (i % 12 == 11) {
// printf("\n");
// }
// }
// printf("tmain exit\n");
}

16
src/klotski_core/group/build_cases.cc

@ -43,12 +43,12 @@ std::vector<CommonCode> Group::all_cases(uint32_t type_id) {
return all_cases;
}
std::vector<RawCode> Group::group_cases(const RawCode &seed) {
std::vector<RawCode> Group::group_cases(const RawCode &raw_code) {
std::queue<uint64_t> cache;
absl::flat_hash_map<uint64_t, uint64_t> cases; // <code, mask>
cases.reserve(max_group_size(seed));
cases.emplace(seed.unwrap(), 0); // without mask
cache.emplace(seed.unwrap());
cases.reserve(max_group_size(raw_code));
cases.emplace(raw_code.unwrap(), 0); // without mask
cache.emplace(raw_code.unwrap());
auto core = Core(
[&cache, &cases](auto &&code, auto &&mask) { // callback function
@ -68,15 +68,15 @@ std::vector<RawCode> Group::group_cases(const RawCode &seed) {
auto result = std::vector<RawCode>();
result.reserve(cases.size());
for (auto &&raw_code : cases) { // export group cases
result.emplace_back(RawCode::unsafe_create(raw_code.first));
for (auto &&tmp : cases) { // export group cases
result.emplace_back(RawCode::unsafe_create(tmp.first));
}
return result;
}
// TODO: test this function
std::vector<RawCode> Group::group_cases(const CommonCode &seed) {
return group_cases(RawCode::from_common_code(seed));
std::vector<RawCode> Group::group_cases(const CommonCode &common_code) {
return group_cases(RawCode::from_common_code(common_code));
}
std::vector<CommonCode> Group::build_group(uint32_t type_id, uint32_t group_id) {

6
src/klotski_core/group/group.h

@ -35,8 +35,10 @@ public:
static std::vector<CommonCode> all_cases(uint32_t type_id);
/// Search for all derivatives that a case can produce.
static std::vector<RawCode> group_cases(const RawCode &seed);
static std::vector<RawCode> group_cases(const CommonCode &seed);
static std::vector<RawCode> group_cases(const RawCode &raw_code);
static std::vector<RawCode> group_cases(const CommonCode &common_code);
// TODO: group_seed
/// Calculate all groups in the specified type_id.
static std::vector<std::vector<CommonCode>> build_groups(uint32_t type_id);

30
src/klotski_core/group/group_info.cc

@ -1,4 +1,9 @@
#include <algorithm>
#include "group.h"
#include "type_id.h"
#include "group_seeds.h"
#include <iostream>
namespace klotski {
@ -11,6 +16,29 @@ Group::group_info_t Group::group_info(const RawCode &raw_code) {
Group::group_info_t Group::group_info(const CommonCode &common_code) {
auto type_id = Group::type_id(common_code);
std::cout << type_id << std::endl;
std::cout << "group num: " << TYPE_ID_GROUP_NUM[type_id] << std::endl;
std::cout << "offset: " << TYPE_ID_OFFSET[type_id] << std::endl;
uint32_t start = TYPE_ID_OFFSET[type_id];
uint32_t end = start + TYPE_ID_GROUP_NUM[type_id];
std::cout << "range: [" << start << ", " << end << ")" << std::endl;
auto group = Group::group_cases(common_code);
std::vector<CommonCode> g(group.begin(), group.end());
auto seed = std::min_element(g.begin(), g.end());
std::cout << "seed: " << *seed << std::endl;
auto t = std::lower_bound(GROUP_SEEDS + start, GROUP_SEEDS + end, seed->unwrap());
auto tmp_index = t - GROUP_SEEDS;
std::cout << "tmp index: " << tmp_index;
std::cout << " (" << CommonCode(GROUP_SEEDS[tmp_index]) << ")" << std::endl;
auto group_id = GROUP_SEEDS_INDEX_[tmp_index];
std::cout << "group id: " << group_id << std::endl;
// TODO: function body
return Group::group_info_t();
@ -18,6 +46,8 @@ Group::group_info_t Group::group_info(const CommonCode &common_code) {
CommonCode Group::group_case(const Group::group_info_t &group_info) {
// TODO: check group info
// TODO: function body
return CommonCode(0);

54
src/klotski_core/group/type_id.h

@ -18,6 +18,42 @@ const uint16_t TYPE_ID_INDEX[203] = {
1618, 1632, 1633, 1634, 1792, 1808, 1824, 1840, 1856, 1872, 1888,
};
const uint16_t TYPE_ID_GROUP_NUM[203] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 13, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1,
1, 1, 3, 79, 1, 1, 1, 1, 1, 1, 1, 1, 1, 21, 141, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 1, 1, 1, 1, 1, 1,
1, 17, 273, 1, 1, 1, 1, 1, 1, 9, 145, 841, 1, 1, 1, 1,
1, 1, 15, 97, 517, 1, 1, 1, 1, 1, 1, 1, 5, 91, 1, 1,
1, 1, 1, 59, 587, 1, 1, 1, 1, 21, 353, 1741, 1, 1, 1, 7,
81, 479, 2327, 1, 1, 1, 5, 33, 165, 1053, 1, 1, 1, 1, 1, 9,
157, 1, 1, 1, 57, 505, 1, 1, 13, 325, 1729, 3, 9, 99, 631, 2609,
1, 17, 91, 487, 2653, 1, 1, 11, 75, 898, 2, 2, 2, 2, 80, 1,
2, 138, 14, 126, 590, 22, 183, 1074, 33, 209, 1178, 13, 171, 1185, 6, 16,
214, 6, 18, 54, 2, 44, 40, 124, 84, 70, 18,
};
const uint16_t TYPE_ID_OFFSET[203] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 69, 148, 149, 150, 151, 152, 153, 154, 155,
156, 157, 178, 319, 320, 321, 322, 323, 324, 325, 326, 327,
328, 329, 346, 347, 348, 349, 350, 351, 352, 353, 370, 643,
644, 645, 646, 647, 648, 649, 658, 803, 1644, 1645, 1646, 1647,
1648, 1649, 1650, 1665, 1762, 2279, 2280, 2281, 2282, 2283, 2284, 2285,
2286, 2291, 2382, 2383, 2384, 2385, 2386, 2387, 2446, 3033, 3034, 3035,
3036, 3037, 3058, 3411, 5152, 5153, 5154, 5155, 5162, 5243, 5722, 8049,
8050, 8051, 8052, 8057, 8090, 8255, 9308, 9309, 9310, 9311, 9312, 9313,
9322, 9479, 9480, 9481, 9482, 9539, 10044, 10045, 10046, 10059, 10384, 12113,
12116, 12125, 12224, 12855, 15464, 15465, 15482, 15573, 16060, 18713, 18714, 18715,
18726, 18801, 19699, 19701, 19703, 19705, 19707, 19787, 19788, 19790, 19928, 19942,
20068, 20658, 20680, 20863, 21937, 21970, 22179, 23357, 23370, 23541, 24726, 24732,
24748, 24962, 24968, 24986, 25040, 25042, 25086, 25126, 25250, 25334, 25404,
};
const uint32_t TYPE_ID_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,
@ -38,7 +74,7 @@ const uint32_t TYPE_ID_SIZE[203] = {
11016, 270, 1080, 1620, 88, 180, 626, 772, 1036, 464, 342,
};
const uint32_t TYPE_ID_MAX_GROUP_SIZE[203] = {
const uint32_t TYPE_ID_GROUP_MAX_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,
@ -58,20 +94,4 @@ const uint32_t TYPE_ID_MAX_GROUP_SIZE[203] = {
1532, 45, 66, 38, 44, 5, 82, 21, 23, 24, 21,
};
const uint16_t TYPE_ID_GROUP_NUM[203] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 13, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1,
1, 1, 3, 79, 1, 1, 1, 1, 1, 1, 1, 1, 1, 21, 141, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 1, 1, 1, 1, 1, 1,
1, 17, 273, 1, 1, 1, 1, 1, 1, 9, 145, 841, 1, 1, 1, 1,
1, 1, 15, 97, 517, 1, 1, 1, 1, 1, 1, 1, 5, 91, 1, 1,
1, 1, 1, 59, 587, 1, 1, 1, 1, 21, 353, 1741, 1, 1, 1, 7,
81, 479, 2327, 1, 1, 1, 5, 33, 165, 1053, 1, 1, 1, 1, 1, 9,
157, 1, 1, 1, 57, 505, 1, 1, 13, 325, 1729, 3, 9, 99, 631, 2609,
1, 17, 91, 487, 2653, 1, 1, 11, 75, 898, 2, 2, 2, 2, 80, 1,
2, 138, 14, 126, 590, 22, 183, 1074, 33, 209, 1178, 13, 171, 1185, 6, 16,
214, 6, 18, 54, 2, 44, 40, 124, 84, 70, 18,
};
} // namespace klotski

Loading…
Cancel
Save