Browse Source

feat: statistics block num

legacy
Dnomd343 2 years ago
parent
commit
1e652a63a4
  1. 6
      src/klotski_core/CMakeLists.txt
  2. 28
      src/klotski_core/ffi/tmain.cc
  3. 3
      src/klotski_core/group/CMakeLists.txt
  4. 49
      src/klotski_core/group/group.cc
  5. 23
      src/klotski_core/group/group.h

6
src/klotski_core/CMakeLists.txt

@ -100,6 +100,8 @@ include_directories(fast_cal)
include_directories(benchmark) include_directories(benchmark)
include_directories(group)
################################################################################ ################################################################################
add_subdirectory(utils) add_subdirectory(utils)
@ -115,6 +117,8 @@ add_subdirectory(fast_cal)
add_subdirectory(benchmark) add_subdirectory(benchmark)
add_subdirectory(group)
################################################################################ ################################################################################
include_directories(.) include_directories(.)
@ -137,6 +141,8 @@ list(APPEND OBJS $<TARGET_OBJECTS:fast_cal>)
list(APPEND OBJS $<TARGET_OBJECTS:benchmark>) list(APPEND OBJS $<TARGET_OBJECTS:benchmark>)
list(APPEND OBJS $<TARGET_OBJECTS:group>)
################################################################################ ################################################################################
if (BUILD_DYN) if (BUILD_DYN)

28
src/klotski_core/ffi/tmain.cc

@ -11,9 +11,37 @@
#include "all_cases.h" #include "all_cases.h"
#include "common_code.h" #include "common_code.h"
#include "group.h"
using klotski::Group;
using klotski::AllCases;
using klotski::RawCode;
using klotski::CommonCode;
using klotski::Benchmark; using klotski::Benchmark;
void tmain() { 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"); // printf("tmain start\n");
// std::cout << "warm up: " << Benchmark::warm_up(1000000) << "us" << std::endl; // std::cout << "warm up: " << Benchmark::warm_up(1000000) << "us" << std::endl;

3
src/klotski_core/group/CMakeLists.txt

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.0)
add_library(group OBJECT group.cc)

49
src/klotski_core/group/group.cc

@ -0,0 +1,49 @@
#include <iostream>
#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

23
src/klotski_core/group/group.h

@ -0,0 +1,23 @@
#pragma once
#include <cstdint>
#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);
};
}
Loading…
Cancel
Save