-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.h
68 lines (52 loc) · 1.19 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
#ifndef __CELL_H__
#define __CELL_H__
#include <unordered_set>
#include <vector>
#include <SFML/Graphics.hpp>
struct ViewInfo;
/**
* A cell as described in Conway's Game of Life.
*
* Just a container for the position and state.
*
* Defined in it's own file to avid cyclic includes
*/
class Cell {
public:
unsigned long x;
unsigned long y;
bool isAlive;
void
Draw(const ViewInfo& view,
sf::RenderTarget& texture,
sf::Color colour) const;
Cell(unsigned long x,
unsigned long y)
: x(x), y(y), isAlive(true) {}
Cell(unsigned long x,
unsigned long y,
bool isAlive)
: x(x), y(y), isAlive(isAlive) {}
Cell(const Cell& other)
: x(other.x), y(other.y), isAlive(other.isAlive) {}
Cell&
operator=(const Cell& other) {
x = other.x;
y = other.y;
isAlive = other.isAlive;
return *this;
}
bool
operator==(const Cell& other) const {
return x == other.x && y == other.y;
}
};
struct CellHash {
inline std::size_t
operator()(const Cell& cell) const {
// TODO: Better hash
return ((cell.x % UINT_MAX) * 31 + cell.y % UINT_MAX) % UINT_MAX;
}
};
typedef std::unordered_set<Cell, CellHash> CellSet;
#endif