-
Notifications
You must be signed in to change notification settings - Fork 0
/
city.hpp
128 lines (118 loc) · 3.39 KB
/
city.hpp
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
126
127
128
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <random>
using namespace std;
const int cityxsize = 11;
const int cityysize = 13;
char citygrid[cityysize]
[cityxsize]; // so much headache all from the mandate that this be
// a c-array, as opposed to vectory of arbitrary data
vector<Robber<Jewel>> cityrobbers;
vector<Jewel> cityjewels;
vector<Police> rollapd;
int totalvalrobbers;
int toalvalpolice;
class City {
public:
bool fiftyFifty() { // rand was just not working very well. so we're doing
// this now.
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(0, 1);
int result = dis(gen);
return result == 0;
}
// char citygrid[cityysize][cityxsize]; //so much headache all from the
// mandate that this be a c-array, as opposed to vectory of arbitrary data
City() {
Jewel hold(0, 0, 0);
// replace all of our nulls with zeroes.
for (int i = 0; i < cityysize; i++) {
for (int k = 0; k < cityxsize; k++) {
citygrid[i][k] = '0';
}
}
// now to make 60 random Jewel's
for (int i = 0; i < cityysize; i++) {
for (int k = 0; k < cityxsize; k++) {
if (cityjewels.size() < 60 && fiftyFifty() && citygrid[i][k] == '0') {
citygrid[i][k] = 'J';
hold.ycord = i;
hold.xcord = k;
hold.jval = pow((i + k), 2);
cityjewels.push_back(hold);
}
}
}
// cout<<"added "<<cityjewels.size() <<" jewels."<<endl;
// now to make our robbers
Robber<Jewel> jango;
for (int i = 0; i < cityysize; i++) {
for (int k = 0; k < cityxsize; k++) {
if (cityrobbers.size() < 5 && fiftyFifty() && citygrid[i][k] == '0') {
citygrid[i][k] = 'r';
jango.id = rand();
jango.ycord = i;
jango.xcord = k;
jango.active = 1;
if (cityrobbers.size() <= 2) {
jango.type = 0;
}
if (cityrobbers.size() > 2) {
jango.type = 1;
}
cityrobbers.push_back(jango);
}
}
}
// now to make our police.
Police wigum;
for (int i = 0; i < cityysize; i++) {
for (int k = 0; k < cityxsize; k++) {
if (rollapd.size() < 3 && fiftyFifty() && citygrid[i][k] == '0') {
citygrid[i][k] = 'p';
wigum.ycord = i;
wigum.xcord = k;
wigum.id = rand();
rollapd.push_back(wigum);
}
}
}
}
void renderCity() {
int numj = 0;
int numrb = 0;
int numpd = 0;
for (int i = 0; i < cityysize; i++) {
for (int f = 0; f < cityxsize; f++) {
cout << citygrid[i][f];
switch (citygrid[i][f]) {
case 'J':
numj++;
break;
case 'r':
numrb++;
break;
case 'p':
numpd++;
break;
case 'R':
int sconchtitan = 0;
for (unsigned int z = 0; z < cityrobbers.size(); z++) {
if (cityrobbers.at(z).xcord == f && cityrobbers.at(z).ycord == i) {
sconchtitan++;
}
}
numrb += sconchtitan;
};
}
cout << flush << endl;
}
cout << "jewels(J): " << numj << endl;
cout << "robbers(r): " << numrb << endl;
cout << "cops(p): " << numpd << endl;
cout << "multiple robbers at same house(R)" << endl;
}
};