mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 years ago
8 changed files with 119 additions and 12 deletions
@ -1,5 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include <cstdint> |
|||
|
|||
uint32_t fast_cal(uint64_t start_code); |
@ -0,0 +1,4 @@ |
|||
cmake_minimum_required(VERSION 3.0) |
|||
|
|||
add_library(fast_cal fast_cal.cc) |
|||
target_link_libraries(fast_cal core) |
@ -0,0 +1,65 @@ |
|||
#include "core.h" |
|||
#include "common.h" |
|||
#include "fast_cal.h" |
|||
|
|||
#include "raw_code.h" |
|||
|
|||
#include <iostream> |
|||
|
|||
void FastCal::fast_cal(uint64_t code) { |
|||
|
|||
std::cout << RawCode(code).dump_case() << std::endl; |
|||
|
|||
auto core = Core(); |
|||
core.release_next = std::bind(&FastCal::add_new_case, this, std::placeholders::_1, std::placeholders::_2); |
|||
|
|||
cases.empty(); |
|||
cache.empty(); |
|||
|
|||
cases[code] = fast_cal_t { |
|||
.code = code, |
|||
.mask = 0, |
|||
.last = nullptr, |
|||
}; |
|||
cache.emplace(&cases[code]); |
|||
|
|||
while (!cache.empty()) { |
|||
|
|||
// break check point
|
|||
if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) { |
|||
std::cout << "Resolved" << std::endl; |
|||
// std::cout << RawCode(cache.front()->code).dump_case() << std::endl;
|
|||
break; |
|||
} |
|||
|
|||
core.next_step(cache.front()->code, cache.front()->mask); |
|||
cache.pop(); |
|||
} |
|||
|
|||
auto solution = cache.front(); |
|||
|
|||
while (solution != nullptr) { |
|||
// std::cout << RawCode(solution->code).dump_case() << std::endl;
|
|||
solution = solution->last; |
|||
} |
|||
|
|||
} |
|||
|
|||
void FastCal::add_new_case(uint64_t code, uint64_t mask) { |
|||
|
|||
auto exist_case = cases.find(code); |
|||
if (exist_case != cases.end()) { // find existed case
|
|||
|
|||
exist_case->second.mask |= mask; // mask update
|
|||
return; |
|||
|
|||
} |
|||
|
|||
cases[code] = fast_cal_t { |
|||
.code = code, |
|||
.mask = mask, |
|||
.last = cache.front(), |
|||
};; |
|||
cache.emplace(&cases[code]); |
|||
|
|||
} |
@ -0,0 +1,22 @@ |
|||
#pragma once |
|||
|
|||
#include <queue> |
|||
#include <cstdint> |
|||
#include <unordered_map> |
|||
|
|||
class FastCal { |
|||
public: |
|||
struct fast_cal_t { |
|||
uint64_t code; |
|||
uint64_t mask; |
|||
fast_cal_t *last; |
|||
}; |
|||
|
|||
std::queue<fast_cal_t*> cache; |
|||
std::unordered_map<uint64_t, fast_cal_t> cases; |
|||
|
|||
void fast_cal(uint64_t code); |
|||
|
|||
void add_new_case(uint64_t code, uint64_t mask); |
|||
|
|||
}; |
Loading…
Reference in new issue