Browse Source

feat: enhance group seeds

legacy
Dnomd343 2 years ago
parent
commit
066f23f410
  1. 7
      src/klotski_core/ffi/tmain.cc
  2. 2
      src/klotski_core/group/CMakeLists.txt
  3. 50
      src/klotski_core/group/build_cases.cc
  4. 12
      src/klotski_core/group/group.h
  5. 2
      src/klotski_core/group/group_info.cc
  6. 3184
      src/klotski_core/group/group_seeds.h
  7. 34
      src/klotski_core/group/seeds.cc
  8. 1589
      src/klotski_core/group/static/group_seeds_index.inc
  9. 1589
      src/klotski_core/group/static/group_seeds_index_rev.inc

7
src/klotski_core/ffi/tmain.cc

@ -33,7 +33,12 @@ using klotski::TYPE_ID_LIMIT;
void tmain() { void tmain() {
// printf("tmain start\n"); // printf("tmain start\n");
Group::group_info(CommonCode(0x1A9BF0C00)); // Group::build_group(123, 233);
auto seed = Group::group_seed(123, 233);
std::cout << seed << std::endl;
// Group::group_info(CommonCode(0x1A9BF0C00));
// std::vector<uint32_t> group_num; // std::vector<uint32_t> group_num;
// group_num.reserve(TYPE_ID_LIMIT); // group_num.reserve(TYPE_ID_LIMIT);

2
src/klotski_core/group/CMakeLists.txt

@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
add_library(group OBJECT group.cc block_num.cc build_cases.cc group_info.cc) add_library(group OBJECT seeds.cc group.cc block_num.cc build_cases.cc group_info.cc)

50
src/klotski_core/group/build_cases.cc

@ -6,6 +6,9 @@
#include "common_code.h" #include "common_code.h"
#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_map.h"
#include "type_id.h"
#include "group_seeds.h"
namespace klotski { namespace klotski {
using Common::check_range; using Common::check_range;
@ -79,21 +82,42 @@ std::vector<RawCode> Group::group_cases(const CommonCode &common_code) {
return group_cases(RawCode::from_common_code(common_code)); return group_cases(RawCode::from_common_code(common_code));
} }
// TODO: refactor build_group -> using GROUP_SEEDS
std::vector<CommonCode> Group::build_group(uint32_t type_id, uint32_t group_id) { std::vector<CommonCode> Group::build_group(uint32_t type_id, uint32_t group_id) {
uint32_t group_num = 0;
auto all_cases = Group::all_cases(type_id); // load all cases of type_id
std::set<CommonCode> cases(all_cases.begin(), all_cases.end());
while (!cases.empty()) { auto offset = TYPE_ID_OFFSET[type_id];
if (group_id == group_num) { // found target group
auto group = group_cases(cases.begin()->to_raw_code()); std::cout << "size: " << TYPE_ID_GROUP_NUM[type_id] << std::endl;
return {group.begin(), group.end()};
} auto k = GROUP_SEEDS_INDEX[offset + group_id];
for (auto &&tmp : group_cases(cases.begin()->to_raw_code())) {
cases.erase(tmp.to_common_code()); // remove from global union std::cout << "tmp index: " << k << std::endl;
}
++group_num; auto r = k + offset;
}
std::cout << "real index: " << r << std::endl;
auto seed = CommonCode(GROUP_SEEDS[r]);
std::cout << "seed: " << seed << std::endl;
std::cout << RawCode(seed) << std::endl;
// uint32_t group_num = 0;
// auto all_cases = Group::all_cases(type_id); // load all cases of type_id
// std::set<CommonCode> cases(all_cases.begin(), all_cases.end());
//
// while (!cases.empty()) {
// if (group_id == group_num) { // found target group
// auto group = group_cases(cases.begin()->to_raw_code());
// return {group.begin(), group.end()};
// }
// for (auto &&tmp : group_cases(cases.begin()->to_raw_code())) {
// cases.erase(tmp.to_common_code()); // remove from global union
// }
// ++group_num;
// }
return {}; // group_id out of range return {}; // group_id out of range
} }

12
src/klotski_core/group/group.h

@ -29,6 +29,14 @@ public:
static block_num_t block_num(const RawCode &raw_code); static block_num_t block_num(const RawCode &raw_code);
static block_num_t block_num(const CommonCode &common_code); static block_num_t block_num(const CommonCode &common_code);
/// --------------------------------- cases expansion ---------------------------------
static CommonCode group_seed(const RawCode &raw_code);
static CommonCode group_seed(const CommonCode &common_code);
static CommonCode group_seed(uint32_t type_id, uint32_t group_id);
static std::vector<CommonCode> group_seeds(uint32_t type_id);
/// --------------------------------- cases expansion --------------------------------- /// --------------------------------- cases expansion ---------------------------------
/// Search for all cases of the specified type_id. /// Search for all cases of the specified type_id.
@ -38,13 +46,9 @@ public:
static std::vector<RawCode> group_cases(const RawCode &raw_code); static std::vector<RawCode> group_cases(const RawCode &raw_code);
static std::vector<RawCode> group_cases(const CommonCode &common_code); static std::vector<RawCode> group_cases(const CommonCode &common_code);
// TODO: group_seed
/// 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);

2
src/klotski_core/group/group_info.cc

@ -36,7 +36,7 @@ Group::group_info_t Group::group_info(const CommonCode &common_code) {
std::cout << "tmp index: " << tmp_index; std::cout << "tmp index: " << tmp_index;
std::cout << " (" << CommonCode(GROUP_SEEDS[tmp_index]) << ")" << std::endl; std::cout << " (" << CommonCode(GROUP_SEEDS[tmp_index]) << ")" << std::endl;
auto group_id = GROUP_SEEDS_INDEX_[tmp_index]; auto group_id = GROUP_SEEDS_INDEX_REV[tmp_index];
std::cout << "group id: " << group_id << std::endl; std::cout << "group id: " << group_id << std::endl;
// TODO: function body // TODO: function body

3184
src/klotski_core/group/group_seeds.h

File diff suppressed because it is too large

34
src/klotski_core/group/seeds.cc

@ -0,0 +1,34 @@
#include "group.h"
#include "type_id.h"
#include "group_seeds.h"
#include <iostream>
namespace klotski {
CommonCode Group::group_seed(uint32_t type_id, uint32_t group_id) {
// TODO: check value
auto offset = TYPE_ID_OFFSET[type_id];
std::cout << "size: " << TYPE_ID_GROUP_NUM[type_id] << std::endl;
auto k = GROUP_SEEDS_INDEX[offset + group_id];
std::cout << "tmp index: " << k << std::endl;
auto r = k + offset;
std::cout << "real index: " << r << std::endl;
auto seed = CommonCode(GROUP_SEEDS[r]);
std::cout << "seed: " << seed << std::endl;
std::cout << RawCode(seed) << std::endl;
return seed;
}
} // namespace klotski

1589
src/klotski_core/group/static/group_seeds_index.inc

File diff suppressed because it is too large

1589
src/klotski_core/group/static/group_seeds_index_rev.inc

File diff suppressed because it is too large
Loading…
Cancel
Save