mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 years ago
5 changed files with 89 additions and 2 deletions
@ -0,0 +1,4 @@ |
|||
cmake_minimum_required(VERSION 3.0) |
|||
|
|||
add_library(analyse analyse.cc) |
|||
target_link_libraries(analyse core) |
@ -0,0 +1,49 @@ |
|||
#include "core.h" |
|||
#include "analyse.h" |
|||
|
|||
#include <iostream> |
|||
|
|||
Core Analyse::new_core() { |
|||
return Core( |
|||
[this](auto &&code, auto &&mask) { // lambda as function pointer
|
|||
new_case(std::forward<decltype(code)>(code), std::forward<decltype(mask)>(mask)); |
|||
} |
|||
); |
|||
} |
|||
|
|||
void Analyse::start_analyse(uint64_t code) { |
|||
|
|||
auto core = new_core(); |
|||
|
|||
cases.empty(); |
|||
cache.empty(); |
|||
|
|||
cases.reserve(65536); |
|||
|
|||
cache.emplace(&cases.emplace(code, analyse_t { |
|||
.code = code, |
|||
.mask = 0, |
|||
}).first->second); |
|||
|
|||
while (!cache.empty()) { |
|||
|
|||
core.next_step(cache.front()->code, cache.front()->mask); |
|||
cache.pop(); |
|||
} |
|||
|
|||
std::cout << "size: " << cases.size() << std::endl; |
|||
|
|||
} |
|||
|
|||
void Analyse::new_case(uint64_t code, uint64_t mask) { |
|||
auto current = cases.find(code); |
|||
if (current != cases.end()) { // find existed case
|
|||
current->second.mask |= mask; // update mask info
|
|||
return; |
|||
} |
|||
|
|||
cache.emplace(&cases.emplace(code, analyse_t { |
|||
.code = code, |
|||
.mask = mask, |
|||
}).first->second); |
|||
} |
@ -0,0 +1,27 @@ |
|||
#pragma once |
|||
|
|||
#include <queue> |
|||
#include <cstdint> |
|||
#include <unordered_map> |
|||
|
|||
class Analyse { |
|||
public: |
|||
struct analyse_t { |
|||
uint64_t code; |
|||
uint64_t mask; |
|||
|
|||
// int step;
|
|||
// TODO: try set / unordered_set
|
|||
// std::list<analyse_t*> src;
|
|||
}; |
|||
|
|||
std::queue<analyse_t*> cache; |
|||
std::unordered_map<uint64_t, analyse_t> cases; |
|||
|
|||
inline Core new_core(); |
|||
|
|||
void start_analyse(uint64_t code); |
|||
|
|||
void new_case(uint64_t code, uint64_t mask); |
|||
|
|||
}; |
Loading…
Reference in new issue