From 81887d976ebb809b612cd0d271ebb45d78268c24 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 6 Jan 2023 11:44:19 +0800 Subject: [PATCH] feat: common code check function --- klotski/CMakeLists.txt | 2 +- klotski/common_code.cc | 11 +++++++++++ klotski/common_code.h | 8 ++++++++ klotski/main.cc | 16 ++++++++++++---- 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 klotski/common_code.cc create mode 100644 klotski/common_code.h diff --git a/klotski/CMakeLists.txt b/klotski/CMakeLists.txt index 261c9d5..7a19422 100644 --- a/klotski/CMakeLists.txt +++ b/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) diff --git a/klotski/common_code.cc b/klotski/common_code.cc new file mode 100644 index 0000000..fae0267 --- /dev/null +++ b/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 +} diff --git a/klotski/common_code.h b/klotski/common_code.h new file mode 100644 index 0000000..9a2005c --- /dev/null +++ b/klotski/common_code.h @@ -0,0 +1,8 @@ +#pragma once + +#include + +class CommonCode { +public: + static bool check(uint64_t common_code); +}; diff --git a/klotski/main.cc b/klotski/main.cc index 1ced2bb..659653e 100644 --- a/klotski/main.cc +++ b/klotski/main.cc @@ -1,6 +1,7 @@ #include //#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; }