From 46d7d7a051a694bbba78de33be702ac579d08a5e Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 12 Jan 2023 02:23:45 +0800 Subject: [PATCH] feat: solution path backtrack --- src/fast_cal.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/fast_cal.cc b/src/fast_cal.cc index 8c6405c..acb504d 100644 --- a/src/fast_cal.cc +++ b/src/fast_cal.cc @@ -10,6 +10,7 @@ struct fast_cal_t { uint64_t code; uint64_t mask; // uint32_t step; + fast_cal_t *last; }; std::queue cache; @@ -29,8 +30,12 @@ void add_new_case(uint64_t code, uint64_t mask) { cases[code] = fast_cal_t { .code = code, .mask = mask, + .last = cache.front(), };; cache.emplace(&cases[code]); + + // TODO: try to check head address = 0xD at here + } uint32_t fast_cal(uint64_t code) { @@ -39,17 +44,20 @@ uint32_t fast_cal(uint64_t code) { cases.empty(); + cache.empty(); + cases[code] = fast_cal_t { .code = code, .mask = 0, + .last = nullptr, }; cache.emplace(&cases[code]); while (!cache.empty()) { if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) { - std::cout << "Resolve" << std::endl; - std::cout << RawCode(cache.front()->code).dump_case() << std::endl; + std::cout << "Resolved" << std::endl; +// std::cout << RawCode(cache.front()->code).dump_case() << std::endl; break; } @@ -57,6 +65,13 @@ uint32_t fast_cal(uint64_t code) { cache.pop(); } + auto solution = cache.front(); + + while (solution != nullptr) { + std::cout << RawCode(solution->code).dump_case() << std::endl; + solution = solution->last; + } + return cases.size(); }