diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index 9c128b6..866dd14 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -58,6 +58,12 @@ uint64_t FastCal::solve(uint64_t code) { }); } +std::vector FastCal::solve_multi(uint64_t code) { + return FastCal::target_multi(code, [](uint64_t code) { + return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address + }); +} + uint64_t FastCal::target(uint64_t code, const check_t &match) { auto core = init(); @@ -76,3 +82,59 @@ uint64_t FastCal::target(uint64_t code, const check_t &match) { } return FastCal::NOT_FOUND; // target not found } + +std::vector FastCal::target_multi(uint64_t code, const FastCal::check_t &match) { + + auto core = init(); + + cache.emplace(&cases.emplace(code, fast_cal_t { + .code = code, + .mask = 0, + .last = nullptr, // without parent node + }).first->second); + + auto layer_end = cache.back(); + + int layer_num = 0; + +// bool matched = false; + + std::vector matched; + + while (!cache.empty()) { + + if (match(cache.front()->code)) { +// matched = true; + matched.emplace_back(cache.front()->code); +// std::cout << "found: " << std::endl; +// std::cout << RawCode(cache.front()->code); + + } + + core.next_cases(cache.front()->code, cache.front()->mask); + + if (cache.front() == layer_end) { + + if (!matched.empty()) { + std::cout << "layer " << layer_num << " end -> exit search" << std::endl; + return matched; + } + + std::cout << "reach layer " << layer_num << " ending" << std::endl; + ++layer_num; + + layer_end = cache.back(); + + } + + cache.pop(); + + } + + return std::vector{}; // no target found + +} + + + + diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index 1bf2d3c..a04ac0c 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -27,6 +27,9 @@ public: uint64_t target(uint64_t code, const check_t &match); + std::vector solve_multi(uint64_t code); + std::vector target_multi(uint64_t code, const check_t &match); + std::vector backtrack(uint64_t code); // TODO: static search functions diff --git a/src/main.cc b/src/main.cc index 56b7a55..01daf99 100644 --- a/src/main.cc +++ b/src/main.cc @@ -26,11 +26,15 @@ int main() { // AllCases::build(); auto f = FastCal(); - auto ret = f.solve((uint64_t)RawCode::from_common_code("1a9bf0c")); +// auto ret = f.solve((uint64_t)RawCode::from_common_code("1a9bf0c")); + auto ret = f.solve_multi((uint64_t)RawCode::from_common_code("1a9bf0c")); // auto f = FastCal(RawCode::from_common_code("1a9bf0c").unwrap()); // auto ret = f.solve(); - std::cout << RawCode(ret) << std::endl; +// std::cout << RawCode(ret) << std::endl; + for (const auto &r : ret) { + std::cout << RawCode(r) << std::endl; + } // for (const auto &c : ret) { // std::cout << RawCode(c) << std::endl;