|
@ -1,12 +1,10 @@ |
|
|
|
|
|
#include <algorithm> |
|
|
#include "core.h" |
|
|
#include "core.h" |
|
|
#include "common.h" |
|
|
#include "common.h" |
|
|
#include "fast_cal.h" |
|
|
#include "fast_cal.h" |
|
|
|
|
|
|
|
|
#include "raw_code.h" |
|
|
#include "raw_code.h" |
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
/// klotski resolved -> 2x2 block at address 13 (aka 0xD)
|
|
|
#include <algorithm> |
|
|
|
|
|
|
|
|
|
|
|
RawCode FastCal::solve(RawCode code) { |
|
|
RawCode FastCal::solve(RawCode code) { |
|
|
return FastCal::target(code, [](uint64_t code) { |
|
|
return FastCal::target(code, [](uint64_t code) { |
|
|
return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address
|
|
|
return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // check 2x2 block address
|
|
@ -19,34 +17,31 @@ std::vector<RawCode> FastCal::solve_multi(RawCode code) { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<uint64_t> FastCal::backtrack(uint64_t code) { |
|
|
/// backtrack of FastCal tree
|
|
|
std::vector<uint64_t> path; |
|
|
int FastCal::step_num(RawCode code) { |
|
|
|
|
|
auto tmp = cases.find((uint64_t)code); |
|
|
// TODO: confirm code exist
|
|
|
if (tmp == cases.end()) { |
|
|
auto node = &cases[code]; |
|
|
return -1; // code not exist
|
|
|
|
|
|
|
|
|
while (node != nullptr) { |
|
|
|
|
|
path.emplace_back(node->code); |
|
|
|
|
|
node = node->last; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::reverse(path.begin(), path.end()); |
|
|
|
|
|
return path; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
int num = 0; // step number
|
|
|
|
|
|
auto node = &tmp->second; // backtrack entry
|
|
|
|
|
|
|
|
|
uint32_t FastCal::step_num(uint64_t code) { |
|
|
|
|
|
|
|
|
|
|
|
uint32_t num = 0; |
|
|
|
|
|
|
|
|
|
|
|
// TODO: confirm code exist
|
|
|
|
|
|
auto node = &cases[code]; |
|
|
|
|
|
|
|
|
|
|
|
while ((node = node->last) != nullptr) { |
|
|
while ((node = node->last) != nullptr) { |
|
|
++num; |
|
|
++num; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return num; |
|
|
return num; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::vector<RawCode> FastCal::backtrack(RawCode code) { |
|
|
|
|
|
auto tmp = cases.find((uint64_t)code); |
|
|
|
|
|
if (tmp == cases.end()) { |
|
|
|
|
|
return std::vector<RawCode>{}; // code not exist
|
|
|
|
|
|
} |
|
|
|
|
|
auto node = &tmp->second; // backtrack entry
|
|
|
|
|
|
std::vector<RawCode> path; // backtrack path
|
|
|
|
|
|
while (node != nullptr) { |
|
|
|
|
|
path.emplace_back(RawCode::unsafe_create(node->code)); // record path info
|
|
|
|
|
|
node = node->last; |
|
|
|
|
|
} |
|
|
|
|
|
std::reverse(path.begin(), path.end()); // reverse path cases
|
|
|
|
|
|
return path; |
|
|
|
|
|
} |
|
|