From da8d0947f47c20a5b2f0d5ad4ebc48255a88fca8 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 26 Feb 2023 13:43:17 +0800 Subject: [PATCH] update: complete horizontal mirror --- src/klotski_core/ffi/tmain.cc | 5 +++- src/klotski_core/raw_code/mirror.cc | 43 ++++++++++------------------- 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index 9790602..1fb430a 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -15,7 +15,10 @@ void tmain() { printf("tmain start\n"); // klotski::RawCode::from_common_code(0x1A9BF0C00).is_horizontal_mirror(); - klotski::RawCode::from_common_code(0x1A9BF0C00).to_horizontal_mirror(); +// auto ret = klotski::RawCode::from_common_code(0x1A9BF0C00).to_horizontal_mirror(); + auto ret = klotski::RawCode::from_common_code(0x4FEA13400).to_horizontal_mirror(); + + std::cout << ret.to_common_code() << std::endl << ret << std::endl; return; diff --git a/src/klotski_core/raw_code/mirror.cc b/src/klotski_core/raw_code/mirror.cc index 64eb28f..d187349 100644 --- a/src/klotski_core/raw_code/mirror.cc +++ b/src/klotski_core/raw_code/mirror.cc @@ -43,6 +43,15 @@ bool RawCode::is_horizontal_mirror(const RawCode &raw_code) const { #include +/// MASK_MIRROR_A | MASK_MIRROR_B +/// 111 000 000 000 | 000 111 000 000 +/// 111 000 000 000 | 000 111 000 000 +/// 111 000 000 000 | 000 111 000 000 +/// 111 000 000 000 | 000 111 000 000 +/// 111 000 000 000 | 000 111 000 000 +constexpr uint64_t MASK_MIRROR_A = 0x0'007'007'007'007'007; +constexpr uint64_t MASK_MIRROR_B = 0x0'038'038'038'038'038; + void horizontal_fill(uint64_t &raw_code) { for (int addr = 0; addr < 60; addr += 3) { // traverse every 3-bits switch ((raw_code >> addr) & 0b111) { @@ -59,17 +68,13 @@ void horizontal_fill(uint64_t &raw_code) { } void horizontal_clear(uint64_t &raw_code) { - for (int addr = 0; addr < 60; addr += 3) { // traverse every 3-bits - switch ((raw_code >> addr) & 0b111) { case B_1x2: case B_2x2: - raw_code |= (uint64_t)0b111 << (addr + 3); + raw_code |= (uint64_t)0b111 << (addr + 3); // reset as original block } - } - } uint64_t RawCode::vertical_mirror(uint64_t raw_code) { @@ -80,19 +85,10 @@ uint64_t RawCode::vertical_mirror(uint64_t raw_code) { } uint64_t RawCode::horizontal_mirror(uint64_t raw_code) { - - // TODO: horizontal mirror convert - - // fill -> mirror -> unfill - horizontal_fill(raw_code); - - // flip raw code - + raw_code = ((raw_code >> 9) & MASK_MIRROR_A) | ((raw_code >> 3) & MASK_MIRROR_B) + | ((raw_code & MASK_MIRROR_B) << 3) | ((raw_code & MASK_MIRROR_A) << 9); // flip raw code horizontal_clear(raw_code); - - std::cout << RawCode::unsafe_create(raw_code) << std::endl; - return raw_code; } @@ -103,19 +99,8 @@ bool RawCode::vertical_mirror_check(uint64_t raw_code) { return false; } - - - bool RawCode::horizontal_mirror_check(uint64_t raw_code) { - /// MASK_A MASK_B - /// 111 000 000 000 | 000 111 000 000 - /// 111 000 000 000 | 000 111 000 000 - /// 111 000 000 000 | 000 111 000 000 - /// 111 000 000 000 | 000 111 000 000 - /// 111 000 000 000 | 000 111 000 000 - constexpr uint64_t MASK_A = 0x0'007'007'007'007'007; - constexpr uint64_t MASK_B = 0x0'038'038'038'038'038; - horizontal_fill(raw_code); - return ((raw_code >> 9 ^ raw_code) & MASK_A) && ((raw_code >> 3 ^ raw_code) & MASK_B); + return ((raw_code ^ (raw_code >> 9)) & MASK_MIRROR_A) + && ((raw_code ^ (raw_code >> 3)) & MASK_MIRROR_B); }