diff --git a/src/core_demo.cc b/src/core_demo.cc index 5cd4858..33d996d 100644 --- a/src/core_demo.cc +++ b/src/core_demo.cc @@ -2,6 +2,9 @@ #include "raw_code.h" #include "core_demo.h" +int cache_size; +cache_t cache[16]; + #define release_1x1(filter_dir) {\ cache_t next_case = { \ .code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), \ @@ -12,23 +15,17 @@ cache_insert(next_case); \ } -int cache_size; -cache_t cache[16]; +#define release_1x2(filter_dir) {\ + cache_t next_case = { \ + .code = code & ~(F_1x2 << addr) | (C_1x2 << next_addr), \ + .mask = (uint64_t)0b111 << next_addr, \ + .filter = filter_dir, \ + .addr = next_addr \ + }; \ + cache_insert(next_case); \ +} inline bool cache_insert(cache_t &new_item) { - - // TODO: try closed hashing -// auto volatile hash = new_item.code; -// printf("%016lX -> ", hash); // 64-bits -// hash ^= hash >> 32; -// printf("%08lX -> ", hash & 0xFFFFFFFF); // 32-bits -// hash ^= hash >> 16; -// printf("%04lX -> ", hash & 0xFFFF); // 16-bits -// hash ^= hash >> 8; -// printf("%02lX -> ", hash & 0xFF); // 8-bits -// hash ^= hash >> 4; -// printf("%01lX\n", hash & 0xF); // 4-bits - auto *p = cache; for (; p < cache + cache_size; ++p) { if (p->code == new_item.code) { @@ -42,12 +39,11 @@ inline bool cache_insert(cache_t &new_item) { void move_1x1(uint64_t code, int addr) { cache_size = 1; - cache[0].code = code; // load into queue + cache[0].code = code; cache[0].addr = addr; cache[0].filter = 0; // filter unset int current = 0; - while (current != cache_size) { // start bfs search code = cache[current].code; addr = cache[current].addr; @@ -55,16 +51,45 @@ void move_1x1(uint64_t code, int addr) { int filter = cache[current++].filter; // case filter if (filter != UP && addr >= 4 * 3 && !(code >> (next_addr = addr + UP) & F_1x1)) { - release_1x1(-UP); // block can move up + release_1x1(-UP); // 1x1 block can move up } if (filter != DOWN && addr <= 15 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x1)) { - release_1x1(-DOWN); // block can move down + release_1x1(-DOWN); // 1x1 block can move down } if (filter != LEFT && (addr & 3) != 0 && !(code >> (next_addr = addr + LEFT) & F_1x1)) { - release_1x1(-LEFT); // block can move left + release_1x1(-LEFT); // 1x1 block can move left } if (filter != RIGHT && (addr & 3) != 1 && !(code >> (next_addr = addr + RIGHT) & F_1x1)) { - release_1x1(-RIGHT); // block can move right + release_1x1(-RIGHT); // 1x1 block can move right + } + } +} + + +void move_1x2(uint64_t code, int addr) { + cache_size = 1; + cache[0].code = code; + cache[0].addr = addr; + cache[0].filter = 0; // filter unset + + int current = 0; + while (current != cache_size) { // start bfs search + code = cache[current].code; + addr = cache[current].addr; + int next_addr; // address after block moved + int filter = cache[current++].filter; // case filter + + if (filter != UP && addr >= 4 * 3 && !(code >> (next_addr = addr + UP) & F_1x2)) { + release_1x2(-UP); // 1x2 block can move up + } + if (filter != DOWN && addr <= 14 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x2)) { + release_1x2(-DOWN); // 1x2 block can move down + } + if (filter != LEFT && (addr & 3) != 0 && !(code >> (next_addr = addr + LEFT) & F_1x1)) { + release_1x2(-LEFT); // 1x2 block can move left + } + if (filter != RIGHT && (addr & 3) != 2 && !(code >> (next_addr = addr + RIGHT) & F_1x1_R)) { + release_1x2(-RIGHT); // 1x2 block can move right } } } @@ -72,16 +97,49 @@ void move_1x1(uint64_t code, int addr) { void next_step(uint64_t raw_code, uint64_t mask) { +// int addr = 17; +// raw_code = RawCode(CommonCode("4fea134")).unwrap(); +// move_1x1(raw_code, addr * 3); + + +// int addr = 9; +// raw_code = RawCode(CommonCode("1003")).unwrap(); +// move_1x1(raw_code, addr * 3); + + + int addr = 9; + raw_code = RawCode(CommonCode("1001")).unwrap(); + move_1x2(raw_code, addr * 3); + + // std::cout << RawCode(raw_code).dump_case(); // printf("mask -> %016lX\n", mask); - for (int i = 0; i < 1000000000; ++i) { - move_1x1(raw_code, 17 * 3); - } +// for (int i = 0; i < 1000000000; ++i) { +// move_1x1(raw_code, addr * 3); +// } - std::cout << cache_size << std::endl; - std::cout << RawCode(cache[0].code).dump_case() << std::endl; - std::cout << RawCode(cache[1].code).dump_case() << std::endl; - std::cout << RawCode(cache[2].code).dump_case() << std::endl; + for (int i = 0; i < cache_size; ++i) { + std::cout << "=======" << std::endl; + + std::cout << RawCode(cache[i].code).dump_case(); + + if (i != 0) { + auto _mask = cache[i].mask; + std::cout << std::endl; + for (int n = 0; n < 20; ++n, _mask >>= 3) { + if (_mask & 0b111) { + std::cout << "+ "; + } else { + std::cout << ". "; + } + if ((n & 0b11) == 0b11) { + std::cout << std::endl; + } + } + } + + std::cout << "=======" << std::endl << std::endl; + } } diff --git a/src/main.cc b/src/main.cc index 89ac612..cbd2f93 100644 --- a/src/main.cc +++ b/src/main.cc @@ -142,7 +142,8 @@ int main() { // std::cout << CommonCode(RawCode(0x0E58FC85FFEBC4DB)).to_string() << std::endl; - next_step(CommonCode("4FEA134").to_raw_code().unwrap(), 0); // mask unset +// next_step(CommonCode("4FEA134").to_raw_code().unwrap(), 0); // mask unset + next_step(0, 0); return 0; } diff --git a/src/raw_code/raw_code.cc b/src/raw_code/raw_code.cc index 8835ebf..c844a11 100644 --- a/src/raw_code/raw_code.cc +++ b/src/raw_code/raw_code.cc @@ -78,7 +78,7 @@ std::string RawCode::dump_case() const { }; auto raw_code = code; - for (int addr = 0; raw_code; ++addr, raw_code >>= 3) { + for (int addr = 0; addr < 20; ++addr, raw_code >>= 3) { result.push_back(dump_map[raw_code & 0b111]); if ((addr & 0b11) == 0b11) { result.push_back('\n'); // new line diff --git a/src/raw_code/raw_code.h b/src/raw_code/raw_code.h index d6c8037..a795596 100644 --- a/src/raw_code/raw_code.h +++ b/src/raw_code/raw_code.h @@ -20,6 +20,9 @@ #define F_2x1 (uint64_t)0x7007 // 111 000 000 000 111 #define F_2x2 (uint64_t)0x3F03F // 111 111 000 000 111 111 +#define F_1x1_R (uint64_t)0x38 // 111 000 +#define F_1x1_D (uint64_t)0x7000 // 111 000 000 000 000 + class CommonCode; class RawCode {