From 825abf8d7b657b9877c12282dfc92f2eaa190739 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 12 Jan 2023 15:24:25 +0800 Subject: [PATCH] remove: some legacy code --- include/case.h | 9 --- include/common.h | 9 --- src-legacy/case.cc | 131 ------------------------------------------ src-legacy/common.cc | 20 ------- src-legacy/klotski.cc | 55 ------------------ 5 files changed, 224 deletions(-) delete mode 100644 include/case.h delete mode 100644 include/common.h delete mode 100644 src-legacy/case.cc delete mode 100644 src-legacy/common.cc delete mode 100644 src-legacy/klotski.cc diff --git a/include/case.h b/include/case.h deleted file mode 100644 index 8c65854..0000000 --- a/include/case.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _CASE_H_ -#define _CASE_H_ - -#include -#include - -void find_all_case(std::vector *all_case); - -#endif diff --git a/include/common.h b/include/common.h deleted file mode 100644 index dfbca11..0000000 --- a/include/common.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _COMMON_H_ -#define _COMMON_H_ - -#include - -void binary_reverse(uint32_t &range); -void binary_to_str(uint64_t binary, char *string); - -#endif diff --git a/src-legacy/case.cc b/src-legacy/case.cc deleted file mode 100644 index c35f2e6..0000000 --- a/src-legacy/case.cc +++ /dev/null @@ -1,131 +0,0 @@ -#include "case.h" -#include "common.h" -#include - -bool check_case(int head, uint32_t range); -void build_base_range(std::vector &base_range); -void gen_range(std::vector &release, int n1, int n2, int n3, int n4); - -inline int binary_num(uint32_t binary, int length) { // get number of non-zero bit - int num = 0; - for (int i = 0; i < length; ++i) { - num += int((binary >> i) & 0x1); - } - return num; -} - -void find_all_case(std::vector *all_case) { - all_case->clear(); - std::vector base_range; - build_base_range(base_range); - for (int head = 0; head < 16; ++head) { // address for 2x2 block - if (head % 4 != 3) { - uint64_t prefix = int64_t(head) << 32; - for (auto range : base_range) { // combine 2x2 address and range - if (check_case(head, range)) { - binary_reverse(range); - all_case->emplace_back(prefix | range); - } - } - } - } -} - -void build_base_range(std::vector &base_range) { - for (int n = 0; n <= 7; ++n) { // number of 1x2 and 2x1 block -> 0 ~ (20 - 4 - 2) / 2 - for (int n_2x1 = 0; n_2x1 <= n; ++n_2x1) { // number of 1x2 block - for (int n_1x1 = 0; n_1x1 <= (14 - n * 2); ++n_1x1) { // number of 1x1 block - gen_range(base_range, (16 - n * 2 - n_1x1), (n - n_2x1), n_2x1, n_1x1); - } - } - } - for (auto &bin : base_range) { - binary_reverse(bin); - } - std::sort(base_range.begin(), base_range.end()); - for (auto &bin : base_range) { - binary_reverse(bin); - } -} - -void gen_range(std::vector &release, int n1, int n2, int n3, int n4) { - std::vector cache_1, cache_2; - - int length = n1 + n2; - for (uint32_t bin = 0; bin < (0x1 << length); ++bin) { - if (binary_num(bin, length) == n2) { // match binary with `n2` non-zero bit - uint32_t range = 0; - for (int i = 0; i < length; ++i) { // generate range base on binary value - (range <<= 2) |= ((bin >> i) & 0x1); - } - cache_1.emplace_back(range); // insert into cache level 1 - } - } - - length = n1 + n2 + n3; - for (uint32_t bin = 0; bin < (0x1 << length); ++bin) { - if (binary_num(bin, length) == n3) { // match binary with `n3` non-zero bit - for (auto base : cache_1) { // traverse cache level 1 - uint32_t range = 0; - for (int i = 0; i < length; ++i) { // generate range base on binary value - if ((bin >> i) & 1) { // non-zero bit - (range <<= 2) |= 0x2; - } else { // zero bit - (range <<= 2) |= (base & 0x3); - base >>= 2; - } - } - cache_2.emplace_back(range); // insert into cache level 2 - } - } - } - - length = n1 + n2 + n3 + n4; - for (uint32_t bin = 0; bin < (0x1 << length); ++bin) { - if (binary_num(bin, length) == n4) { // match binary with `n4` non-zero bit - for (auto base : cache_2) { // traverse cache level 2 - uint32_t range = 0; - for (int i = 0; i < length; ++i) { // generate range base on binary value - if ((bin >> i) & 1) { // non-zero bit - (range <<= 2) |= 0x3; - } else { // zero bit - (range <<= 2) |= (base & 0x3); - base >>= 2; - } - } - release.emplace_back(range); // insert into release - } - } - } -} - -bool check_case(int head, uint32_t range) { // whether case is valid - uint32_t status = 0x33 << head; - for (int addr = 0; range; range >>= 2) { - while (status >> addr & 0x1) { - ++addr; - } - switch (range & 0x3) { - case 0x0: // space - case 0x3: // 1x1 - if (addr > 19) { - return false; - } - status |= 0x1 << addr; - break; - case 0x1: // 1x2 - if (addr % 4 == 3 || addr > 18 || status >> (addr + 1) & 0x1) { - return false; - } - status |= 0x3 << addr; - break; - case 0x2: // 2x1 - if (addr > 15 || status >> (addr + 4) & 0x1) { - return false; - } - status |= 0x11 << addr; - break; - } - } - return true; -} diff --git a/src-legacy/common.cc b/src-legacy/common.cc deleted file mode 100644 index b30563c..0000000 --- a/src-legacy/common.cc +++ /dev/null @@ -1,20 +0,0 @@ -#include "common.h" - -void binary_reverse(uint32_t &range) { // reverse binary every 2 bits - range = ((range << 16) & 0xFFFF0000) | ((range >> 16) & 0x0000FFFF); - range = ((range << 8) & 0xFF00FF00) | ((range >> 8) & 0x00FF00FF); - range = ((range << 4) & 0xF0F0F0F0) | ((range >> 4) & 0x0F0F0F0F); - range = ((range << 2) & 0xCCCCCCCC) | ((range >> 2) & 0x33333333); -} - -void binary_to_str(uint64_t binary, char *string) { - for (int i = 0; i < 9; ++i, ++string) { // only read low 9 * 4 bits - *string = int8_t(binary >> (8 - i) * 4 & 0xF); - if (*string < 10) { - *string += 48; // 0 -> 48 - } else { - *string += 55; // A -> 65 - } - } - string[9] = 0x0; // string ending -} diff --git a/src-legacy/klotski.cc b/src-legacy/klotski.cc deleted file mode 100644 index 29f6746..0000000 --- a/src-legacy/klotski.cc +++ /dev/null @@ -1,55 +0,0 @@ -#include "common.h" -#include "klotski.h" - -uint64_t compact_code(uint64_t code) { - int block_num = 0; - uint64_t ret = 0; - uint32_t range = 0; - for (int addr = 0; code; ++addr, code >>= 3) { - switch (code & 0x7) { - case B_space: - range <<= 2; - break; - case B_1x2: - (range <<= 2) |= 0x1; - break; - case B_2x1: - (range <<= 2) |= 0x2; - break; - case B_1x1: - (range <<= 2) |= 0x3; - break; - case B_2x2: - ret |= uint64_t(addr) << 32; - default: - continue; - } - ++block_num; - } - return ret | range << (16 - block_num) * 2; -} - -uint64_t extract_code(uint64_t code) { - uint64_t ret = C_2x2 << (code >> 32) * 3; - auto range = uint32_t(code); - binary_reverse(range); - for (int addr = 0; range; range >>= 2) { - while (0x7 & ret >> addr) { - addr += 3; - } - switch (range & 0x3) { - case 0x1: - ret |= C_1x2 << addr; - break; - case 0x2: - ret |= C_2x1 << addr; - break; - case 0x3: - ret |= C_1x1 << addr; - break; - case 0x0: - addr += 3; - } - } - return ret; -}