-
Notifications
You must be signed in to change notification settings - Fork 2
/
Methods.txt
142 lines (129 loc) · 3.23 KB
/
Methods.txt
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
uint16_t Player::ThrowSingle(uint16_t d, const Board& board)
{
//return result of throwing for single d
//d is the score that the player is aiming for
srand(static_cast<unsigned int>(time(0)));
uint16_t r = (rand() % 100 + 1);
if (d == OUTER) // outer bull 80% accuracy
{
if (r <= 80) //80% chance
{
HitOuter = true;
return OUTER; //throw was successful
}
else if (r > 80 && r <= 90) //10% chance
{
HitBull = true;
return BULL; //red inner bull hit instead
}
else
{
return (rand() % 20 + 1); //return a random score between 1 and 20
}
}
else if (d == BULL) // outer bull 80% accuracy
{
if (r <= 80) //80% chance
{
HitBull = true;
return BULL; //throw was successful
}
else if (r > 80 && r <= 90) //10% chance
{
HitOuter = true;
return OUTER; //outer bull hit instead
}
else
{
return (rand() % 20 + 1); //return a random score between 1 and 20
}
}
else if (r <= 70) // 70% chance for 1 to 20 single
{
return d; //return score
}
else if (r > 70 && r <= 80) //10% chance for scoring left
{
return board.GetAtPosition(0,d); //return score to the left
}
else if (r > 80 && r <= 90 ) //10% chance for scoring right
{
return board.GetAtPosition(1,d); //return score to the right
}
else if (r > 90 && r <= 95) //5% chance for scoring double
{
HitDouble = true;
return 2 * d; //return double score
}
else //5% chance for scoring triple
{
HitTriple = true;
return 3 * d; //return triple score
}
}
uint16_t Player::ThrowDouble(uint16_t d, const Board& board)
{
//return result of throwing for single d
//d is the score that the player is aiming for
uint16_t r = (rand() % 100 + 1);
if (r <= 70) // 70% chance for double
{
HitDouble = true;
return 2 * d; //return double score
}
else if (r > 70 && r <= 80) //10% chance for scoring double left
{
return 2 * board.GetAtPosition(0, d); //return double score to the left
}
else if (r > 80 && r <= 90) //10% chance for scoring double right
{
return 2 * board.GetAtPosition(1, d); //return double score to the right
}
else //10% chance for scoring single
{
return d; //return single score
}
}
uint16_t Player::ThrowTriple(uint16_t d, const Board& board)
{
//return result of throwing for single d
//d is the score that the player is aiming for
uint16_t r = (rand() % 100 + 1);
if (r <= 70) // 70% chance for triple
{
return 3 * d; //return triple score
}
else if (r > 70 && r <= 80) //10% chance for scoring triple left
{
return 3 * board.GetAtPosition(0, d); //return triple score to the left
}
else if (r > 80 && r <= 90) //10% chance for scoring triple right
{
return 3 * board.GetAtPosition(1, d); //return triple score to the right
}
else if (r > 90 && r <= 95) //5% chance for scoring single left
{
return board.GetAtPosition(0, d);
}
else //5% chance for scoring single right
{
return board.GetAtPosition(1, d);
}
}
uint16_t Player::ThrowBull(uint16_t percentage)
{
// Throw for the bull with given accuracy
int r = (rand() % 100 + 1);
if (r <= percentage) //happens with custom percentage chance
{
return BULL;
}
else if (r > percentage && r < percentage + 20) //happens with 20% chance
{
return OUTER;
}
else //happens with left percentage
{
return (rand() % 20 + 1);
}
}