forked from kroyee/SpeedBlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomizer.cpp
48 lines (40 loc) · 851 Bytes
/
randomizer.cpp
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
#include "randomizer.h"
#include <SFML/Graphics.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
short randomizer::getPiece() {
short returnpiece=0;
float piece = piece_dist(piece_gen);
for (int i=0; i<7; i++) {
piece-=cogP[i];
if (piece < 0) {
returnpiece = i;
break;
}
}
noP[returnpiece]++;
total++;
float adjust=(cogP[returnpiece]/4)*3;
cogP[returnpiece]-=adjust;
adjust/=6.0;
for (int i=0; i<7; i++)
if (i!=returnpiece)
cogP[i]+=adjust;
return returnpiece;
}
void randomizer::seedPiece(short seedNr) {
piece_gen.seed(seedNr);
}
short randomizer::getHole() {
return hole_dist(hole_gen);
}
void randomizer::seedHole(short seedNr) {
hole_gen.seed(seedNr);
}
void randomizer::reset() {
for (int i=0; i<7; i++) {
noP[i]=0;
cogP[i]=1000/7;
total=0;
}
}