From 1e652a63a4468fc03d4a91e6eec44413828b6307 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 8 Apr 2023 23:03:19 +0800 Subject: [PATCH] feat: statistics block num --- src/klotski_core/CMakeLists.txt | 6 ++++ src/klotski_core/ffi/tmain.cc | 28 +++++++++++++++ src/klotski_core/group/CMakeLists.txt | 3 ++ src/klotski_core/group/group.cc | 49 +++++++++++++++++++++++++++ src/klotski_core/group/group.h | 23 +++++++++++++ 5 files changed, 109 insertions(+) create mode 100644 src/klotski_core/group/CMakeLists.txt create mode 100644 src/klotski_core/group/group.cc create mode 100644 src/klotski_core/group/group.h diff --git a/src/klotski_core/CMakeLists.txt b/src/klotski_core/CMakeLists.txt index 6b57505..216e42f 100644 --- a/src/klotski_core/CMakeLists.txt +++ b/src/klotski_core/CMakeLists.txt @@ -100,6 +100,8 @@ include_directories(fast_cal) include_directories(benchmark) +include_directories(group) + ################################################################################ add_subdirectory(utils) @@ -115,6 +117,8 @@ add_subdirectory(fast_cal) add_subdirectory(benchmark) +add_subdirectory(group) + ################################################################################ include_directories(.) @@ -137,6 +141,8 @@ list(APPEND OBJS $) list(APPEND OBJS $) +list(APPEND OBJS $) + ################################################################################ if (BUILD_DYN) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index b2d3380..d860c33 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -11,9 +11,37 @@ #include "all_cases.h" #include "common_code.h" +#include "group.h" + +using klotski::Group; +using klotski::AllCases; + +using klotski::RawCode; +using klotski::CommonCode; + using klotski::Benchmark; void tmain() { + +// Group::block_num(CommonCode(0x1A9BF0C00)); +// Group::block_num(RawCode::from_common_code(0x1A9BF0C00)); + +// std::cout << std::endl; + +// Group::block_num(CommonCode(0x4FEA13400)); +// Group::block_num(RawCode::from_common_code(0x4FEA13400)); + + for (auto &&common_code : AllCases::release()) { + auto s1 = Group::block_num(common_code); + auto s2 = Group::block_num(common_code.to_raw_code()); + if (s1.n_1x1 != s2.n_1x1 || s1.n_1x2 != s2.n_1x2 || s1.n_2x1 != s2.n_2x1) { + std::cout << "fuck" << std::endl; + } + } + + + return; + // printf("tmain start\n"); // std::cout << "warm up: " << Benchmark::warm_up(1000000) << "us" << std::endl; diff --git a/src/klotski_core/group/CMakeLists.txt b/src/klotski_core/group/CMakeLists.txt new file mode 100644 index 0000000..2ba2948 --- /dev/null +++ b/src/klotski_core/group/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.0) + +add_library(group OBJECT group.cc) diff --git a/src/klotski_core/group/group.cc b/src/klotski_core/group/group.cc new file mode 100644 index 0000000..8e03ad8 --- /dev/null +++ b/src/klotski_core/group/group.cc @@ -0,0 +1,49 @@ +#include +#include "group.h" +#include "common.h" + +namespace klotski { + +using Common::range_reverse; + +Group::block_num_t Group::block_num(const RawCode &raw_code) { + block_num_t result; + auto tmp = raw_code.unwrap(); + for (int addr = 0; addr < 20; ++addr, tmp >>= 3) { + switch (tmp & 0b111) { + case B_1x1: + ++result.n_1x1; + continue; + case B_1x2: + ++result.n_1x2; + continue; + case B_2x1: + ++result.n_2x1; + continue; + } + } + return result; +} + +Group::block_num_t Group::block_num(const CommonCode &common_code) { + block_num_t result; + auto range = range_reverse((uint32_t)common_code.unwrap()); + for (; range; range >>= 2) { + switch (range & 0b11) { + case 0b01: /// 1x2 block + ++result.n_1x2; + continue; + case 0b10: /// 2x1 block + ++result.n_2x1; + continue; + case 0b11: /// 1x1 block + ++result.n_1x1; + continue; + } + } + return result; +} + + + +} // namespace klotski diff --git a/src/klotski_core/group/group.h b/src/klotski_core/group/group.h new file mode 100644 index 0000000..2a6cce5 --- /dev/null +++ b/src/klotski_core/group/group.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include "raw_code.h" +#include "common_code.h" + +namespace klotski { + +class Group { +public: + + struct block_num_t { + uint8_t n_1x1 = 0; + uint8_t n_1x2 = 0; + uint8_t n_2x1 = 0; + }; + + static block_num_t block_num(const RawCode &raw_code); + static block_num_t block_num(const CommonCode &common_code); + +}; + +}