-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.h
76 lines (61 loc) · 1.6 KB
/
grid.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
#ifndef _HGOL_GRID_H_
#define _HGOL_GRID_H_
#include <stdint.h>
const int SIZE = 5;
const int ROWS = (2 * SIZE - 1);
const int COLS = ROWS;
const int GRID_ROW_SIZE[ROWS] = {5, 6, 7, 8, 9, 8, 7, 6, 5};
class Grid
{
public:
Grid();
bool cells[ROWS][COLS];
bool kill[ROWS][COLS];
bool spawn[ROWS][COLS];
static int rowLength(int i);
static bool cellExists(int i, int j);
void calculateEra();
void applyEra();
int eolCount() const;
uint32_t era() const;
uint32_t resets() const;
void reset();
const static int EOL_END = 78;
const static int EOL_TRIGGER = 75;
const static uint64_t EOL_GRID_FULL = 0x1fffffffffffffff;
const static uint64_t EOL_GRID_EMPTY = 0x0;
private:
void _calculateCell(int i, int j);
void _calculateEolCell(int i, int j);
void _applyCell(int i, int j);
int _countNeighbours(int i, int j);
int _neighboursFromSmallerRow(int i, int j, int len);
int _neighboursFromLargerRow(int i, int j);
// End of life detection.
const static int EOL_DETECT_LEN = 16;
uint32_t _era = 0;
uint64_t _eolEntries[EOL_DETECT_LEN] = {0};
int _eolCount = 0;
uint32_t _resets = 0;
void _updateEol();
uint64_t _currentEol();
};
class GridView
{
public:
virtual void update(const Grid *grid, float progress);
};
class CompoundGridView : public GridView
{
public:
CompoundGridView(GridView &a, GridView &b) : _a(a), _b(b) {}
void update(const Grid *grid, float progress)
{
_a.update(grid, progress);
_b.update(grid, progress);
}
private:
GridView &_a;
GridView &_b;
};
#endif