Browse Source

update: fix several warnings

master
Dnomd343 1 year ago
parent
commit
e4069422f8
  1. 4
      src/CMakeLists.txt
  2. 2
      src/all_cases/all_cases.cc
  3. 28
      src/common_code/common_code.cc
  4. 4
      src/core/core.cc
  5. 7
      src/core/core.h
  6. 2
      src/fast_cal/fast_cal.cc
  7. 14
      src/main.cc

4
src/CMakeLists.txt

@ -23,7 +23,7 @@ add_subdirectory(short_code)
add_subdirectory(common_code)
add_subdirectory(core)
add_subdirectory(analyse)
#add_subdirectory(analyse)
add_subdirectory(fast_cal)
################################################
@ -40,7 +40,7 @@ target_link_libraries(klotski short_code)
target_link_libraries(klotski common_code)
target_link_libraries(klotski core)
target_link_libraries(klotski analyse)
#target_link_libraries(klotski analyse)
target_link_libraries(klotski fast_cal)
target_link_libraries(klotski pthread)

2
src/all_cases/all_cases.cc

@ -44,7 +44,7 @@ void AllCases::build_data() { // find all cases
/// head -> 0/1/2 / 4/5/6 / 8/9/10 / 12/13/14
data[head].reserve(ALL_CASES_SIZE[head]); // memory pre-allocated
/// head(4-bits) + basic ranges(32-bits) ==check==> release valid cases
for (auto index = 0; index < basic_ranges.size(); ++index) {
for (uint32_t index = 0; index < basic_ranges.size(); ++index) {
auto broken_offset = Common::check_range(head, basic_ranges[index]);
if (broken_offset) { // case invalid
auto delta = (uint32_t)1 << (32 - broken_offset * 2); // delta to next possible range

28
src/common_code/common_code.cc

@ -51,30 +51,32 @@ bool CommonCode::check(uint64_t common_code) { // whether common code is valid
uint32_t mask = M_2x2 << head; // fill 2x2 block
auto range = Common::range_reverse((uint32_t)common_code);
for (int addr = 0;; range >>= 2) { // traverse every 2-bits
while (mask >> addr & 0b1) {
while ((mask >> addr) & 0b1) {
++addr; // search next unfilled block
}
if (addr >= 20) {
return !range && space_num > 1; // empty range and >= 2 space
}
switch (range & 0b11) {
case 0b00: // space
case 0b00: /// space
mask |= M_1x1 << addr; // fill space
++space_num;
case 0b11: // 1x1 block
mask |= M_1x1 << addr; // fill space or 1x1 block
break;
case 0b10: // 2x1 block
if (addr > 15 || mask >> (addr + 4) & 0b1) { // invalid address
return false;
continue;
case 0b11: /// 1x1 block
mask |= M_1x1 << addr; // fill 1x1 block
continue;
case 0b10: /// 2x1 block
if (addr > 15 || mask >> (addr + 4) & 0b1) {
return false; // invalid address
}
mask |= M_2x1 << addr; // fill 2x1 block
break;
case 0b01: // 1x2 block
if ((addr & 0b11) == 0b11 || mask >> (addr + 1) & 0b1) { // invalid address
return false;
continue;
case 0b01: /// 1x2 block
if ((addr & 0b11) == 0b11 || mask >> (addr + 1) & 0b1) {
return false; // invalid address
}
mask |= M_1x2 << addr; // fill 1x2 block
break;
continue;
}
}
}

4
src/core/core.cc

@ -147,7 +147,7 @@ void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block
}
}
void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases
void Core::next_cases(uint64_t code, uint64_t mask) { // search next step cases
cache[0].filter = 0; // without filter
cache[0].code = code; // bfs root code
auto range = code | mask;
@ -171,7 +171,7 @@ void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases
}
if (cache_size != 1) { // found one or more next cases
for (int i = 1; i < cache_size; ++i) {
release(cache[i].code, cache[i].mask); // release next cases
Core::release(cache[i].code, cache[i].mask); // release next cases
}
cache_size = 1; // reset cache size
}

7
src/core/core.h

@ -11,9 +11,11 @@
class Core {
public:
/// Release with code and mask
typedef std::function<void(uint64_t, uint64_t)> release_t;
void next_step(uint64_t code, uint64_t mask);
/// Core interface
void next_cases(uint64_t code, uint64_t mask);
explicit Core(release_t release_func) : release(std::move(release_func)) {}
private:
@ -26,12 +28,11 @@ private:
int cache_size = 1;
cache_t cache[16]{};
release_t release; // release code and mask
release_t release; // release function
void move_1x1(uint64_t code, int addr);
void move_1x2(uint64_t code, int addr);
void move_2x1(uint64_t code, int addr);
void move_2x2(uint64_t code, int addr);
inline void cache_insert(Core::cache_t &next_case);
};

2
src/fast_cal/fast_cal.cc

@ -79,7 +79,7 @@ void FastCal::fast_cal(uint64_t code) {
break;
}
core.next_step(cache.front()->code, cache.front()->mask);
core.next_cases(cache.front()->code, cache.front()->mask);
cache.pop();
}

14
src/main.cc

@ -23,7 +23,11 @@ int main() {
// std::cout << "start benchmark" << std::endl;
auto start_time = clock();
AllCases::build();
for (uint32_t common_code = 0x10000000; common_code < 0x20000000; ++common_code) {
CommonCode::check(common_code);
}
// AllCases::build();
// auto raw_code = CommonCode("1a9bf0c").to_raw_code().unwrap();
@ -75,10 +79,10 @@ int main() {
// std::cout << ShortCode("EP4HZ") << std::endl;
// std::cout << ShortCode(14323231) << std::endl;
std::cout << RawCode::from_common_code("4fea134") << std::endl;
std::cout << CommonCode::from_raw_code(0xE58FC85FFEBC4DB) << std::endl;
std::cout << ShortCode::from_common_code("4fea134") << std::endl;
std::cout << CommonCode::from_short_code("AXCZN") << std::endl;
// std::cout << RawCode::from_common_code("4fea134") << std::endl;
// std::cout << CommonCode::from_raw_code(0xE58FC85FFEBC4DB) << std::endl;
// std::cout << ShortCode::from_common_code("4fea134") << std::endl;
// std::cout << CommonCode::from_short_code("AXCZN") << std::endl;
// std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl;

Loading…
Cancel
Save