|
|
@ -5,41 +5,51 @@ |
|
|
|
int cache_size; |
|
|
|
cache_t cache[16]; |
|
|
|
|
|
|
|
#define release_1x1(filter_dir) { \ |
|
|
|
#define ALLOW_UP (filter != UP) |
|
|
|
#define ALLOW_DOWN (filter != DOWN) |
|
|
|
#define ALLOW_LEFT (filter != LEFT) |
|
|
|
#define ALLOW_RIGHT (filter != RIGHT) |
|
|
|
|
|
|
|
#define MOVE_UP (next_addr = addr + UP) |
|
|
|
#define MOVE_DOWN (next_addr = addr + DOWN) |
|
|
|
#define MOVE_LEFT (next_addr = addr + LEFT) |
|
|
|
#define MOVE_RIGHT (next_addr = addr + RIGHT) |
|
|
|
|
|
|
|
#define release_1x1(_filter) { \ |
|
|
|
cache_t next_case = { \ |
|
|
|
.code = code & ~(F_1x1 << addr) | (C_1x1 << next_addr), \ |
|
|
|
.mask = (uint64_t)0b111 << next_addr, \ |
|
|
|
.filter = filter_dir, \ |
|
|
|
.mask = F_1x1 << next_addr, \ |
|
|
|
.filter = _filter, \ |
|
|
|
.addr = next_addr \ |
|
|
|
}; \ |
|
|
|
cache_insert(next_case); \ |
|
|
|
} |
|
|
|
|
|
|
|
#define release_1x2(filter_dir) { \ |
|
|
|
#define release_1x2(_filter) { \ |
|
|
|
cache_t next_case = { \ |
|
|
|
.code = code & ~(F_1x2 << addr) | (C_1x2 << next_addr), \ |
|
|
|
.mask = (uint64_t)0b111 << next_addr, \ |
|
|
|
.filter = filter_dir, \ |
|
|
|
.mask = F_1x1 << next_addr, \ |
|
|
|
.filter = _filter, \ |
|
|
|
.addr = next_addr \ |
|
|
|
}; \ |
|
|
|
cache_insert(next_case); \ |
|
|
|
} |
|
|
|
|
|
|
|
#define release_2x1(filter_dir) { \ |
|
|
|
#define release_2x1(_filter) { \ |
|
|
|
cache_t next_case = { \ |
|
|
|
.code = code & ~(F_2x1 << addr) | (C_2x1 << next_addr), \ |
|
|
|
.mask = (uint64_t)0b111 << next_addr, \ |
|
|
|
.filter = filter_dir, \ |
|
|
|
.mask = F_1x1 << next_addr, \ |
|
|
|
.filter = _filter, \ |
|
|
|
.addr = next_addr \ |
|
|
|
}; \ |
|
|
|
cache_insert(next_case); \ |
|
|
|
} |
|
|
|
|
|
|
|
#define release_2x2(filter_dir) { \ |
|
|
|
#define release_2x2(_filter) { \ |
|
|
|
cache_t next_case = { \ |
|
|
|
.code = code & ~(F_2x2 << addr) | (C_2x2 << next_addr), \ |
|
|
|
.mask = (uint64_t)0b111 << next_addr, \ |
|
|
|
.filter = filter_dir, \ |
|
|
|
.mask = F_1x1 << next_addr, \ |
|
|
|
.filter = _filter, \ |
|
|
|
.addr = next_addr \ |
|
|
|
}; \ |
|
|
|
cache_insert(next_case); \ |
|
|
@ -47,15 +57,12 @@ cache_t cache[16]; |
|
|
|
|
|
|
|
inline bool cache_insert(cache_t &new_item) { |
|
|
|
|
|
|
|
static int match_num = 0; |
|
|
|
// std::cout << "insert times: " << ++match_num << std::endl;
|
|
|
|
// static int insert_num = 0;
|
|
|
|
// std::cout << "insert times: " << ++insert_num << std::endl;
|
|
|
|
|
|
|
|
auto *p = cache; |
|
|
|
for (; p < cache + cache_size; ++p) { |
|
|
|
if (p->code == new_item.code) { |
|
|
|
|
|
|
|
p->filter |= new_item.filter; |
|
|
|
|
|
|
|
return false; // already exist -> insert failed
|
|
|
|
} |
|
|
|
} |
|
|
@ -68,8 +75,7 @@ void move_1x1(uint64_t code, int addr) { |
|
|
|
cache_size = 1; |
|
|
|
cache[0].code = code; |
|
|
|
cache[0].addr = addr; |
|
|
|
// cache[0].filter = 0; // filter unset
|
|
|
|
cache[0].filter = 0b0000; // filter unset
|
|
|
|
cache[0].filter = 0; // filter unset
|
|
|
|
|
|
|
|
int current = 0; |
|
|
|
while (current != cache_size) { // start bfs search
|
|
|
@ -78,33 +84,18 @@ void move_1x1(uint64_t code, int addr) { |
|
|
|
int next_addr; // address after block moved
|
|
|
|
int filter = cache[current++].filter; // case filter
|
|
|
|
|
|
|
|
|
|
|
|
if (!(filter & 0b0001) && addr >= 4 * 3 && !(code >> (next_addr = addr + UP) & F_1x1)) { |
|
|
|
release_1x1(0b0010) // 1x1 block move up
|
|
|
|
if (ALLOW_UP && addr >= 4 * 3 && !(code >> MOVE_UP & F_1x1)) { |
|
|
|
release_1x1(-UP) // 1x1 block move up
|
|
|
|
} |
|
|
|
if (!(filter & 0b0010) && addr <= 15 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x1)) { |
|
|
|
release_1x1(0b0001) // 1x1 block move down
|
|
|
|
if (ALLOW_DOWN && addr <= 15 * 3 && !(code >> MOVE_DOWN & F_1x1)) { |
|
|
|
release_1x1(-DOWN) // 1x1 block move down
|
|
|
|
} |
|
|
|
if (!(filter & 0b0100) && (addr & 3) != 0 && !(code >> (next_addr = addr + LEFT) & F_1x1)) { |
|
|
|
release_1x1(0b1000) // 1x1 block move left
|
|
|
|
if (ALLOW_LEFT && (addr & 3) != 0 && !(code >> MOVE_LEFT & F_1x1)) { |
|
|
|
release_1x1(-LEFT) // 1x1 block move left
|
|
|
|
} |
|
|
|
if (!(filter & 0b1000) && (addr & 3) != 1 && !(code >> (next_addr = addr + RIGHT) & F_1x1)) { |
|
|
|
release_1x1(0b0100) // 1x1 block move right
|
|
|
|
if (ALLOW_RIGHT && (addr & 3) != 1 && !(code >> MOVE_RIGHT & F_1x1)) { |
|
|
|
release_1x1(-RIGHT) // 1x1 block move right
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// if (filter != UP && addr >= 4 * 3 && !(code >> (next_addr = addr + UP) & F_1x1)) {
|
|
|
|
// release_1x1(-UP) // 1x1 block move up
|
|
|
|
// }
|
|
|
|
// if (filter != DOWN && addr <= 15 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x1)) {
|
|
|
|
// release_1x1(-DOWN) // 1x1 block move down
|
|
|
|
// }
|
|
|
|
// if (filter != LEFT && (addr & 3) != 0 && !(code >> (next_addr = addr + LEFT) & F_1x1)) {
|
|
|
|
// release_1x1(-LEFT) // 1x1 block move left
|
|
|
|
// }
|
|
|
|
// if (filter != RIGHT && (addr & 3) != 1 && !(code >> (next_addr = addr + RIGHT) & F_1x1)) {
|
|
|
|
// release_1x1(-RIGHT) // 1x1 block move right
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -121,16 +112,16 @@ void move_1x2(uint64_t code, int 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)) { |
|
|
|
if (ALLOW_UP && addr >= 4 * 3 && !(code >> MOVE_UP & F_1x2)) { |
|
|
|
release_1x2(-UP) // 1x2 block move up
|
|
|
|
} |
|
|
|
if (filter != DOWN && addr <= 14 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x2)) { |
|
|
|
if (ALLOW_DOWN && addr <= 14 * 3 && !(code >> MOVE_DOWN & F_1x2)) { |
|
|
|
release_1x2(-DOWN) // 1x2 block move down
|
|
|
|
} |
|
|
|
if (filter != LEFT && (addr & 3) != 0 && !(code >> (next_addr = addr + LEFT) & F_1x1)) { |
|
|
|
if (ALLOW_LEFT && (addr & 3) != 0 && !(code >> MOVE_LEFT & F_1x1)) { |
|
|
|
release_1x2(-LEFT) // 1x2 block move left
|
|
|
|
} |
|
|
|
if (filter != RIGHT && (addr & 3) != 2 && !(code >> (next_addr = addr + RIGHT) & F_1x1_R)) { |
|
|
|
if (ALLOW_RIGHT && (addr & 3) != 2 && !(code >> MOVE_RIGHT & F_1x1_R)) { |
|
|
|
release_1x2(-RIGHT) // 1x2 block move right
|
|
|
|
} |
|
|
|
} |
|
|
@ -149,16 +140,16 @@ void move_2x1(uint64_t code, int 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_1x1)) { |
|
|
|
if (ALLOW_UP && addr >= 4 * 3 && !(code >> MOVE_UP & F_1x1)) { |
|
|
|
release_2x1(-UP) // 2x1 block move up
|
|
|
|
} |
|
|
|
if (filter != DOWN && addr <= 11 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x1_D)) { |
|
|
|
if (ALLOW_DOWN && addr <= 11 * 3 && !(code >> MOVE_DOWN & F_1x1_D)) { |
|
|
|
release_2x1(-DOWN) // 2x1 block move down
|
|
|
|
} |
|
|
|
if (filter != LEFT && (addr & 0x3) != 0 && !(code >> (next_addr = addr + LEFT) & F_2x1)) { |
|
|
|
if (ALLOW_LEFT && (addr & 0x3) != 0 && !(code >> MOVE_LEFT & F_2x1)) { |
|
|
|
release_2x1(-LEFT) // 2x1 block move left
|
|
|
|
} |
|
|
|
if (filter != RIGHT && (addr & 0x3) != 1 && !(code >> (next_addr = addr + RIGHT) & F_2x1)) { |
|
|
|
if (ALLOW_RIGHT && (addr & 0x3) != 1 && !(code >> MOVE_RIGHT & F_2x1)) { |
|
|
|
release_2x1(-RIGHT) // 2x1 block move right
|
|
|
|
} |
|
|
|
} |
|
|
@ -178,16 +169,16 @@ void move_2x2(uint64_t code, int 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)) { |
|
|
|
if (ALLOW_UP && addr >= 4 * 3 && !(code >> MOVE_UP & F_1x2)) { |
|
|
|
release_2x2(-UP) // 2x2 block move up
|
|
|
|
} |
|
|
|
if (filter != DOWN && addr <= 10 * 3 && !(code >> (next_addr = addr + DOWN) & F_1x2_D)) { |
|
|
|
if (ALLOW_DOWN && addr <= 10 * 3 && !(code >> MOVE_DOWN & F_1x2_D)) { |
|
|
|
release_2x2(-DOWN) // 2x2 block move down
|
|
|
|
} |
|
|
|
if (filter != LEFT && (addr & 3) != 0 && !(code >> (next_addr = addr + LEFT) & F_2x1)) { |
|
|
|
if (ALLOW_LEFT && (addr & 3) != 0 && !(code >> MOVE_LEFT & F_2x1)) { |
|
|
|
release_2x2(-LEFT) // 2x2 block move left
|
|
|
|
} |
|
|
|
if (filter != RIGHT && (addr & 3) != 2 && !(code >> (next_addr = addr + RIGHT) & F_2x1_R)) { |
|
|
|
if (ALLOW_RIGHT && (addr & 3) != 2 && !(code >> MOVE_RIGHT & F_2x1_R)) { |
|
|
|
release_2x2(-RIGHT) // 2x2 block move right
|
|
|
|
} |
|
|
|
} |
|
|
@ -196,12 +187,12 @@ void move_2x2(uint64_t code, int addr) { |
|
|
|
|
|
|
|
void next_step(uint64_t raw_code, uint64_t mask) { |
|
|
|
|
|
|
|
// int addr = 17;
|
|
|
|
// raw_code = RawCode(CommonCode("4fea134")).unwrap();
|
|
|
|
int addr = 17; |
|
|
|
raw_code = RawCode(CommonCode("4fea134")).unwrap(); |
|
|
|
// move_1x1(raw_code, addr * 3);
|
|
|
|
|
|
|
|
int addr = 9; |
|
|
|
raw_code = RawCode(CommonCode("1003")).unwrap(); |
|
|
|
// int addr = 9;
|
|
|
|
// raw_code = RawCode(CommonCode("1003")).unwrap();
|
|
|
|
// move_1x1(raw_code, addr * 3);
|
|
|
|
|
|
|
|
// int addr = 9;
|
|
|
@ -216,34 +207,34 @@ void next_step(uint64_t raw_code, uint64_t mask) { |
|
|
|
// std::cout << RawCode(raw_code).dump_case();
|
|
|
|
// printf("mask -> %016lX\n", mask);
|
|
|
|
|
|
|
|
// for (int i = 0; i < 1000000000; ++i) {
|
|
|
|
for (int i = 0; i < 50000000; ++i) { |
|
|
|
for (int i = 0; i < 1000000000; ++i) { |
|
|
|
// for (int i = 0; i < 50000000; ++i) {
|
|
|
|
move_1x1(raw_code, addr * 3); |
|
|
|
} |
|
|
|
|
|
|
|
std::cout << "cache size: " << cache_size << 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;
|
|
|
|
// }
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|