From 9f978fcf6b0f866af7d48dfeee26338b6ac33bae Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 27 Jan 2023 01:43:49 +0800 Subject: [PATCH] update: common utils --- legacy/main-old.cc | 40 ------------------------------------- src/klotski/utils/common.cc | 13 ++++++------ src/klotski/utils/common.h | 4 ++++ 3 files changed, 10 insertions(+), 47 deletions(-) diff --git a/legacy/main-old.cc b/legacy/main-old.cc index 14a817c..93d475c 100644 --- a/legacy/main-old.cc +++ b/legacy/main-old.cc @@ -2,51 +2,11 @@ /* - uint64_t -> 0000 + [xxx] * 20 - - 2x2 2x1 1x2 1x1 - # # # # # # - # # # - - 00 01 02 03 - 04 05 06 07 - 08 09 10 11 - 12 13 14 15 - 16 17 18 19 - x1 (%4) => 0 1 2 3 x3 (%4) => 0 3 2 1 */ -/* -====================================================== - - 1x1 -> 011 000 000 000 -> 0000 0000 0011 -> 0x3 - - 1x2 -> 001 111 000 000 -> 0000 0011 1001 -> 0x39 - - 2x1 -> 010 000 000 000 -> 0000 0000 0010 -> 0x7002 - 111 000 000 000 -> 0000 0000 0111 - - 2x2 -> 100 111 000 000 -> 0000 0011 1100 -> 0x3F03C - 111 111 000 000 -> 0000 0011 1111 - -====================================================== - - 1x1 -> 111 000 000 000 -> 0000 0000 0111 -> 0x7 - - 1x2 -> 111 111 000 000 -> 0000 0011 1111 -> 0x3F - - 2x1 -> 111 000 000 000 -> 0000 0000 0111 -> 0x7007 - 111 000 000 000 -> 0000 0000 0111 - - 2x2 -> 111 111 000 000 -> 0000 0011 1111 -> 0x3F03F - 111 111 000 000 -> 0000 0011 1111 - -====================================================== -*/ - int main() { printf("Klotski engine\n"); diff --git a/src/klotski/utils/common.cc b/src/klotski/utils/common.cc index 25f780f..6c12042 100644 --- a/src/klotski/utils/common.cc +++ b/src/klotski/utils/common.cc @@ -7,7 +7,7 @@ uint32_t Common::range_reverse(uint32_t bin) { // reverse binary every 2-bits return ((bin << 2) & 0xCCCCCCCC) | ((bin >> 2) & 0x33333333); } -/// NOTE: don't check unknown ranges +/// WARN: don't check unknown data -> may cause infinite loop uint8_t Common::check_range(uint32_t head, uint32_t range) { // check generated range /// M_1x1 M_1x2 M_2x1 M_2x2 /// 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 @@ -18,25 +18,24 @@ uint8_t Common::check_range(uint32_t head, uint32_t range) { // check generated constexpr uint32_t M_2x1 = 0b10001; constexpr uint32_t M_2x2 = 0b110011; - int block_offset = 1; + uint8_t block_offset = 1; uint32_t cache = M_2x2 << head; // fill 2x2 block for (int addr = 0; range; range >>= 2, ++block_offset) { // traverse every 2-bits - // TODO: will addr >= 32 in some special cases? while ((cache >> addr) & 0b1) { ++addr; // search next unfilled block } switch (range & 0b11) { - case 0b00: // space - case 0b11: // 1x1 block + case 0b00: /// space + case 0b11: /// 1x1 block cache |= M_1x1 << addr; // fill space or 1x1 block break; - case 0b10: // 2x1 block + case 0b10: /// 2x1 block if (addr > 15 || cache >> (addr + 4) & 0b1) { // invalid address return block_offset; // broken block number } cache |= M_2x1 << addr; // fill 2x1 block break; - case 0b01: // 1x2 block + case 0b01: /// 1x2 block if ((addr & 0b11) == 0b11 || cache >> (addr + 1) & 0b1) { // invalid address return block_offset; // broken block number } diff --git a/src/klotski/utils/common.h b/src/klotski/utils/common.h index 2b641a2..5b4006d 100644 --- a/src/klotski/utils/common.h +++ b/src/klotski/utils/common.h @@ -9,6 +9,10 @@ /// /// 3. `2x2` block must have and only one, `2x1` `1x2` `1x1` are not required in number. /// +/// NOTE: 2x2 2x1 1x2 1x1 +/// # # # # # # +/// # # # +/// /// After statistics, there are a total of 29334498 cases that meet the above requirements. #include