renamed the global variable r to hrngen; added a commentr about hrngen; fixed hrandom_shuffle in rogueviz-kohonen
This commit is contained in:
parent
e9c82a5005
commit
11d9d3de5a
17
game.cpp
17
game.cpp
|
@ -142,24 +142,29 @@ cellwalker cwt; // single player character position
|
|||
inline cell*& singlepos() { return cwt.c; }
|
||||
inline bool singleused() { return !(shmup::on || multi::players > 1); }
|
||||
|
||||
std::mt19937 r;
|
||||
// the main random number generator for the game
|
||||
// all the random calls related to the game mechanics (land generation, AI...) should use hrngen
|
||||
// random calls not related to the game mechanics (graphical effects) should not use hrngen
|
||||
// this ensures that the game should unfold exactly the same if given the same seed and the same input
|
||||
|
||||
std::mt19937 hrngen;
|
||||
|
||||
void shrand(int i) {
|
||||
r.seed(i);
|
||||
hrngen.seed(i);
|
||||
}
|
||||
|
||||
int hrandpos() { return r() & HRANDMAX; }
|
||||
int hrandpos() { return hrngen() & HRANDMAX; }
|
||||
|
||||
int hrand(int i) {
|
||||
return r() % i;
|
||||
return hrngen() % i;
|
||||
}
|
||||
|
||||
ld hrandf() {
|
||||
return (r() & HRANDMAX) / (HRANDMAX + 1.0);
|
||||
return (hrngen() & HRANDMAX) / (HRANDMAX + 1.0);
|
||||
}
|
||||
|
||||
int hrandstate() {
|
||||
std::mt19937 r2 = r;
|
||||
std::mt19937 r2 = hrngen;
|
||||
return r2() & HRANDMAX;
|
||||
}
|
||||
|
||||
|
|
|
@ -691,7 +691,7 @@ void describe(cell *c) {
|
|||
help += "\n";
|
||||
vector<pair<double, int>> v;
|
||||
for(int s=0; s<samples; s++) if(whowon[s] == n) v.emplace_back(vnorm(n->net, data[s].val), s);
|
||||
hrandom_shuffle(&v[0], isize(v));
|
||||
for(int i=1; i<isize(v); i++) swap(v[i], v[rand() % (i+1)]);
|
||||
sort(v.begin(), v.end(), [] (pair<double,int> a, pair<double,int> b) { return a.first < b.first; });
|
||||
|
||||
for(int i=0; i<isize(v) && i<20; i++) {
|
||||
|
|
Loading…
Reference in New Issue