-
Notifications
You must be signed in to change notification settings - Fork 0
/
bet.c
executable file
·159 lines (143 loc) · 5.73 KB
/
bet.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "bet.h"
//this function returns a cstring description of b
char* betType(bet* b, char* input)
{
int type = b->type;
if(type >= BET_0 && type <= BET_18)
{
input = "single number";
}
else if(type >= BET_ROW3 && type <= BET_ROW18)
{
input = "row";
}
else if(type == BET_ODD)
{
input = "odd";
}
else if(type <= BET_EVEN)
{
input = "even";
}
else if(type == BET_1TO9)
{
input = "1 to 9";
}
else if(type <= BET_10TO18)
{
input = "10 to 18";
}
return input;
}
//this function returns the payoff for a bet b, given a bet of size amount.
float payoff(bet* b, float amount)
{
int type = b->type;
if(type >= BET_0 && type <= BET_18)
{
return BET_0_PAYOFF;
}
else if(type >= BET_ROW3 && type <= BET_ROW18)
{
return BET_ROW3_PAYOFF;
}
else if(type >= BET_ODD && type <= BET_EVEN)
{
return BET_ODD_PAYOFF;
}
else if(type >= BET_1TO9 && type <= BET_10TO18)
{
return BET_1TO9_PAYOFF;
}
else
{
return -1;
}
}
//this function returns 1 if and only if the bet in b will return a payoff.
//hit is the value the ball landed on.
int didPayoff(bet* b, int hit)
{
int type = b->type;
switch(type)
{
case BET_0: return (hit == 0) ? 1 : 0; break;
case BET_1: return (hit == 1) ? 1 : 0; break;
case BET_2: return (hit == 2) ? 1 : 0; break;
case BET_3: return (hit == 3) ? 1 : 0; break;
case BET_4: return (hit == 4) ? 1 : 0; break;
case BET_5: return (hit == 5) ? 1 : 0; break;
case BET_6: return (hit == 6) ? 1 : 0; break;
case BET_7: return (hit == 7) ? 1 : 0; break;
case BET_8: return (hit == 8) ? 1 : 0; break;
case BET_9: return (hit == 9) ? 1 : 0; break;
case BET_10: return (hit == 10) ? 1 : 0; break;
case BET_11: return (hit == 11) ? 1 : 0; break;
case BET_12: return (hit == 12) ? 1 : 0; break;
case BET_13: return (hit == 13) ? 1 : 0; break;
case BET_14: return (hit == 14) ? 1 : 0; break;
case BET_15: return (hit == 15) ? 1 : 0; break;
case BET_16: return (hit == 16) ? 1 : 0; break;
case BET_17: return (hit == 17) ? 1 : 0; break;
case BET_18: return (hit == 18) ? 1 : 0; break;
case BET_ROW3: return (hit >= 1 && hit <= 3) ? 1 : 0; break;
case BET_ROW6: return (hit >= 4 && hit <= 6) ? 1 : 0; break;
case BET_ROW9: return (hit >= 7 && hit <= 9) ? 1 : 0; break;
case BET_ROW12: return (hit >= 10 && hit <= 12) ? 1 : 0; break;
case BET_ROW15: return (hit >= 13 && hit <= 15) ? 1 : 0; break;
case BET_ROW18: return (hit >= 16 && hit <= 18) ? 1 : 0; break;
case BET_ODD: return ((hit != 0) && !divisible(hit, 2)) ? 1 : 0; break;
case BET_EVEN: return ((hit != 0) && divisible(hit, 2)) ? 1 : 0; break;
case BET_1TO9: return (hit >= 1 && hit <= 9) ? 1 : 0; break;
case BET_10TO18: return (hit >= 10 && hit <= 18) ? 1 : 0; break;
default: return 0;
}
}
//this function returns 1 if and only if the bet in b will return a payoff.
//hit is the value the ball landed on.
float getPayoff(bet* b, int hit)
{
int type = b->type;
float amount = b->amount;
switch(type)
{
case BET_0: return (hit == 0) ? amount * BET_0_PAYOFF : 0; break;
case BET_1: return (hit == 1) ? amount * BET_1_PAYOFF : 0; break;
case BET_2: return (hit == 2) ? amount * BET_2_PAYOFF : 0; break;
case BET_3: return (hit == 3) ? amount * BET_3_PAYOFF : 0; break;
case BET_4: return (hit == 4) ? amount * BET_4_PAYOFF : 0; break;
case BET_5: return (hit == 5) ? amount * BET_5_PAYOFF : 0; break;
case BET_6: return (hit == 6) ? amount * BET_6_PAYOFF : 0; break;
case BET_7: return (hit == 7) ? amount * BET_7_PAYOFF : 0; break;
case BET_8: return (hit == 8) ? amount * BET_8_PAYOFF : 0; break;
case BET_9: return (hit == 9) ? amount * BET_9_PAYOFF : 0; break;
case BET_10: return (hit == 10) ? amount * BET_10_PAYOFF : 0; break;
case BET_11: return (hit == 11) ? amount * BET_11_PAYOFF : 0; break;
case BET_12: return (hit == 12) ? amount * BET_12_PAYOFF : 0; break;
case BET_13: return (hit == 13) ? amount * BET_13_PAYOFF : 0; break;
case BET_14: return (hit == 14) ? amount * BET_14_PAYOFF : 0; break;
case BET_15: return (hit == 15) ? amount * BET_15_PAYOFF : 0; break;
case BET_16: return (hit == 16) ? amount * BET_16_PAYOFF : 0; break;
case BET_17: return (hit == 17) ? amount * BET_17_PAYOFF : 0; break;
case BET_18: return (hit == 18) ? amount * BET_18_PAYOFF : 0; break;
case BET_ROW3: return (hit >= 1 && hit <= 3) ? amount * BET_ROW3_PAYOFF : 0; break;
case BET_ROW6: return (hit >= 4 && hit <= 6) ? amount * BET_ROW6_PAYOFF : 0; break;
case BET_ROW9: return (hit >= 7 && hit <= 9) ? amount * BET_ROW9_PAYOFF : 0; break;
case BET_ROW12: return (hit >= 10 && hit <= 12) ? amount * BET_ROW12_PAYOFF : 0; break;
case BET_ROW15: return (hit >= 13 && hit <= 15) ? amount * BET_ROW15_PAYOFF : 0; break;
case BET_ROW18: return (hit >= 16 && hit <= 18) ? amount * BET_ROW18_PAYOFF : 0; break;
case BET_ODD: return ((hit != 0) && !divisible(hit, 2)) ? amount * BET_ODD_PAYOFF : 0; break;
case BET_EVEN: return ((hit != 0) && divisible(hit, 2)) ? amount * BET_EVEN_PAYOFF : 0; break;
case BET_1TO9: return (hit >= 1 && hit <= 9) ? amount * BET_1TO9_PAYOFF : 0; break;
case BET_10TO18: return (hit >= 10 && hit <= 18) ? amount * BET_10TO18_PAYOFF : 0; break;
default: return 0;
}
}
int divisible(int a, int b)
{
while(a >= b)
{
a -= b;
}
return (a == 0);
}