-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
144 lines (143 loc) · 4.74 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "block.hpp"
#include "board.hpp"
#include "search.hpp"
#include <string_view>
#include <iostream>
#include "bench.hpp"
using namespace std;
bool _ = ios::sync_with_stdio(false);
template <reachability::block block, bool print=false, reachability::coord start=reachability::coord{4, 20}, unsigned init_rot=0>
array<double, 2> test(const BOARD &b, string_view name) {
using namespace reachability::search;
cout << "BOARD " << name << endl;
auto binary = binary_bfs<block, start, init_rot>(b);
auto ordinary = ordinary_bfs_without_binary(b, block, start, init_rot);
if (binary.size() != ordinary.size()) {
cout << " binary.size() != ordinary.size()" << endl;
cout << " binary.size() = " << binary.size() << endl;
cout << " ordinary.size() = " << ordinary.size() << endl;
}
for (size_t i = 0; i < min(binary.size(), ordinary.size()); ++i) {
if (binary[i] != ordinary[i]) {
cout << " binary[" << i << "] != ordinary[" << i << "]" << endl;
cout << to_string(binary[i], ordinary[i], b);
} else if (print) {
cout << " result[" << i << "]" << endl;
cout << to_string(binary[i], b);
}
}
auto binary_time = bench<1000000>([](auto b){ return binary_bfs<block, start, init_rot>(b); }, b);
cout << " binary : " << binary_time << " cycles" << endl;
auto ordinary_time = bench([](auto b){ return ordinary_bfs_without_binary(b, block, start, init_rot); }, b);
cout << " true ord: " << ordinary_time << " cycles" << endl;
return {binary_time, ordinary_time};
}
template <bool print=false, reachability::coord start=reachability::coord{4, 20}, unsigned init_rot=0>
array<double, 2> test(const BOARD &b, string_view name, char block) {
using namespace reachability::search;
using namespace reachability::blocks;
cout << "BOARD " << name << endl;
cout << " BLOCK " << block << endl;
auto binary = binary_bfs<SRS, start, init_rot>(b, block);
auto ordinary = ordinary_bfs_without_binary<SRS>(b, block, start, init_rot);
if (binary.size() != ordinary.size()) {
cout << " binary.size() != ordinary.size()" << endl;
cout << " binary.size() = " << binary.size() << endl;
cout << " ordinary.size() = " << ordinary.size() << endl;
}
for (size_t i = 0; i < min(binary.size(), ordinary.size()); ++i) {
if (binary[i] != ordinary[i]) {
cout << " binary[" << i << "] != ordinary[" << i << "]" << endl;
cout << to_string(binary[i], ordinary[i], b);
} else if (print) {
cout << " result[" << i << "]" << endl;
cout << to_string(binary[i], b);
}
}
auto binary_time = bench<1000000>([](auto b, auto block){ return binary_bfs<SRS, start, init_rot>(b, block); }, b, block);
cout << " binary : " << binary_time << " cycles" << endl;
auto ordinary_time = bench([](auto b, auto block){ return ordinary_bfs_without_binary<SRS>(b, block, start, init_rot); }, b, block);
cout << " true ord: " << ordinary_time << " cycles" << endl;
return {binary_time, ordinary_time};
}
int main() {
double binary_sum = 0, ordinary_sum = 0;
for (size_t i = 0; i < board_names.size(); ++i) {
for (char block : "IJLOSTZ"sv) {
auto [binary_time, ordinary_time] = test(boards[i], board_names[i], block);
binary_sum += binary_time;
ordinary_sum += ordinary_time;
}
}
cout << "TOTAL binary : " << binary_sum << " cycles" << endl;
cout << "TOTAL true ord: " << ordinary_sum << " cycles" << endl;
using namespace reachability::blocks;
constexpr auto lzt = merge_str({
"XXXX XXX ",
"XXXXX XXXX",
" X X",
" ",
" X ",
" XX X X",
"XXX X ",
"XX X X",
"X X ",
"XX XXXX X",
"X XX ",
"XX XXX ",
" X ",
" XXX ",
"XX X ",
"X X ",
"X X X",
"X XX X XX",
"XX XXXXXX",
});
test<SRS::Z, true>(lzt, "LZT");
constexpr auto farter1 = merge_str({
" X ",
"XXX X ",
" X",
" X X XX ",
" X ",
" X X X",
"X XXX ",
"X XX ",
" X ",
" X ",
" XX X X ",
"X XX ",
" X X ",
" X X ",
" X ",
"XX X X",
" X X ",
"X X ",
" XX ",
" X ",
" X ",
" XXX XX X ",
});
test<SRS::L, true, reachability::coord{1, 1}, 2>(farter1, "FARTER 1");
constexpr auto farter2 = merge_str({
" X ",
" X ",
" X XX ",
" X ",
" X ",
" X XX",
" X",
" X",
" X X",
" ",
" ",
" X ",
" ",
" ",
" X ",
" ",
" ",
" "
});
test<SRS::I, true, reachability::coord{7, 0}, 0>(farter2, "FARTER 2");
}