-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoalnumber.cpp
More file actions
40 lines (35 loc) · 969 Bytes
/
goalnumber.cpp
File metadata and controls
40 lines (35 loc) · 969 Bytes
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
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
int goalNumber(double attackPower1, double defencePower2);
int main() {
srand(time(NULL));
for (int i=0;i<100;i++)
printf("%d\n" , goalNumber(6000,3000));
}
int goalNumber(double attackPower1, double defencePower2) {
int m = (int) round(attackPower1 / defencePower2);
int goals[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
double odds[11] = {0};
double baze[11] = {0};
int i = 0;
for (i = 0; goals[i] != m; i++);
odds[i] = 1000;
for (int j = i + 1; j < 11; j++) {
odds[j] = odds[j - 1] * (0.2);
}
for (int j = i - 1; j >= 0; j--) {
odds[j] = odds[j + 1] * (0.3);
}
double sum=0;
baze[0] = odds[0];
for (int i = 1; i < 11; i++) {
baze[i] = baze[i - 1] + odds[i];
}
sum = baze[10];
int a = rand()%(int)(round(sum + 1)) ;
int j = 0;
for(j=0 ; a>baze[j] ;j++);
return goals[j];
}