-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompressed_board.hpp
66 lines (51 loc) · 1.85 KB
/
compressed_board.hpp
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
#pragma once
#include "defines.hpp"
struct compressed_row {
uint32_t data;
constexpr compressed_row() = default;
constexpr compressed_row(uint32_t data) : data{data} {}
constexpr compressed_row(row_type row) : data{} {
int32_t mul = 1e8;
for (auto i: row) {
data += i * mul;
mul /= 10;
}
}
constexpr operator row_type() const {
return {static_cast<std::uint8_t>((data / 100000000) % 10),
static_cast<std::uint8_t>((data / 10000000) % 10),
static_cast<std::uint8_t>((data / 1000000) % 10),
static_cast<std::uint8_t>((data / 100000) % 10),
static_cast<std::uint8_t>((data / 10000) % 10),
static_cast<std::uint8_t>((data / 1000) % 10),
static_cast<std::uint8_t>((data / 100) % 10),
static_cast<std::uint8_t>((data / 10) % 10),
static_cast<std::uint8_t>((data / 1) % 10)};
}
constexpr bool operator==(compressed_row other) const {
return data == other.data;
}
constexpr bool operator!=(compressed_row other) const {
return data != other.data;
}
};
struct compressed_board {
std::array<uint32_t, grid_size> data;
constexpr compressed_board() = default;
constexpr compressed_board(board_type board) : data{} {
for (int i = 0; i < grid_size; ++i)
data[i] = static_cast<compressed_row>(board[i]).data;
}
constexpr operator board_type() const {
board_type res;
for (int i = 0; i < grid_size; ++i)
res[i] = compressed_row{data[i]};
return res;
}
constexpr bool operator==(compressed_board const &other) const {
return data == other.data;
}
constexpr bool operator!=(compressed_board const &other) const {
return data != other.data;
}
};