-
Notifications
You must be signed in to change notification settings - Fork 3
/
Cell.h
125 lines (103 loc) · 2.47 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
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
#pragma once
#include <string>
//enum class CellState { Dead, Born, Live, Old, Dying, BrianDying } ;
//enum class CellState : unsigned char { Dead, Born, Live, Old, Dying, BrianDying };
class Cell
{
public:
enum class State : uint8_t { Dead, Born, Live, Old, Dying, BrianDying };
private:
State _state{ State::Dead };
uint8_t _neighbors{ 0 };
uint16_t _age{ 0 };
public:
Cell() = default;
~Cell() = default;
// move/copy constuct
Cell(Cell&& b) = default;
Cell(Cell& b) = default;
// no need to assign one cell to another cell
// TODO future, compare by age or Live/Dead
Cell& operator=(Cell&& b) = delete;
Cell& operator=(Cell& b) = delete;
[[nodiscard]] uint8_t Neighbors() const noexcept
{
return _neighbors;
}
void Neighbors(uint8_t n) noexcept
{
_neighbors = n;
}
void Age(uint16_t age) noexcept
{
_age = age;
}
void GetOlder() noexcept
{
_age++;
}
[[nodiscard]] uint16_t Age() const noexcept
{
return _age;
}
[[nodiscard]] State GetState() const noexcept
{
return _state;
}
void SetState(State state) noexcept
{
// if the state didn't change, do nothing
if (_state == state)
{
return;
}
_state = state;
if (state == State::Born)
{
_age = 0;
}
}
[[nodiscard]] bool ShouldDraw() const noexcept
{
if (_state == State::Live || _state == State::BrianDying)
{
return true;
}
return false;
}
[[nodiscard]] bool IsAlive() const noexcept
{
if (_state == State::Live || _state == State::Dying || _state == State::Old)
{
return true;
}
return false;
}
[[nodiscard]] bool IsAliveNotDying() const noexcept
{
if (_state == State::Live)
{
return true;
}
return false;
}
[[nodiscard]] bool IsDying() const noexcept
{
if (_state == State::Dying)
{
return true;
}
return false;
}
[[nodiscard]] bool IsDead() const noexcept
{
if (_state == State::Dead || _state == State::Born)
{
return true;
}
return false;
}
[[nodiscard]] const char* GetStateString() const noexcept;
[[nodiscard]] const std::wstring& GetEmojiStateString() const;
//void KillOldCell();
};