Browse Source

feat: RawCode vertical mirror fill

legacy
Dnomd343 2 years ago
parent
commit
f521cf6f12
  1. 6
      src/klotski_core/ffi/tmain.cc
  2. 29
      src/klotski_core/raw_code/mirror.cc

6
src/klotski_core/ffi/tmain.cc

@ -16,9 +16,11 @@ void tmain() {
// klotski::RawCode::from_common_code(0x1A9BF0C00).is_horizontal_mirror(); // 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(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; return;

29
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_A = 0x0'007'007'007'007'007;
constexpr uint64_t MASK_MIRROR_B = 0x0'038'038'038'038'038; 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 for (int addr = 0; addr < 60; addr += 3) { // traverse every 3-bits
switch ((raw_code >> addr) & 0b111) { switch ((raw_code >> addr) & 0b111) {
case B_1x2: 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 for (int addr = 0; addr < 60; addr += 3) { // traverse every 3-bits
switch ((raw_code >> addr) & 0b111) { switch ((raw_code >> addr) & 0b111) {
case B_1x2: case B_1x2:
@ -96,6 +117,10 @@ bool RawCode::vertical_mirror_check(uint64_t raw_code) {
// TODO: whether self vertical mirror // TODO: whether self vertical mirror
vertical_fill(raw_code);
std::cout << RawCode::unsafe_create(raw_code) << std::endl;
return false; return false;
} }

Loading…
Cancel
Save