-
Notifications
You must be signed in to change notification settings - Fork 0
/
roulette.c
49 lines (36 loc) · 1.02 KB
/
roulette.c
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
#include <math.h> // ceil
#include <stdlib.h> // free
#include "roulette.h"
#include "globals.h"
void recalculateRouletteStats(void){
int i;
recalculateLengthsSum();
overall_lengths_weights_sum = 0;
for(i = 0; i < mi_constant; ++i){
overall_lengths_weights[i] = overall_lengths_sum/overall_lengths[i];
overall_lengths_weights_sum += overall_lengths_weights[i];
}
}
void recalculateLengthsSum(void){
int i;
overall_lengths_sum = 0;
for(i = 0; i < mi_constant; ++i){
overall_lengths_sum += overall_lengths[i];
}
}
int getParentRoulette(unsigned *seed){
int x, i = 0;
float sum = 0;
x = rand_my(seed) % (int)ceil(overall_lengths_weights_sum);
//TODO jest rozjazd miedzy trzymana suma a faktyczna - tylko czemu?
// for(y = 0; y < mi_constant; ++y){
// sum += overall_lengths[y];
// }
// printf("%d, %f\n",x,overall_lengths_sum - sum);
// sum = 0;
while(sum < x && i < mi_constant){
sum += overall_lengths_weights[i];
++i;
}
return i-1<0?0:i-1;
}