-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerate2048rowLooks.cpp
More file actions
50 lines (44 loc) · 1.43 KB
/
Copy pathGenerate2048rowLooks.cpp
File metadata and controls
50 lines (44 loc) · 1.43 KB
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
#include <cstdint>
#include <fstream>
#include <iostream>
uint16_t row_moves[65536];
void compress(uint16_t& num) {
for (int slot = 4; slot < 13; slot += 4) {
const auto extracted = 15 & (num >> slot);
for (int slot2 = 0; slot2 < 9; slot2 += 4) {
if ((15 & (num >> slot2)) == 0) {
num |= extracted << slot2;
num &= ~(15ULL << slot);
break;
}
}
}
}
void merge(uint16_t& num) {
auto right = 15 & (num >> 4), left = 15 & (num >> 8);
if ((right == (15 & num)) && (right != 0)) {
num++;
num &= ~(15ULL << 4);
right = 15 & (num >> 4);
} if ((right == left) && (right != 0)) {
num += 16;
num &= ~(15ULL << 8);
left = 15 & (num >> 8);
} if ((left == (15 & (num >> 12))) && (left != 0)) {
num += 256;
num &= ~(15ULL << 12);
}
}
int main() {
for (int input = 0; input <= UINT16_MAX; input++) {
uint16_t input1 = input;
compress(input1); merge(input1); compress(input1);
row_moves[input] = input1;
}
std::ofstream out("row_moved.bin", std::ios::binary);
if (!out) {std::cerr << "\nError 101: File Could Not Be Created"; return -1;}
out.write(reinterpret_cast<const char*>(row_moves), sizeof(uint16_t) * 65536);
out.close();
std::cout << "\nAuthored by C++";
return 0;
}