Browse Source

feat: obtain group toward character

legacy
Dnomd343 2 months ago
parent
commit
9e33a23b76
  1. 11
      src/core/group/group.h
  2. 45
      src/core/group/internal/group.inl
  3. 4
      src/core/group/internal/group_union.inl
  4. 54
      src/core/main.cc

11
src/core/group/group.h

@ -158,6 +158,10 @@ class Group {
public: public:
Group() = delete; Group() = delete;
// TODO: add stream output for debug
[[nodiscard]] constexpr std::string to_string() const;
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
enum class Toward { enum class Toward {
@ -180,16 +184,15 @@ public:
/// Get the mirror toward. /// Get the mirror toward.
[[nodiscard]] constexpr Toward toward() const; [[nodiscard]] constexpr Toward toward() const;
/// Get the toward character.
[[nodiscard]] constexpr char toward_char() const;
/// Get the original type id. /// Get the original type id.
[[nodiscard]] constexpr uint32_t type_id() const; [[nodiscard]] constexpr uint32_t type_id() const;
/// Get the original pattern id. /// Get the original pattern id.
[[nodiscard]] constexpr uint32_t pattern_id() const; [[nodiscard]] constexpr uint32_t pattern_id() const;
// TODO: add toward char interface
// TODO: add stream output for debug
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Create Group without any check. /// Create Group without any check.

45
src/core/group/internal/group.inl

@ -4,18 +4,57 @@
namespace klotski::cases { namespace klotski::cases {
[[nodiscard]] constexpr uint32_t Group::type_id() const { constexpr uint32_t Group::type_id() const {
return type_id_; return type_id_;
} }
[[nodiscard]] constexpr uint32_t Group::pattern_id() const { constexpr uint32_t Group::pattern_id() const {
return pattern_id_; return pattern_id_;
} }
[[nodiscard]] constexpr auto Group::toward() const -> Toward { constexpr auto Group::toward() const -> Toward {
return toward_; return toward_;
} }
constexpr char Group::toward_char() const {
// TODO: select chars from pre-build std::array
switch (mirror_type()) {
case MirrorType::Full:
return '\0';
case MirrorType::Horizontal:
return (toward_ == Toward::A) ? 'n' : 'u';
case MirrorType::Centro:
return (toward_ == Toward::A) ? '?' : '!'; // TODO: select chars for centro
case MirrorType::Vertical:
return (toward_ == Toward::A) ? 'p' : 'q';
case MirrorType::Ordinary:
if (toward_ == Toward::A) {
return 'a';
} else if (toward_ == Toward::B) {
return 'b';
} else if (toward_ == Toward::C) {
return 'c';
} else if (toward_ == Toward::D) {
return 'd';
}
return '\0'; // TODO: never reach
}
}
constexpr std::string Group::to_string() const { // TODO: `std::string` not support constexpr
auto c = toward_char();
if (c == '\0') {
return std::format("{}-{}", type_id_, pattern_id_);
}
return std::format("{}-{}{}", type_id_, pattern_id_, c);
}
constexpr auto operator==(const Group &lhs, const Group &rhs) {
return lhs.type_id_ == rhs.type_id_
&& lhs.pattern_id_ == rhs.pattern_id_
&& lhs.toward_ == rhs.toward_;
}
constexpr Group Group::unsafe_create(uint32_t type_id, uint32_t pattern_id, Toward toward) { constexpr Group Group::unsafe_create(uint32_t type_id, uint32_t pattern_id, Toward toward) {
return {type_id, pattern_id, toward}; return {type_id, pattern_id, toward};
} }

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

@ -53,6 +53,10 @@ constexpr uint32_t GroupUnion::max_group_size() const {
// return std::nullopt; // return std::nullopt;
//} //}
constexpr auto operator==(const GroupUnion &lhs, const GroupUnion &rhs) {
return lhs.type_id_ == rhs.type_id_;
}
// ----------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------- //
constexpr uint32_t GroupUnion::pattern_num() const { constexpr uint32_t GroupUnion::pattern_num() const {

54
src/core/main.cc

@ -59,32 +59,34 @@ int main() {
// std::cout << data_s.size() << std::endl; // std::cout << data_s.size() << std::endl;
// std::cout << data_c.size() << std::endl; // std::cout << data_c.size() << std::endl;
// auto group = Group::from_common_code(CommonCode::unsafe_create(0x1A9BF0C00)); auto group = Group::from_common_code(CommonCode::unsafe_create(0x1A9BF0C00));
// std::cout << group.type_id() << std::endl; std::cout << group.type_id() << std::endl;
// std::cout << group.pattern_id() << std::endl; std::cout << group.pattern_id() << std::endl;
// std::cout << (int)group.toward() << std::endl; std::cout << (int)group.toward() << std::endl;
std::cout << group.toward_char() << std::endl;
auto info_1 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00)); std::cout << group.to_string() << std::endl;
std::cout << std::format("{}-{}-{}-{}\n", info_1.group.type_id(), info_1.group.pattern_id(), (int)info_1.group.toward(), info_1.case_id);
auto code_1 = GroupCases::obtain_code(info_1); // auto info_1 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00));
std::cout << code_1 << std::endl; // std::cout << std::format("{}-{}-{}-{}\n", info_1.group.type_id(), info_1.group.pattern_id(), (int)info_1.group.toward(), info_1.case_id);
// auto code_1 = GroupCases::obtain_code(info_1);
auto info_2 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00).to_short_code()); // std::cout << code_1 << std::endl;
std::cout << std::format("{}-{}-{}-{}\n", info_2.group.type_id(), info_2.group.pattern_id(), (int)info_2.group.toward(), info_2.case_id); //
auto code_2 = GroupCases::obtain_code(info_2); // auto info_2 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00).to_short_code());
std::cout << code_2 << std::endl; // std::cout << std::format("{}-{}-{}-{}\n", info_2.group.type_id(), info_2.group.pattern_id(), (int)info_2.group.toward(), info_2.case_id);
// auto code_2 = GroupCases::obtain_code(info_2);
GroupCases::build(); // std::cout << code_2 << std::endl;
//
auto info_3 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00)); // GroupCases::build();
std::cout << std::format("{}-{}-{}-{}\n", info_3.group.type_id(), info_3.group.pattern_id(), (int)info_3.group.toward(), info_3.case_id); //
auto code_3 = GroupCases::obtain_code(info_3); // auto info_3 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00));
std::cout << code_3 << std::endl; // std::cout << std::format("{}-{}-{}-{}\n", info_3.group.type_id(), info_3.group.pattern_id(), (int)info_3.group.toward(), info_3.case_id);
// auto code_3 = GroupCases::obtain_code(info_3);
auto info_4 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00).to_short_code()); // std::cout << code_3 << std::endl;
std::cout << std::format("{}-{}-{}-{}\n", info_4.group.type_id(), info_4.group.pattern_id(), (int)info_4.group.toward(), info_4.case_id); //
auto code_4 = GroupCases::obtain_code(info_4); // auto info_4 = GroupCases::obtain_info(CommonCode::unsafe_create(0x1A9BF0C00).to_short_code());
std::cout << code_4 << std::endl; // std::cout << std::format("{}-{}-{}-{}\n", info_4.group.type_id(), info_4.group.pattern_id(), (int)info_4.group.toward(), info_4.case_id);
// auto code_4 = GroupCases::obtain_code(info_4);
// std::cout << code_4 << std::endl;
// const auto common_code = CommonCode::unsafe_create(0x1A9BF0C00); // const auto common_code = CommonCode::unsafe_create(0x1A9BF0C00);
// const auto group = Group::from_common_code(common_code); // const auto group = Group::from_common_code(common_code);

Loading…
Cancel
Save