Browse Source

feat: static resolve function for FastCal

master
Dnomd343 2 years ago
parent
commit
5bbd6b916f
  1. 25
      src/fast_cal/fast_cal.cc
  2. 12
      src/fast_cal/fast_cal.h
  3. 23
      src/main.cc

25
src/fast_cal/fast_cal.cc

@ -4,17 +4,17 @@
#include "fast_cal.h"
#include "raw_code.h"
auto resolved = [](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address
};
/// klotski resolved -> 2x2 block at address 13 (aka 0xD)
RawCode FastCal::solve(RawCode code) {
return FastCal::target(code, [](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address
});
return FastCal::target(code, resolved);
}
std::vector<RawCode> FastCal::solve_multi(RawCode code) {
return FastCal::target_multi(code, [](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address
});
return FastCal::target_multi(code, resolved);
}
/// backtrack of FastCal tree
@ -45,3 +45,16 @@ std::vector<RawCode> FastCal::backtrack(RawCode code) {
std::reverse(path.begin(), path.end()); // reverse path cases
return path;
}
std::vector<RawCode> FastCal::resolve(RawCode start) {
return FastCal::search(start, resolved);
}
std::vector<RawCode> FastCal::search(RawCode start, const FastCal::match_t &match) {
auto fc = FastCal();
auto result = fc.target(start, match);
if (result == FC_NOT_FOUND) {
return std::vector<RawCode>{}; // target not matched
}
return fc.backtrack(result); // backtrack target path
}

12
src/fast_cal/fast_cal.h

@ -20,19 +20,21 @@ public:
std::vector<RawCode> backtrack(RawCode code);
/// BFS search functions
// TODO: build function with void return -> build total tree
RawCode solve(RawCode code);
std::vector<RawCode> furthest(RawCode code);
std::vector<RawCode> solve_multi(RawCode code);
RawCode target(RawCode code, const match_t &match);
std::vector<RawCode> target_multi(RawCode code, const match_t &match);
/// static BFS search functions
// static std::vector<RawCode> get_furthest(RawCode start);
// TODO: static search functions
// TODO: search / search_multi / resolve / resolve_multi
// TODO: static furthest function
static std::vector<RawCode> resolve(RawCode start);
static std::vector<RawCode> search(RawCode start, const match_t &match);
// static std::vector<std::vector<RawCode>> resolve_multi(RawCode start);
// static std::vector<std::vector<RawCode>> search_multi(RawCode start, const match_t &match);
private:
struct fast_cal_t {

23
src/main.cc

@ -25,9 +25,9 @@ int main() {
// AllCases::build();
auto f = FastCal();
// auto f = FastCal();
// auto ret = f.solve((uint64_t)RawCode::from_common_code("1a9bf0c"));
auto ret = f.solve(RawCode::from_common_code("1a9bf0c"));
// auto ret = f.solve(RawCode::from_common_code("1a9bf0c"));
// auto ret = f.target(RawCode::from_common_code("1a9bf0c"), [](uint64_t code) {
// return code == (uint64_t)RawCode::from_common_code(0xDB23B6C00);
@ -36,15 +36,20 @@ int main() {
// auto ret = f.solve(RawCode::from_common_code("1aaef0c"));
if (ret == FC_NOT_FOUND) {
std::cout << "not found" << std::endl;
} else {
for (const auto &r : f.backtrack(ret)) {
std::cout << r << std::endl;
}
std::cout << "step number: " << f.step_num(ret) << std::endl;
// if (ret == FC_NOT_FOUND) {
// std::cout << "not found" << std::endl;
// } else {
// for (const auto &r : f.backtrack(ret)) {
// std::cout << r << std::endl;
// }
// std::cout << "step number: " << f.step_num(ret) << std::endl;
// }
for (const auto &c : FastCal::resolve(RawCode::from_common_code("1a9bf0c"))) {
std::cout << c << std::endl;
}
// std::cout << f.step_num(ret) << std::endl;
// auto f = FastCal(RawCode::from_common_code("1a9bf0c").unwrap());

Loading…
Cancel
Save