From f521cf6f120abc972ae7cc524dc7640aeb8af1f8 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 26 Feb 2023 15:04:57 +0800 Subject: [PATCH] feat: RawCode vertical mirror fill --- src/klotski_core/ffi/tmain.cc | 6 ++++-- src/klotski_core/raw_code/mirror.cc | 29 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index 1fb430a..2e1d420 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -16,9 +16,11 @@ void tmain() { // klotski::RawCode::from_common_code(0x1A9BF0C00).is_horizontal_mirror(); // auto ret = klotski::RawCode::from_common_code(0x1A9BF0C00).to_horizontal_mirror(); - auto ret = klotski::RawCode::from_common_code(0x4FEA13400).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; +// std::cout << ret.to_common_code() << std::endl << ret << std::endl; + + klotski::RawCode::from_common_code(0x1A9BF0C00).is_vertical_mirror(); return; diff --git a/src/klotski_core/raw_code/mirror.cc b/src/klotski_core/raw_code/mirror.cc index e3162ae..35621b7 100644 --- a/src/klotski_core/raw_code/mirror.cc +++ b/src/klotski_core/raw_code/mirror.cc @@ -52,7 +52,28 @@ bool RawCode::is_horizontal_mirror(const RawCode &raw_code) const { 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) { +void vertical_fill(uint64_t &raw_code) { + uint64_t mask = 0; + for (int addr = 0; addr < 60; addr += 3) { + switch ((raw_code >> addr) & 0b111) { + case B_2x1: + case B_2x2: + mask |= (uint64_t)0b111 << (addr + 12); // generate fill mask + } + } + for (int addr = 0; addr < 60; addr += 3) { + switch ((raw_code | mask) >> addr & 0b111) { + case B_2x1: + raw_code &= ~(uint64_t(~B_2x1 & 0b111) << (addr + 12)); // fill vertical mirror + break; + case B_2x2: + raw_code &= ~(uint64_t(~B_2x2 & 0b111) << (addr + 12)); // fill vertical mirror + break; + } + } +} + +inline void horizontal_fill(uint64_t &raw_code) { for (int addr = 0; addr < 60; addr += 3) { // traverse every 3-bits switch ((raw_code >> addr) & 0b111) { case B_1x2: @@ -67,7 +88,7 @@ void horizontal_fill(uint64_t &raw_code) { } } -void horizontal_clear(uint64_t &raw_code) { +inline 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: @@ -96,6 +117,10 @@ bool RawCode::vertical_mirror_check(uint64_t raw_code) { // TODO: whether self vertical mirror + vertical_fill(raw_code); + + std::cout << RawCode::unsafe_create(raw_code) << std::endl; + return false; }