diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index abf1a68..a3509c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,8 +16,8 @@ add_subdirectory(raw_code) add_subdirectory(short_code) add_subdirectory(common_code) -add_executable(klotski main.cc) -#add_executable(klotski main.cc core_demo.cc) +#add_executable(klotski main.cc) +add_executable(klotski main.cc fast_cal.cc) target_link_libraries(klotski core) target_link_libraries(klotski common) diff --git a/src/fast_cal.cc b/src/fast_cal.cc new file mode 100644 index 0000000..8a15483 --- /dev/null +++ b/src/fast_cal.cc @@ -0,0 +1,77 @@ +#include +#include +#include +#include "core.h" +#include "fast_cal.h" +#include "raw_code.h" + +struct fast_cal_t { + uint64_t code; + uint64_t mask; +// uint32_t step; +}; + +std::unordered_map cal_data; +std::queue cal_temp; + +void add_new_case(uint64_t code, uint64_t mask) { + + auto exist_case = cal_data.find(code); + if (exist_case != cal_data.end()) { // find it + // mask update +// std::cout << "match exist case" << std::endl; + return; + } + +// std::cout << RawCode(code).dump_case(); +// std::cout << "~~~~~~~" << std::endl; +// for (int n = 0; n < 20; ++n, mask >>= 3) { +// std::cout << "+."[!(mask & 0b111)] << " \n"[!(~n & 0b11)]; +// } +// std::cout << std::endl; + + auto new_case = fast_cal_t { + .code = code, + .mask = mask, + }; + + cal_data[code] = new_case; + + // TODO: avoid redundancy map search + cal_temp.emplace(&cal_data[code]); + +} + +void fast_cal(uint64_t start_raw_code) { + std::cout << RawCode(start_raw_code).dump_case() << std::endl; + + auto core = Core(); + + auto setup = fast_cal_t { + .code = start_raw_code, + .mask = 0, + }; + + cal_data[start_raw_code] = setup; + cal_temp.emplace(&cal_data[start_raw_code]); + +// core.next_step(cal_temp.front()->code, add_new_case); +// cal_temp.pop(); + +// std::cout << "start cal second case" << std::endl; +// std::cout << RawCode(cal_temp.front()->code).dump_case() << std::endl << std::endl; + +// core.next_step(cal_temp.front()->code, add_new_case); +// cal_temp.pop(); + + + while (!cal_temp.empty()) { + core.next_step(cal_temp.front()->code, add_new_case); + cal_temp.pop(); + } + + std::cout << "size = " << cal_data.size() << std::endl; + std::cout << "queue size = " << cal_temp.size() << std::endl; + + +} diff --git a/src/fast_cal.h b/src/fast_cal.h new file mode 100644 index 0000000..e68670a --- /dev/null +++ b/src/fast_cal.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void fast_cal(uint64_t start_raw_code); diff --git a/src/main.cc b/src/main.cc index 4551eeb..5498e2b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -5,6 +5,7 @@ #include "common_code.h" #include "short_code.h" #include "raw_code.h" +#include "fast_cal.h" //#include "core_demo.h" @@ -37,14 +38,14 @@ // } //} -void release(uint64_t code, uint64_t mask) { - std::cout << RawCode(code).dump_case(); - std::cout << "~~~~~~~" << std::endl; - for (int n = 0; n < 20; ++n, mask >>= 3) { - std::cout << "+."[!(mask & 0b111)] << " \n"[!(~n & 0b11)]; - } - std::cout << std::endl; -} +//void release(uint64_t code, uint64_t mask) { +// std::cout << RawCode(code).dump_case(); +// std::cout << "~~~~~~~" << std::endl; +// for (int n = 0; n < 20; ++n, mask >>= 3) { +// std::cout << "+."[!(mask & 0b111)] << " \n"[!(~n & 0b11)]; +// } +// std::cout << std::endl; +//} int main() { @@ -153,11 +154,11 @@ int main() { // std::cout << CommonCode(RawCode(0x0E58FC85FFEBC4DB)).to_string() << std::endl; - auto c = Core(); +// auto c = Core(); // auto raw_code = RawCode(CommonCode("4fea134")).unwrap(); - auto raw_code = RawCode(CommonCode("1A9bf0c")).unwrap(); - c.next_step(raw_code, release); +// auto raw_code = RawCode(CommonCode("1A9bf0c")).unwrap(); +// c.next_step(raw_code, release); // std::vector all_cases_raw; // for (int head = 0; head < 16; ++head) { @@ -195,5 +196,7 @@ int main() { // std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; // std::cout << "complete benchmark" << std::endl; + fast_cal(CommonCode("1a9bf0c").to_raw_code().unwrap()); + return 0; }