Browse Source

feat: add diagonal mirror of RawCode

master
Dnomd343 5 days ago
parent
commit
2b358e9b05
  1. 7
      src/core/raw_code/internal/mirror.inl
  2. 4
      src/core/raw_code/internal/raw_code.inl
  3. 6
      src/core/raw_code/raw_code.h

7
src/core/raw_code/internal/mirror.inl

@ -2,8 +2,6 @@
namespace klotski::codec { namespace klotski::codec {
// TODO: add `diagonal_mirror` support
constexpr uint64_t RawCode::get_vertical_mirror(const uint64_t raw_code) { constexpr uint64_t RawCode::get_vertical_mirror(const uint64_t raw_code) {
uint64_t code = ((raw_code >> 36) & 0x000'000'000'fff'fff) | ((raw_code << 36) & 0xfff'fff'000'000'000); uint64_t code = ((raw_code >> 36) & 0x000'000'000'fff'fff) | ((raw_code << 36) & 0xfff'fff'000'000'000);
code = ((code >> 12) & 0x000'fff'000'000'fff) | ((code << 12) & 0xfff'000'000'fff'000); code = ((code >> 12) & 0x000'fff'000'000'fff) | ((code << 12) & 0xfff'000'000'fff'000);
@ -25,6 +23,11 @@ constexpr uint64_t RawCode::get_horizontal_mirror(const uint64_t raw_code) {
return (code | m1 | m2) & ~(m1 >> 3) & ~(m2 >> 3); return (code | m1 | m2) & ~(m1 >> 3) & ~(m2 >> 3);
} }
constexpr uint64_t RawCode::get_diagonal_mirror(const uint64_t raw_code) {
// TODO: perf it
return get_horizontal_mirror(get_vertical_mirror(raw_code));
}
constexpr bool RawCode::check_mirror(const uint64_t raw_code) { constexpr bool RawCode::check_mirror(const uint64_t raw_code) {
const uint64_t m1 = ~raw_code & (raw_code << 1) & 0x492'492'492'492'492; const uint64_t m1 = ~raw_code & (raw_code << 1) & 0x492'492'492'492'492;
const uint64_t m2 = raw_code & 0x924'924'924'924'924; const uint64_t m2 = raw_code & 0x924'924'924'924'924;

4
src/core/raw_code/internal/raw_code.inl

@ -67,6 +67,10 @@ constexpr bool RawCode::is_horizontal_mirror() const {
return check_mirror(code_); return check_mirror(code_);
} }
constexpr RawCode RawCode::to_diagonal_mirror() const {
return unsafe_create(get_diagonal_mirror(code_));
}
constexpr RawCode RawCode::to_vertical_mirror() const { constexpr RawCode RawCode::to_vertical_mirror() const {
return unsafe_create(get_vertical_mirror(code_)); return unsafe_create(get_vertical_mirror(code_));
} }

6
src/core/raw_code/raw_code.h

@ -127,6 +127,9 @@ public:
/// Whether the layout is horizontally symmetrical. /// Whether the layout is horizontally symmetrical.
[[nodiscard]] constexpr bool is_horizontal_mirror() const; [[nodiscard]] constexpr bool is_horizontal_mirror() const;
/// Calculate the diagonally symmetrical klotski layout.
[[nodiscard]] constexpr RawCode to_diagonal_mirror() const;
/// Calculate the vertically symmetrical klotski layout. /// Calculate the vertically symmetrical klotski layout.
[[nodiscard]] constexpr RawCode to_vertical_mirror() const; [[nodiscard]] constexpr RawCode to_vertical_mirror() const;
@ -161,6 +164,9 @@ private:
/// Check the horizontally symmetrical. /// Check the horizontally symmetrical.
static constexpr bool check_mirror(uint64_t raw_code); static constexpr bool check_mirror(uint64_t raw_code);
/// Get the diagonally symmetrical layout.
static constexpr uint64_t get_diagonal_mirror(uint64_t raw_code);
/// Get the vertically symmetrical layout. /// Get the vertically symmetrical layout.
static constexpr uint64_t get_vertical_mirror(uint64_t raw_code); static constexpr uint64_t get_vertical_mirror(uint64_t raw_code);

Loading…
Cancel
Save