Browse Source

update: AllCases class interface

master
Dnomd343 2 years ago
parent
commit
4062d468c0
  1. 24
      klotski/all_cases.cc
  2. 10
      klotski/all_cases.h
  3. 8
      klotski/main.cc

24
klotski/all_cases.cc

@ -93,6 +93,30 @@ void AllCases::build_basic_ranges() { // build basic ranges
}
}
void AllCases::find_all_cases() { // find all valid cases
get_basic_ranges(); // ensure basic ranges exist
for (uint32_t head = 0; head < 16; ++head) { // address of 2x2 block
if ((head & 0b11) == 0b11) {
continue; // invalid 2x2 address
}
for (uint32_t range : basic_ranges) { // check base on 2x2 address and range
if (Common::check_case(head, range)) {
all_cases[head].emplace_back(Common::range_reverse(range)); // found valid case
}
}
}
}
const std::vector<uint32_t>* AllCases::get_basic_ranges() {
if (basic_ranges.empty()) {
build_basic_ranges(); // basic ranges initialize
}
return &basic_ranges;
}
const std::vector<uint32_t> (*AllCases::get_all_cases())[16] {
if (all_cases->empty()) {
find_all_cases(); // all cases initialize
}
return &all_cases;
}

10
klotski/all_cases.h

@ -6,16 +6,14 @@
class AllCases {
public:
// AllCases() {}
// void find_all_cases();
void build_basic_ranges();
const std::vector<uint32_t>* get_basic_ranges();
const std::vector<uint32_t> (*get_all_cases())[16];
private:
// std::vector<uint32_t> all_cases[16];
std::vector<uint32_t> basic_ranges;
std::vector<uint32_t> all_cases[16];
// void load_basic_ranges();
void find_all_cases();
void build_basic_ranges();
void generate_ranges(int n1, int n2, int n3, int n4);
};

8
klotski/main.cc

@ -4,10 +4,12 @@
int main() {
auto a = AllCases();
a.build_basic_ranges();
auto br = a.get_basic_ranges();
std::cout << br->size() << std::endl;
std::cout << "basic range size: " << a.get_basic_ranges()->size() << std::endl;
for (const auto &temp : *a.get_all_cases()) {
std::cout << temp.size() << std::endl;
}
return 0;
}

Loading…
Cancel
Save