Browse Source

feat: new namespace klotski

master
Dnomd343 1 year ago
parent
commit
8b67cbbb98
  1. 7
      src/klotski/all_cases/all_cases.cc
  2. 32
      src/klotski/all_cases/all_cases.h
  3. 2
      src/klotski/all_cases/basic_ranges.cc
  4. 51
      src/klotski/all_cases/basic_ranges.h
  5. 2
      src/klotski/common_code/common_code.cc
  6. 2
      src/klotski/ffi/tmain.cc
  7. 2
      src/klotski/raw_code/convert.cc
  8. 2
      src/klotski/short_code/convert.cc
  9. 2
      src/klotski/short_code/short_code.cc
  10. 2
      src/klotski/utils/common.cc
  11. 12
      src/klotski/utils/common.h

7
src/klotski/all_cases/all_cases.cc

@ -1,12 +1,7 @@
#include "common.h"
#include "all_cases.h"
const uint32_t ALL_CASES_SIZE[16] = {
2942906, 2260392, 2942906, 0,
2322050, 1876945, 2322050, 0,
2322050, 1876945, 2322050, 0,
2942906, 2260392, 2942906, 0,
};
using namespace klotski;
/// static variable initialize
std::mutex AllCases::building;

32
src/klotski/all_cases/all_cases.h

@ -5,16 +5,26 @@
#include <cstdint>
#include "basic_ranges.h"
class AllCases : public BasicRanges {
public:
static void build();
static enum Status status();
static const std::vector<uint32_t> (&fetch())[16];
namespace klotski {
/// all cases count
const uint32_t ALL_CASES_SIZE[16] = {
2942906, 2260392, 2942906, 0,
2322050, 1876945, 2322050, 0,
2322050, 1876945, 2322050, 0,
2942906, 2260392, 2942906, 0,
};
private:
static bool available;
static std::mutex building;
static std::vector<uint32_t> data[16];
class AllCases : public BasicRanges {
public:
static void build();
static enum Status status();
static const std::vector<uint32_t> (&fetch())[16];
static void build_data();
};
private:
static bool available;
static std::mutex building;
static std::vector<uint32_t> data[16];
static void build_data();
};
}

2
src/klotski/all_cases/basic_ranges.cc

@ -3,7 +3,7 @@
#include "common.h"
#include "basic_ranges.h"
const uint32_t BASIC_RANGES_SIZE = 7311921;
using namespace klotski;
/// static variable initialize
std::mutex BasicRanges::building;

51
src/klotski/all_cases/basic_ranges.h

@ -4,29 +4,34 @@
#include <vector>
#include <cstdint>
class BasicRanges {
public:
enum Status {
NO_INIT,
BUILDING,
AVAILABLE,
};
static void build();
static enum Status status();
static const std::vector<uint32_t>& fetch();
namespace klotski {
/// basic ranges count
const uint32_t BASIC_RANGES_SIZE = 7311921;
private:
struct generate_t {
int n1; // number of `00`
int n2; // number of `01`
int n3; // number of `10`
int n4; // number of `11`
};
class BasicRanges {
public:
enum Status {
NO_INIT,
BUILDING,
AVAILABLE,
};
static void build();
static enum Status status();
static const std::vector<uint32_t> &fetch();
static bool available;
static std::mutex building;
static std::vector<uint32_t> data;
private:
struct generate_t {
int n1; // number of `00`
int n2; // number of `01`
int n3; // number of `10`
int n4; // number of `11`
};
static void build_data();
static void generate(generate_t info);
};
static bool available;
static std::mutex building;
static std::vector<uint32_t> data;
static void build_data();
static void generate(generate_t info);
};
}

2
src/klotski/common_code/common_code.cc

@ -2,6 +2,8 @@
#include "common.h"
#include "common_code.h"
using namespace klotski;
uint64_t CommonCode::unwrap() const {
return code; // raw uint64_t code
}

2
src/klotski/ffi/tmain.cc

@ -14,7 +14,7 @@ void tmain() {
uint64_t common_code = 0x1A9BC0C00;
Common::range_reverse(common_code);
klotski::Common::range_reverse(common_code);
// uint64_t raw_code = 0x0603EDF5CAFFF5E2;

2
src/klotski/raw_code/convert.cc

@ -2,6 +2,8 @@
#include "common.h"
#include "raw_code.h"
using namespace klotski;
/// RawCode to CommonCode
CommonCode RawCode::to_common_code() const {
if (!RawCode::check(code)) {

2
src/klotski/short_code/convert.cc

@ -6,6 +6,8 @@
#include "basic_ranges_offset.h"
#include "range_prefix_offset.h"
using namespace klotski;
/// ShortCode to CommonCode
CommonCode ShortCode::to_common_code() const { // convert to common code
if (ShortCode::mode() == ShortCode::NORMAL) {

2
src/klotski/short_code/short_code.cc

@ -1,6 +1,8 @@
#include "all_cases.h"
#include "short_code.h"
using namespace klotski;
uint32_t ShortCode::unwrap() const {
return code; // raw uint32_t code
}

2
src/klotski/utils/common.cc

@ -1,5 +1,7 @@
#include "common.h"
using namespace klotski;
uint32_t Common::range_reverse(uint32_t bin) { // reverse binary every 2-bits
bin = ((bin << 16) & 0xFFFF0000) | ((bin >> 16) & 0x0000FFFF);
bin = ((bin << 8) & 0xFF00FF00) | ((bin >> 8) & 0x00FF00FF);

12
src/klotski/utils/common.h

@ -59,8 +59,10 @@
/// 00 01 10 11 ... => ... 11 10 01 00
/// (high 8-bits) (low 8-bits)
class Common {
public:
static uint32_t range_reverse(uint32_t bin);
static uint8_t check_range(uint32_t head, uint32_t range);
};
namespace klotski {
class Common {
public:
static uint32_t range_reverse(uint32_t bin);
static uint8_t check_range(uint32_t head, uint32_t range);
};
}

Loading…
Cancel
Save