Browse Source

feat: located group from RawCode

legacy
Dnomd343 2 months ago
parent
commit
9b640c925d
  1. 5
      src/core/group/group.h
  2. 3181
      src/core/group/internal/constant/group_pro.h
  3. 32
      src/core/group/internal/group_pro.cc
  4. 4
      src/core/group/internal/group_pro.inl
  5. 5
      src/core/main.cc

5
src/core/group/group.h

@ -196,7 +196,10 @@ public:
[[nodiscard]] constexpr GroupPro to_vertical_mirror() const;
[[nodiscard]] constexpr GroupPro to_horizontal_mirror() const;
RangesUnion cases() const;
[[nodiscard]] RangesUnion cases() const;
static GroupPro from_raw_code(codec::RawCode raw_code);
static GroupPro from_common_code(codec::CommonCode common_code);
private:
uint32_t type_id_;

3181
src/core/group/internal/constant/group_pro.h

File diff suppressed because one or more lines are too long

32
src/core/group/internal/group_pro.cc

@ -2,13 +2,14 @@
#include "group/group.h"
using klotski::cases::GroupPro;
using klotski::codec::RawCode;
using klotski::codec::CommonCode;
using klotski::cases::GroupPro;
using klotski::cases::RangesUnion;
using klotski::cases::GROUP_PRO_SEED;
using klotski::cases::GROUP_SEED_MAP;
RangesUnion GroupPro::cases() const {
auto seed = CommonCode::unsafe_create(GROUP_PRO_SEED[flat_id()]);
@ -36,3 +37,30 @@ RangesUnion GroupPro::cases() const {
}
return data;
}
static std::unordered_map<uint64_t, GroupPro> build_map_data() {
// NOTE: using CommonCode as map key
std::unordered_map<uint64_t, GroupPro> data;
data.reserve(GROUP_SEED_MAP.size());
for (auto raw : GROUP_SEED_MAP) {
uint32_t type_id = (raw >> 48) & 0b11111111;
uint32_t pattern_id = (raw >> 38) & 0b1111111111;
uint32_t toward = (raw >> 36) & 0b11;
auto seed = CommonCode::unsafe_create(raw & (uint64_t)0xFFFFFFFFF).unwrap();
auto group = GroupPro::unsafe_create(type_id, pattern_id, toward);
data.emplace(seed, group);
}
return data;
}
GroupPro GroupPro::from_raw_code(codec::RawCode raw_code) {
static auto map_data = build_map_data();
auto raw_codes = Group::extend(raw_code);
auto common_codes = raw_codes | std::views::transform([](const RawCode r) {
return r.to_common_code();
}) | std::ranges::to<std::vector>(); // TODO: search min_element directly
auto seed = std::min_element(common_codes.begin(), common_codes.end());
return map_data.at(seed->unwrap());
}

4
src/core/group/internal/group_pro.inl

@ -12,6 +12,10 @@ constexpr uint32_t GroupPro::size() const {
return GROUP_PRO_SIZE[flat_id()];
}
inline GroupPro GroupPro::from_common_code(codec::CommonCode common_code) {
return from_raw_code(common_code.to_raw_code());
}
constexpr GroupPro::MirrorType GroupPro::mirror_type() const {
switch (GROUP_PRO_TYPE[flat_id()]) {
case 0:

5
src/core/main.cc

@ -78,6 +78,11 @@ int main() {
auto g2 = g.to_horizontal_mirror();
std::cout << std::format("{}-{}-{}\n", g2.type_id(), g2.pattern_id(), g2.mirror_toward());
// auto common_code = CommonCode::unsafe_create(0x1A9BF0C00);
auto common_code = CommonCode::unsafe_create(0x4FEA13400);
auto kk = GroupPro::from_common_code(common_code);
std::cout << std::format("{}-{}-{}\n", kk.type_id(), kk.pattern_id(), kk.mirror_toward());
// auto gp = GroupPro::unsafe_create(169, 0, 0);
// std::cout << gp.size() << std::endl;
// std::cout << (int)gp.mirror_type() << std::endl;

Loading…
Cancel
Save