-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.h
54 lines (51 loc) · 1.13 KB
/
cell.h
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
#ifndef CELL_H
#define CELL_H
class Cell {
public:
enum class CellState : unsigned char {
Closed,
Opened,
MarkedAsBomb,
MarkedAsQuestion
};
inline bool isMine() const
{
return data & 1;
}
inline unsigned char minesAround() const
{
return data >> 1 & 0b1111;
}
inline CellState cellState() const
{
return CellState(data >> 5 & 0b11);
}
inline void setMine(bool value = true)
{
if (value)
data |= 1;
else
data = data >> 1 << 1;
}
inline void setMinesAround(unsigned char value)
{
data &= ~0b11110;
value <<= 1;
data |= value;
}
inline void setCellState(CellState state)
{
unsigned char value = static_cast<unsigned char>(state);
data &= ~0b1100000;
value <<= 5;
data |= value;
}
private:
// CellState state; // 2 bits
// char minesAround; // 4 bits
// bool mine; // 1 bit
// reserved cellState minesAround isMine
// 0 00 0000 0
unsigned char data = 0;
};
#endif // CELL_H