Browse Source

feat: type id index

master
Dnomd343 1 year ago
parent
commit
17c449af2d
  1. 12
      src/klotski_core/ffi/tmain.cc
  2. 47
      src/klotski_core/group/group.cc
  3. 2
      src/klotski_core/group/group.h
  4. 34
      src/klotski_core/group/type_id.h

12
src/klotski_core/ffi/tmain.cc

@ -23,6 +23,8 @@ using klotski::Benchmark;
void tmain() {
Group::block_num(123);
// Group::block_num(CommonCode(0x1A9BF0C00));
// Group::block_num(RawCode::from_common_code(0x1A9BF0C00));
@ -61,12 +63,12 @@ void tmain() {
// std::cout << ret[0] << std::endl;
// std::cout << ret[1] << std::endl;
auto tmp = RawCode::from_common_code(0x1A9BF0C00);
for (int i = 0; i < 100; ++i) {
Group::group_cases(tmp);
}
// auto tmp = RawCode::from_common_code(0x1A9BF0C00);
// for (int i = 0; i < 100; ++i) {
// Group::group_cases(tmp);
// }
std::cout << ((clock() - start) * 1000 / CLOCKS_PER_SEC) << "ms" << std::endl;
// std::cout << ((clock() - start) * 1000 / CLOCKS_PER_SEC) << "ms" << std::endl;
return;

47
src/klotski_core/group/group.cc

@ -5,10 +5,56 @@
#include "common.h"
#include "absl/container/flat_hash_map.h"
#include "type_id.h"
namespace klotski {
using Common::range_reverse;
Group::block_num_t Group::block_num(uint32_t type_id) {
// jiang_num (n_x2x)
// bing_num (n_1x1)
// style_num (n_2x1)
auto tids = std::vector<uint32_t>();
uint32_t count = 0;
for (int n_x2x = 0; n_x2x <= 7; ++n_x2x)
for (int n_2x1 = 0; n_2x1 <= n_x2x; ++n_2x1)
for (int n_1x1 = 0; n_1x1 <= (14 - n_x2x * 2); ++n_1x1) {
++count;
uint32_t tid = (n_x2x << 8) | (n_2x1 << 4) | n_1x1;
tids.emplace_back(tid);
std::cout << n_x2x << " " << n_1x1 << " " << n_2x1 << "(" << tid << ")" << std::endl;
}
// std::cout << count << std::endl;
// for (int i = 0; i < tids.size(); ++i) {
//
// printf("% 5d,", tids[i]);
//
// if ((i & 0b111) == 0b111) {
// printf("\n");
// }
// std::cout << tid << std::endl;
// }
// generate(generate_t { // generate target ranges
// .n1 = 16 - n * 2 - n_1x1, /// space -> 00
// .n2 = n - n_2x1, /// 1x2 -> 01
// .n3 = n_2x1, /// 2x1 -> 10
// .n4 = n_1x1, /// 1x1 -> 11
// });
return Group::block_num_t();
}
Group::block_num_t Group::block_num(const RawCode &raw_code) {
block_num_t result;
auto tmp = raw_code.unwrap();
@ -80,4 +126,5 @@ std::vector<RawCode> Group::group_cases(const RawCode &seed) {
} // namespace klotski

2
src/klotski_core/group/group.h

@ -15,7 +15,7 @@ public:
uint8_t n_2x1 = 0;
};
// static block_num_t block_num(uint32_t type_id);
static block_num_t block_num(uint32_t type_id);
static block_num_t block_num(const RawCode &raw_code);
static block_num_t block_num(const CommonCode &common_code);

34
src/klotski_core/group/type_id.h

@ -0,0 +1,34 @@
#pragma once
namespace klotski {
const uint16_t TYPE_ID[204] = {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 256,
257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 272, 273, 274, 275,
276, 277, 278, 279, 280, 281, 282, 283,
284, 512, 513, 514, 515, 516, 517, 518,
519, 520, 521, 522, 528, 529, 530, 531,
532, 533, 534, 535, 536, 537, 538, 544,
545, 546, 547, 548, 549, 550, 551, 552,
553, 554, 768, 769, 770, 771, 772, 773,
774, 775, 776, 784, 785, 786, 787, 788,
789, 790, 791, 792, 800, 801, 802, 803,
804, 805, 806, 807, 808, 816, 817, 818,
819, 820, 821, 822, 823, 824, 1024, 1025,
1026, 1027, 1028, 1029, 1030, 1040, 1041, 1042,
1043, 1044, 1045, 1046, 1056, 1057, 1058, 1059,
1060, 1061, 1062, 1072, 1073, 1074, 1075, 1076,
1077, 1078, 1088, 1089, 1090, 1091, 1092, 1093,
1094, 1280, 1281, 1282, 1283, 1284, 1296, 1297,
1298, 1299, 1300, 1312, 1313, 1314, 1315, 1316,
1328, 1329, 1330, 1331, 1332, 1344, 1345, 1346,
1347, 1348, 1360, 1361, 1362, 1363, 1364, 1536,
1537, 1538, 1552, 1553, 1554, 1568, 1569, 1570,
1584, 1585, 1586, 1600, 1601, 1602, 1616, 1617,
1618, 1632, 1633, 1634, 1792, 1808, 1824, 1840,
1856, 1872, 1888, 1904,
};
} // namespace klotski
Loading…
Cancel
Save