Browse Source

feat: next_step statistics for all cases

master
Dnomd343 2 years ago
parent
commit
7837c5f4df
  1. 12
      src/core/core.cc
  2. 3
      src/core/core.h
  3. 29
      src/main.cc

12
src/core/core.cc

@ -128,7 +128,10 @@ void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block
#include <iostream>
void Core::next_step(uint64_t raw_code) {
uint32_t Core::next_step(uint64_t raw_code) {
uint32_t sum = 0;
auto code = raw_code;
for (int addr = 0; code; addr += 3, code >>= 3) { // traverse every 3-bits
switch (code & 0b111) { // match low 3-bits
@ -161,6 +164,13 @@ void Core::next_step(uint64_t raw_code) {
// std::cout << std::endl;
}
sum += cache_size - 1;
}
}
// std::cout << "sum = " << sum << std::endl;
return sum;
}

3
src/core/core.h

@ -19,7 +19,8 @@
class Core {
public:
void next_step(uint64_t raw_code);
// void next_step(uint64_t raw_code);
uint32_t next_step(uint64_t raw_code);
private:
struct cache_t {

29
src/main.cc

@ -9,6 +9,7 @@
//#include "core_demo.h"
#include <thread>
#include <algorithm>
//void get_status() {
// switch (BasicRanges::status()) {
@ -143,9 +144,7 @@ int main() {
// std::cout << CommonCode(RawCode(0x0E58FC85FFEBC4DB)).to_string() << std::endl;
// next_step(CommonCode("4FEA134").to_raw_code().unwrap(), 0); // mask unset
// auto raw_code = RawCode(CommonCode("4fea134")).unwrap();
auto c = Core();
std::vector<uint64_t> all_cases_raw;
for (int head = 0; head < 16; ++head) {
@ -157,19 +156,31 @@ int main() {
}
}
std::cout << "start benchmark" << std::endl;
auto start_time = clock();
// std::cout << "start benchmark" << std::endl;
// auto start_time = clock();
auto c = Core();
// auto raw_code = RawCode(CommonCode("4fea134")).unwrap();
// for (int i = 0; i < 100000000; ++i) {
// c.next_step(raw_code);
// }
std::vector<uint32_t> steps;
for (auto const &raw_code : all_cases_raw) {
c.next_step(raw_code);
steps.emplace_back(c.next_step(raw_code));
}
// std::sort(steps.begin(), steps.end());
// std::cout << steps[0] << std::endl;
// std::cout << steps[steps.size() - 1] << std::endl;
for (int i = 0; i < all_cases_raw.size(); ++i) {
// if (steps[i] == 0) {
if (steps[i] == 68) { // max next steps
std::cout << RawCode(all_cases_raw[i]).dump_case();
std::cout << CommonCode(RawCode(all_cases_raw[i])).to_string() << std::endl << std::endl;
}
}
std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
std::cout << "complete benchmark" << std::endl;
// std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
// std::cout << "complete benchmark" << std::endl;
return 0;
}

Loading…
Cancel
Save