From ba401598ca2b3ab302d95f8a368baf1881eb462b Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 9 Apr 2023 20:24:06 +0800 Subject: [PATCH] update: check the order of group all cases --- src/klotski_core/ffi/tmain.cc | 68 ++++++--------------------------- src/klotski_core/group/group.cc | 25 +++--------- 2 files changed, 17 insertions(+), 76 deletions(-) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index cd2dd92..bc349fe 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -25,72 +25,28 @@ using klotski::BasicRanges; void tmain() { -// std::vector ok; -// for (auto &&c : AllCases::release()) { -// if (Group::type_id(c) == 123) { -// ok.emplace_back(c); -// } -// } -// std::cout << ok.size() << std::endl; - -// std::cout << Group::all_cases(123).size() << std::endl; -// std::vector err; -// auto ret = Group::all_cases(123); -// std::cout << ret.size() << std::endl; -// err.reserve(ret.size()); -// for (auto &&r : ret) { -// if (Group::type_id(r) != 123) { -// std::cout << r << std::endl; -// } -// err.emplace_back(r); -// } - // uint32_t sum = 0; // for (uint32_t type_id = 0; type_id < 204; ++type_id) { // sum += Group::all_cases(type_id).size(); -// auto tmp = Group::block_num(type_id); -// -// std::vector ranges; -// -// BasicRanges::generate(ranges, BasicRanges::generate_t { // generate target ranges -// .n1 = 16 - tmp.n_1x1 - (tmp.n_1x2 + tmp.n_2x1) * 2, /// space -> 00 -// .n2 = tmp.n_1x2, /// 1x2 -> 01 -// .n3 = tmp.n_2x1, /// 2x1 -> 10 -// .n4 = tmp.n_1x1, /// 1x1 -> 11 -// }); -// sum += ranges.size(); // } // std::cout << "sum = " << sum << std::endl; - - uint32_t sum = 0; for (uint32_t type_id = 0; type_id < 204; ++type_id) { - sum += Group::all_cases(type_id).size(); - } - std::cout << "sum = " << sum << std::endl; + std::vector codes; + std::vector codes_; + for (auto &&t : Group::all_cases(type_id)) { + codes.emplace_back(t.unwrap()); + codes_.emplace_back(t.unwrap()); + } + std::sort(codes.begin(), codes.end()); -// auto r = Group::block_num(123); - -// std::cout << (int)r.n_1x1 << " " << (int)r.n_1x2 << " " << (int)r.n_2x1 << std::endl; - -// std::cout << Group::type_id(r) << std::endl; - -// Group::block_num(CommonCode(0x1A9BF0C00)); -// Group::block_num(RawCode::from_common_code(0x1A9BF0C00)); - -// std::cout << std::endl; - -// Group::block_num(CommonCode(0x4FEA13400)); -// Group::block_num(RawCode::from_common_code(0x4FEA13400)); + if (codes != codes_) { + std::cout << type_id << std::endl; + } +// std::cout << (codes == codes_) << std::endl; -// for (auto &&common_code : AllCases::release()) { -// auto s1 = Group::block_num(common_code); -// auto s2 = Group::block_num(common_code.to_raw_code()); -// if (s1.n_1x1 != s2.n_1x1 || s1.n_1x2 != s2.n_1x2 || s1.n_2x1 != s2.n_2x1) { -// std::cout << "fuck" << std::endl; -// } -// } + } // auto cases = std::vector(); // auto common_codes = AllCases::release(); diff --git a/src/klotski_core/group/group.cc b/src/klotski_core/group/group.cc index 3439742..e316f1f 100644 --- a/src/klotski_core/group/group.cc +++ b/src/klotski_core/group/group.cc @@ -14,46 +14,34 @@ using klotski::Common::check_range; using klotski::Common::range_reverse; std::vector Group::all_cases(uint32_t type_id) { - auto tmp = block_num(type_id); - - std::vector ranges; - + std::vector ranges; // basic ranges of type_id BasicRanges::generate(ranges, BasicRanges::generate_t { // generate target ranges .n1 = 16 - tmp.n_1x1 - (tmp.n_1x2 + tmp.n_2x1) * 2, /// space -> 00 .n2 = tmp.n_1x2, /// 1x2 -> 01 .n3 = tmp.n_2x1, /// 2x1 -> 10 .n4 = tmp.n_1x1, /// 1x1 -> 11 }); - for (auto &range : ranges) { range = range_reverse(range); // basic ranges reversed } -// std::cout << ranges.size() << std::endl; - std::vector all_cases; - + // TODO: all_cases pre-allocated for (uint64_t head = 0; head < 15; ++head) { // address of 2x2 block /// head -> 0/1/2 / 4/5/6 / 8/9/10 / 12/13/14 if ((head & 0b11) == 0b11) { ++head; // skip invalid address } - /// head(4-bit) + basic-range(32-bit) --check--> valid cases for (auto &&range : ranges) { - if (!check_range(head, range)) { // case valid - all_cases.emplace_back(CommonCode::create( - - head << 32 | range_reverse(range) - - )); -// range_reverse(range); // release valid cases + all_cases.emplace_back(CommonCode::unsafe_create( + head << 32 | range_reverse(range) // release valid cases + )); } } } - return all_cases; } @@ -88,7 +76,4 @@ std::vector Group::group_cases(const RawCode &seed) { return result; } - - - } // namespace klotski