Browse Source

feat: klotski resolves as backtrack graph

legacy
Dnomd343 2 years ago
parent
commit
4e37512930
  1. 4
      src/graph/graph.cc
  2. 2
      src/graph/graph.h
  3. 46
      src/main.cc

4
src/graph/graph.cc

@ -6,7 +6,7 @@
#include "svg.h"
void Graph::svg_demo(Analyse::track_data_t track_data) {
std::string Graph::svg_demo(Analyse::track_data_t track_data) {
// for (uint32_t i = 0; i < track_data.size(); ++i) {
//
@ -154,6 +154,6 @@ void Graph::svg_demo(Analyse::track_data_t track_data) {
}
}
std::cout << svg.dump() << std::endl;
return svg.dump();
}

2
src/graph/graph.h

@ -51,6 +51,6 @@ public:
uint64_t LINE_OFFSET = 2;
void svg_demo(Analyse::track_data_t track_data);
std::string svg_demo(Analyse::track_data_t track_data);
};

46
src/main.cc

@ -13,10 +13,12 @@
#include <thread>
#include <algorithm>
#include <unistd.h>
#include <fstream>
//int main(int argc, char *argv[]) {
int main() {
BasicRanges::build();
// BasicRanges::build();
// AllCases::build();
@ -42,7 +44,7 @@ int main() {
// sleep(3);
// std::cout << "start benchmark" << std::endl;
auto start_time = clock();
// auto start_time = clock();
// auto fc = FastCal(RawCode::from_common_code("1a9bf0c"));
@ -60,11 +62,34 @@ int main() {
// 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("1FA6F80"));
// auto a = Analyse(RawCode::from_common_code("1FA6F80"));
// auto a = Analyse(RawCode::from_common_code("0F5747"));
// if (argc < 2) {
// std::cout << "without input code" << std::endl;
// }
// auto a = Analyse(RawCode::from_common_code(argv[1]));
std::string input;
std::cout << "Please give a common code: ";
std::cin >> input;
auto common_code = CommonCode::from_string(input);
std::cout << ShortCode::from_common_code(common_code).to_string() << " -> ";
auto start_time = clock();
auto a = Analyse(RawCode::from_common_code(common_code));
// a.build();
auto ret = a.build_until([](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
});
std::cout << ret.size() << std::endl;
std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
// std::cout << "analyse complete" << std::endl;
// for (const auto &r : ret) {
@ -80,7 +105,15 @@ int main() {
// std::cout << "backtrack complete" << std::endl;
auto g = Graph();
g.svg_demo(svg_ret);
auto svg_data = g.svg_demo(svg_ret);
std::ofstream output;
output.open(common_code.to_string(true) + ".svg");
output << svg_data << std::endl;
output.close();
// std::cout << svg_data << std::endl;
// auto start_time = clock();
@ -126,11 +159,12 @@ int main() {
// std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl;
// std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
// std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
// std::cout << "complete benchmark" << std::endl;
// pause();
std::cerr << "Press CTRL-C for exit...";
pause();
return 0;
}

Loading…
Cancel
Save