Browse Source

update: build resolve in Analyse

master
Dnomd343 2 years ago
parent
commit
12c8d90c77
  1. 7
      src/analyse/analyse.cc
  2. 7
      src/analyse/analyse.h
  3. 19
      src/main.cc

7
src/analyse/analyse.cc

@ -1,4 +1,5 @@
#include "analyse.h"
#include "common.h"
Analyse::Analyse(const RawCode &code) {
this->root = (uint64_t)code;
@ -31,6 +32,12 @@ std::vector<std::vector<RawCode>> Analyse::layer_export() {
return layer_cases;
}
std::vector<RawCode> Analyse::build_resolve() {
return build_until([](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
});
}
/// memory initialize and return klotski core
Core Analyse::init(uint64_t code) {
/// reset working data

7
src/analyse/analyse.h

@ -21,9 +21,12 @@ public:
/// BFS search functions
void build();
std::vector<RawCode> build_resolve();
// TODO: build_furthest
std::vector<RawCode> build_until(const match_t &match);
/// analysed layer export
// TODO: ending point search
std::vector<std::vector<RawCode>> layer_export();
std::vector<RawCode> layer_export(uint32_t layer_num);
@ -46,14 +49,18 @@ private:
/// backtrack definitions
public:
struct track_t {
// TODO: try using RawCode
uint64_t code;
uint32_t layer_num;
std::list<track_t*> last;
std::list<track_t*> next;
};
// TODO: try using RawCode
typedef std::vector<std::unordered_map<uint64_t, track_t>> track_data_t;
// TODO: using RawCode instead of uint64_t
track_data_t backtrack(const std::vector<RawCode> &codes);
// TODO: RawCode enable `hash` and `equal_to` trait in namespace std
};

19
src/main.cc

@ -61,15 +61,16 @@ int main() {
auto start_time = clock();
// auto a = Analyse(RawCode::from_common_code("1a9bf0c"));
auto a = Analyse(RawCode::from_common_code("1a9bf0c"));
// auto a = Analyse(RawCode::from_common_code("4fea134"));
auto a = Analyse(RawCode::from_common_code("A5D3AF"));
// auto a = Analyse(RawCode::from_common_code("A5D3AF"));
// a.build();
auto ret = a.build_until([](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
});
// auto ret = a.build_until([](uint64_t code) {
// return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
// });
auto ret = a.build_resolve();
// for (const auto &r : ret) {
// std::cout << r << std::endl;
// }
@ -79,11 +80,15 @@ int main() {
std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
auto g = Graph();
start_time = clock();
auto svg_ret = a.backtrack(ret);
std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
auto g = Graph();
auto svg_data = g.svg_demo(svg_ret);
std::cout << svg_data << std::endl;
// std::cout << svg_data << std::endl;
// std::cout << a.layer_export(81).size() << std::endl;

Loading…
Cancel
Save