Browse Source

feat: add backtrack support

master
Dnomd343 3 weeks ago
parent
commit
86ff28d141
  1. 5
      src/core/fast_cal/fast_cal.h
  2. 22
      src/core/fast_cal/internal/demo.cc

5
src/core/fast_cal/fast_cal.h

@ -131,6 +131,11 @@ public:
// ------------------------------------------------------------------------------------- //
/// Backtrack the shortest path from specified case.
std::vector<RawCode> backtrack(RawCode code);
// ------------------------------------------------------------------------------------- //
private:
// ------------------------------------------------------------------------------------- //

22
src/core/fast_cal/internal/demo.cc

@ -96,13 +96,29 @@ std::vector<RawCode> FastCalPro::furthest() {
}
}
std::vector<RawCode> FastCalPro::backtrack(RawCode code) {
if (const auto match = cases_.find(code.unwrap()); match == cases_.end()) {
return {}; // case not found
}
std::vector<RawCode> path;
while (code != 0) {
path.emplace_back(code);
code = RawCode::unsafe_create(cases_.find(code.unwrap())->second.back);
}
std::reverse(path.begin(), path.end());
return path;
}
RawCode FastCal_demo(RawCode raw_code) {
klotski::fast_cal::FastCalPro fc {raw_code};
return fc.solve().value();
// return fc.solve().value();
// auto tmp = fc.solve();
auto tmp = fc.solve();
// std::cout << tmp.value().to_common_code() << std::endl;
auto path = fc.backtrack(tmp.value());
std::cout << path.size() << std::endl;
// auto tmp = fc.solve_multi();
// for (const auto x : tmp) {
// std::cout << x.to_common_code() << std::endl;
@ -118,5 +134,5 @@ RawCode FastCal_demo(RawCode raw_code) {
// });
// std::cout << tmp.value().to_common_code() << std::endl;
// return RawCode::unsafe_create(0);
return RawCode::unsafe_create(0);
}

Loading…
Cancel
Save