-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.h
53 lines (49 loc) · 1.57 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
#ifndef GRID_H
#define GRID_H
#include <ostream>
#include <vector>
#include "RNG.h"
#include <iostream>
#include <unistd.h>
#include <sys/time.h>
class Grid {
public:
Grid(double threshold = 0.5, int seed = (int) time(0));
~Grid();
struct GridEl {
unsigned int row;
unsigned int col;
GridEl* N;
GridEl* E;
GridEl* S;
GridEl* W;
unsigned int race;
bool happy, movable;
GridEl(unsigned int r, unsigned int c, unsigned int racevalue, GridEl* former, GridEl* next, GridEl* lower, GridEl* upper) :
row(r), col(c), race(racevalue), W(former), S(lower), N(upper), E(next), happy(false), movable(true) {}
};
void initiate(unsigned int gridSize);
void populate(double percentEmpty, unsigned int nRaces);
void drawPlot();
void simulate(unsigned int nMax, int plotAfter, int sleep = 10000);
void updateHappiness();
void move();
void countElements();
GridEl* next(GridEl* reference);
float timedifference_msec(struct timeval t0, struct timeval t1);
private:
double happinessThreshold;
unsigned int n, gridSize, nRaces, nMoves;
GridEl* head;
bool allHappy;
int moves;
std::vector<GridEl*> emptyPlaces;
RNG rng;// = RNG (12);
double findRatio(GridEl* reference);
std::vector<char> raceChars {' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
// timing purposes only
float totalSleep;
struct timeval t0, t1;
};
#endif