Browse Source

feat: common code check function

legacy
Dnomd343 2 years ago
parent
commit
81887d976e
  1. 2
      klotski/CMakeLists.txt
  2. 11
      klotski/common_code.cc
  3. 8
      klotski/common_code.h
  4. 16
      klotski/main.cc

2
klotski/CMakeLists.txt

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)
set(CMAKE_CXX_STANDARD 14)
add_executable(klotski main.cc common.cc all_cases.cc short_code.cc)
add_executable(klotski main.cc common.cc all_cases.cc short_code.cc common_code.cc)

11
klotski/common_code.cc

@ -0,0 +1,11 @@
#include "common.h"
#include "common_code.h"
bool CommonCode::check(uint64_t common_code) {
uint32_t head = common_code >> 32;
auto range = (uint32_t)common_code;
if (head >= 16 || (head & 0b11) == 0b11) { // check 2x2 block address
return false; // invalid common code
}
return Common::check_case(head, Common::range_reverse(range)); // check by head and range
}

8
klotski/common_code.h

@ -0,0 +1,8 @@
#pragma once
#include <cstdint>
class CommonCode {
public:
static bool check(uint64_t common_code);
};

16
klotski/main.cc

@ -1,6 +1,7 @@
#include <iostream>
//#include "all_cases.h"
#include "short_code.h"
#include "common_code.h"
int main() {
@ -31,11 +32,18 @@ int main() {
// s.speed_up(ShortCode::Mode::NORMAL);
// std::cout << s.basic_ranges.size() << std::endl;
auto s = ShortCode();
s.speed_up(ShortCode::Mode::NORMAL); // enter normal mode first
// auto s = ShortCode();
// s.speed_up(ShortCode::Mode::NORMAL); // enter normal mode first
//
// printf("%d\n", s.tiny_encode(0x6EC0F8800));
// printf("%09lX\n", s.tiny_decode(14323231));
printf("%d\n", s.tiny_encode(0x6EC0F8800));
printf("%09lX\n", s.tiny_decode(14323231));
if (CommonCode::check(0x4FEA13400)) {
std::cout << "true" << std::endl;
} else {
std::cout << "false" << std::endl;
}
return 0;
}

Loading…
Cancel
Save