|
|
|
#include <cstring>
|
|
|
|
#include "klotski.h"
|
|
|
|
#include "all_cases.h"
|
|
|
|
#include "short_code.h"
|
|
|
|
|
|
|
|
using klotski::RawCode;
|
|
|
|
using klotski::ShortCode;
|
|
|
|
using klotski::CommonCode;
|
|
|
|
|
|
|
|
using klotski::AllCases;
|
|
|
|
using klotski::BasicRanges;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void short_code_enable() noexcept {
|
|
|
|
ShortCode::speed_up(ShortCode::NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void short_code_enable_fast() noexcept {
|
|
|
|
ShortCode::speed_up(ShortCode::FAST);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_short_code_available() noexcept {
|
|
|
|
if (BasicRanges::status() != BasicRanges::AVAILABLE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ShortCode::speed_up(ShortCode::NORMAL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_short_code_available_fast() noexcept {
|
|
|
|
if (AllCases::status() != AllCases::AVAILABLE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ShortCode::speed_up(ShortCode::FAST);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool raw_code_check(uint64_t raw_code) noexcept {
|
|
|
|
return RawCode::check(raw_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool short_code_check(uint32_t short_code) noexcept {
|
|
|
|
return ShortCode::check(short_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool common_code_check(uint64_t common_code) noexcept {
|
|
|
|
return CommonCode::check(common_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool raw_code_to_short_code(uint64_t raw_code, uint32_t *short_code) noexcept {
|
|
|
|
if (!RawCode::check(raw_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*short_code = ShortCode::from_common_code(
|
|
|
|
CommonCode::from_raw_code(RawCode::unsafe_create(raw_code))
|
|
|
|
).unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool short_code_to_raw_code(uint32_t short_code, uint64_t *raw_code) noexcept {
|
|
|
|
if (!ShortCode::check(short_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*raw_code = RawCode::from_common_code(
|
|
|
|
CommonCode::from_short_code(ShortCode::unsafe_create(short_code))
|
|
|
|
).unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool raw_code_to_common_code(uint64_t raw_code, uint64_t *common_code) noexcept {
|
|
|
|
if (!RawCode::check(raw_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*common_code = CommonCode::from_raw_code(
|
|
|
|
RawCode::unsafe_create(raw_code)
|
|
|
|
).unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool common_code_to_raw_code(uint64_t common_code, uint64_t *raw_code) noexcept {
|
|
|
|
if (!CommonCode::check(common_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*raw_code = RawCode::from_common_code(
|
|
|
|
CommonCode::unsafe_create(common_code)
|
|
|
|
).unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool short_code_to_common_code(uint32_t short_code, uint64_t *common_code) noexcept {
|
|
|
|
if (!ShortCode::check(short_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*common_code = CommonCode::from_short_code(
|
|
|
|
ShortCode::unsafe_create(short_code)
|
|
|
|
).unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool common_code_to_short_code(uint64_t common_code, uint32_t *short_code) noexcept {
|
|
|
|
if (!CommonCode::check(common_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*short_code = ShortCode::from_common_code(
|
|
|
|
CommonCode::unsafe_create(common_code)
|
|
|
|
).unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
uint32_t raw_code_to_short_code_unsafe(uint64_t raw_code) noexcept {
|
|
|
|
return RawCode::unsafe_create(raw_code)
|
|
|
|
.to_common_code().to_short_code().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t short_code_to_raw_code_unsafe(uint32_t short_code) noexcept {
|
|
|
|
return ShortCode::unsafe_create(short_code)
|
|
|
|
.to_common_code().to_raw_code().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t raw_code_to_common_code_unsafe(uint64_t raw_code) noexcept {
|
|
|
|
return RawCode::unsafe_create(raw_code).to_common_code().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t common_code_to_raw_code_unsafe(uint64_t common_code) noexcept {
|
|
|
|
return CommonCode::unsafe_create(common_code).to_raw_code().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t short_code_to_common_code_unsafe(uint32_t short_code) noexcept {
|
|
|
|
return ShortCode::unsafe_create(short_code).to_common_code().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t common_code_to_short_code_unsafe(uint64_t common_code) noexcept {
|
|
|
|
return CommonCode::unsafe_create(common_code).to_short_code().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool is_vertical_mirror(uint64_t raw_code, bool *result) noexcept {
|
|
|
|
if (!RawCode::check(raw_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*result = RawCode::unsafe_create(raw_code).is_vertical_mirror();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_horizontal_mirror(uint64_t raw_code, bool *result) noexcept {
|
|
|
|
if (!RawCode::check(raw_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*result = RawCode::unsafe_create(raw_code).is_horizontal_mirror();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool to_vertical_mirror(uint64_t raw_code, uint64_t *result) noexcept {
|
|
|
|
if (!RawCode::check(raw_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*result = RawCode::unsafe_create(raw_code).to_vertical_mirror().unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool to_horizontal_mirror(uint64_t raw_code, uint64_t *result) noexcept {
|
|
|
|
if (!RawCode::check(raw_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*result = RawCode::unsafe_create(raw_code).to_horizontal_mirror().unwrap();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool is_vertical_mirror_unsafe(uint64_t raw_code) noexcept {
|
|
|
|
return RawCode::unsafe_create(raw_code).is_vertical_mirror();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_horizontal_mirror_unsafe(uint64_t raw_code) noexcept {
|
|
|
|
return RawCode::unsafe_create(raw_code).is_horizontal_mirror();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t to_vertical_mirror_unsafe(uint64_t raw_code) noexcept {
|
|
|
|
return RawCode::unsafe_create(raw_code).to_vertical_mirror().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t to_horizontal_mirror_unsafe(uint64_t raw_code) noexcept {
|
|
|
|
return RawCode::unsafe_create(raw_code).to_horizontal_mirror().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const uint32_t SHORT_CODE_STR_SIZE = 6;
|
|
|
|
|
|
|
|
bool short_code_to_string(uint32_t short_code, char short_code_str[]) noexcept {
|
|
|
|
if (!ShortCode::check(short_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string str = ShortCode::unsafe_create(short_code).to_string();
|
|
|
|
strcpy(short_code_str, str.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool short_code_from_string(const char short_code_str[], uint32_t *short_code) noexcept {
|
|
|
|
try {
|
|
|
|
*short_code = ShortCode::from_string(short_code_str).unwrap();
|
|
|
|
} catch (...) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const uint32_t COMMON_CODE_STR_SIZE = 10;
|
|
|
|
|
|
|
|
bool common_code_to_string(uint64_t common_code, char common_code_str[]) noexcept {
|
|
|
|
if (!CommonCode::check(common_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string str = CommonCode::unsafe_create(common_code).to_string(false);
|
|
|
|
strcpy(common_code_str, str.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool common_code_to_string_shorten(uint64_t common_code, char common_code_str[]) noexcept {
|
|
|
|
if (!CommonCode::check(common_code)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::string str = CommonCode::unsafe_create(common_code).to_string(true);
|
|
|
|
strcpy(common_code_str, str.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool common_code_from_string(const char common_code_str[], uint64_t *common_code) noexcept {
|
|
|
|
try {
|
|
|
|
*common_code = CommonCode::from_string(common_code_str).unwrap();
|
|
|
|
} catch (...) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|