From c69b59424a289d5609d8489ee96f5f125e302fe9 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 19 Jan 2023 15:18:54 +0800 Subject: [PATCH] feat: backtrack for furthest cases in FastCal --- src/fast_cal/fast_cal.cc | 13 +++++++++++-- src/fast_cal/fast_cal.h | 9 ++++----- src/main.cc | 10 +++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index e981b7b..9f4cf42 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -54,6 +54,15 @@ std::vector> FastCal::resolve_multi(RawCode start) { return FastCal::search_multi(start, resolved); } +std::vector> FastCal::to_furthest(RawCode start) { + auto fc = FastCal(); + std::vector> result; + for (const auto &furthest : fc.furthest(start)) { + result.emplace_back(fc.backtrack(furthest)); // backtrack every furthest cases + } + return result; +} + std::vector FastCal::search(RawCode start, const match_t &match) { auto fc = FastCal(); auto result = fc.target(start, match); @@ -66,8 +75,8 @@ std::vector FastCal::search(RawCode start, const match_t &match) { std::vector> FastCal::search_multi(RawCode start, const match_t &match) { auto fc = FastCal(); std::vector> result; - for (const auto &c : fc.target_multi(start, match)) { - result.emplace_back(fc.backtrack(c)); // backtrack every target + for (const auto &target : fc.target_multi(start, match)) { + result.emplace_back(fc.backtrack(target)); // backtrack every target } return result; } diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index 22e2b2d..ad51b49 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -28,15 +28,14 @@ public: std::vector target_multi(RawCode code, const match_t &match); /// static BFS search functions - // TODO: (RawCode code) -> (const RawCode &code) -// static std::vector get_furthest(RawCode start); - static std::vector resolve(RawCode start); - static std::vector search(RawCode start, const match_t &match); - + static std::vector> to_furthest(RawCode start); static std::vector> resolve_multi(RawCode start); + static std::vector search(RawCode start, const match_t &match); static std::vector> search_multi(RawCode start, const match_t &match); + // TODO: (RawCode code) -> (const RawCode &code) + private: struct fast_cal_t { uint64_t code; diff --git a/src/main.cc b/src/main.cc index 8d03fc6..6fd91d9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -49,11 +49,11 @@ int main() { // std::cout << c << std::endl; // } - for (const auto &s : FastCal::resolve_multi(RawCode::from_common_code("1a9bf0c"))) { -// for (const auto &c : s) { -// std::cout << c << std::endl; -// } -// std::cout << "--------------------------------------------" << std::endl; + for (const auto &s : FastCal::to_furthest(RawCode::from_common_code("1a9bf0c"))) { + for (const auto &c : s) { + std::cout << c << std::endl; + } + std::cout << "--------------------------------------------" << std::endl; } // std::cout << f.step_num(ret) << std::endl;