forked from ShaneFerrell/Dice-Roller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice_roller.c
362 lines (356 loc) · 6.51 KB
/
dice_roller.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// Shane Ferrell
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
//this function rolls dice
uint32_t roll_dice( uint32_t number_of_dice, uint32_t sides)
{
uint32_t roll = 0, sum = 0;
for (uint32_t i = 0; i < number_of_dice; i++)
{
do
{
roll = ((rand() % sides) + 1);
sum += roll;
} while(roll == sides);
}
return sum;
}
//this function tells how many dices to roll which dice.
uint32_t step(uint32_t step)
{
switch(step)
{
case 1:
{
return (roll_dice(1, 4) - 2);
}
case 2:
{
return (roll_dice(1, 4) - 1);
}
case 3:
{
return roll_dice(1, 4);
}
case 4:
{
return roll_dice(1, 6);
}
case 5:
{
return roll_dice(1, 8);
}
case 6:
{
return roll_dice(1, 10);
}
case 7:
{
return roll_dice(1, 12);
}
case 8:
{
return roll_dice(2, 6);
}
case 9:
{
return (roll_dice(1, 8) + roll_dice(1, 6));
}
case 10:
{
return roll_dice(2, 8);
}
case 11:
{
return (roll_dice(1, 10) + roll_dice(1, 6));
}
case 12:
{
return roll_dice(2, 10);
}
case 13:
{
return (roll_dice(1, 12) + roll_dice(1, 10));
}
case 14:
{
return roll_dice(1, 12);
}
case 15:
{
return (roll_dice(1, 12) + roll_dice(2, 6));
}
case 16:
{
return (roll_dice(1, 12) + roll_dice(1, 8) + roll_dice(1, 6));
}
case 17:
{
return (roll_dice(1, 12) + roll_dice(2, 8));
}
case 18:
{
return (roll_dice(1, 12) + roll_dice(1, 10) + roll_dice(1, 8));
}
case 19:
{
return (roll_dice(1, 20) + roll_dice(2, 6));
}
case 20:
{
return (roll_dice(1, 20) + roll_dice(1, 8) + roll_dice(1, 6));
}
case 21:
{
return (roll_dice(1, 20) + roll_dice(2, 8));
}
case 22:
{
return (roll_dice(1, 20) + roll_dice(1, 10) + roll_dice(1, 8));
}
case 23:
{
return (roll_dice(1, 20) + roll_dice(2, 10));
}
case 24:
{
return (roll_dice(1, 20) + roll_dice(1, 12) + roll_dice(1, 10));
}
case 25:
{
return (roll_dice(1, 20) + roll_dice(2, 12));
}
case 26:
{
return (roll_dice(1, 20) + roll_dice(1, 12) + roll_dice(2, 6));
}
case 27:
{
return (roll_dice(1, 20) + roll_dice(1, 12) + roll_dice(1, 8) + roll_dice(1, 6));
}
case 28:
{
return (roll_dice(1, 20) + roll_dice(1, 12) + roll_dice(2, 8));
}
case 29:
{
return (roll_dice(1, 20) + roll_dice(1, 12) + roll_dice(1, 10) + roll_dice(1, 8));
}
case 30:
{
return (roll_dice(2, 20) + roll_dice(2, 6));
}
case 31:
{
return (roll_dice(2, 20) + roll_dice(1, 8) + roll_dice(1, 6));
}
case 32:
{
return (roll_dice(2, 20) + roll_dice(2, 8));
}
case 33:
{
return (roll_dice(2, 20) + roll_dice(1, 10) + roll_dice(1, 8));
}
case 34:
{
return (roll_dice(2, 20) + roll_dice(2, 10));
}
case 35:
{
return (roll_dice(2, 20) + roll_dice(1, 12) + roll_dice(1, 10));
}
case 36:
{
return (roll_dice(2, 20) + roll_dice(2, 12));
}
case 37:
{
return (roll_dice(2, 20) + roll_dice(1, 12) + roll_dice(2, 6));
}
case 38:
{
return (roll_dice(2, 20) + roll_dice(1, 12) + roll_dice(1, 8) + roll_dice(1, 6));
}
case 39:
{
return (roll_dice(2, 20) + roll_dice(1, 12) + roll_dice(2, 8));
}
case 40:
{
return (roll_dice(2, 20) + roll_dice(1, 12) + roll_dice(1, 10) + roll_dice(1, 8));
}
case 41:
{
return roll_dice(3, 20) + roll_dice(3, 6);
}
case 42:
{
return roll_dice(3, 20) + roll_dice(2, 8) + roll_dice(2, 6);
}
case 43:
{
return roll_dice(3, 20) + roll_dice(3, 8);
}
case 44:
{
return roll_dice(3, 20) + roll_dice(2, 10) + roll_dice(2, 8);
}
case 45:
{
return roll_dice(3, 20) + roll_dice(3, 10);
}
case 46:
{
return roll_dice(3, 20) + roll_dice(2, 12) + roll_dice(2, 10);
}
case 47:
{
return roll_dice(3, 20) + roll_dice(3, 12);
}
case 48:
{
return roll_dice(3, 20) + roll_dice(3, 20) + roll_dice(2, 12) + roll_dice(3, 6);
}
case 49:
{
return roll_dice(3, 20) + roll_dice(2, 12) + roll_dice(2, 8) + roll_dice(2, 6);
}
case 50:
{
return roll_dice(3, 20) + roll_dice(2, 12) + roll_dice(3, 8);
}
case 51:
{
return roll_dice(3, 20) + roll_dice(2, 12) + roll_dice(2, 10) + roll_dice(2, 8);
}
case 52:
{
return roll_dice(4, 20) + roll_dice(4, 6);
}
case 53:
{
return roll_dice(4, 20) + roll_dice(3, 8) + roll_dice(3, 6);
}
case 54:
{
return roll_dice(4, 20) + roll_dice(4, 8);
}
case 55:
{
return roll_dice(4, 20) + roll_dice(3, 10) + roll_dice(3, 8);
}
case 56:
{
return roll_dice(4, 20) + roll_dice(4, 10);
}
case 57:
{
return roll_dice(4, 20) + roll_dice(3, 12) + roll_dice(3, 10);
}
case 58:
{
return roll_dice(4, 20) + roll_dice(4, 12);
}
case 59:
{
return roll_dice(4, 20) + roll_dice(3, 12) + roll_dice(4, 6);
}
case 60:
{
return roll_dice(4, 20) + roll_dice(3, 12) + roll_dice(3, 8);
}
case 61:
{
return roll_dice(4, 20) + roll_dice(3, 12) + roll_dice(4, 8);
}
case 62:
{
return roll_dice(4, 20) + roll_dice(3, 12) + roll_dice(3, 10) + roll_dice(3, 8);
}
case 63:
{
return roll_dice(5, 20) + roll_dice(5, 6);
}
case 64:
{
return roll_dice(5, 20) + roll_dice(4, 8) + roll_dice(4, 6);
}
case 65:
{
return roll_dice(5, 20) + roll_dice(5, 8);
}
case 66:
{
return roll_dice(5, 20) + roll_dice(4, 10) + roll_dice(4, 8);
}
case 67:
{
return roll_dice(5, 20) + roll_dice(5, 10);
}
case 68:
{
return roll_dice(5, 20) + roll_dice(4, 12) + roll_dice(4, 10);
}
case 69:
{
return roll_dice(5, 20) + roll_dice(5, 12);
}
case 70:
{
return roll_dice(5, 20) + roll_dice(4, 12) + roll_dice(4, 6);
}
case 71:
{
return roll_dice(5, 20) + roll_dice(4, 12) + roll_dice(4, 8) + roll_dice(4, 6);
}
case 72:
{
return roll_dice(5, 20) + roll_dice(4, 12) + roll_dice(5, 8);
}
case 73:
{
return roll_dice(5, 20) + roll_dice(4, 12) + roll_dice(4, 10) + roll_dice(4, 8);
}
case 74:
{
return roll_dice(6, 20) + roll_dice(6, 6);
}
case 75:
{
return roll_dice(6, 20) + roll_dice(5, 8) + roll_dice(5, 6);
}
case 76:
{
return roll_dice(6, 20) + roll_dice(6, 8);
}
case 77:
{
return roll_dice(6, 20) + roll_dice(5, 10) + roll_dice(5, 8);
}
case 78:
{
return roll_dice(6, 20) + roll_dice(6, 10);
}
case 79:
{
return roll_dice(6, 20) + roll_dice(5, 12) + roll_dice(5, 10);
}
case 80:
{
return roll_dice(6, 20) + roll_dice(6, 12);
}
default:
{
return 0;
}
}
}
//main function rolls dice according to the arguments
int main(int argc, char *argv[])
{
srand(time(0));
printf("%d\n", step(atoi(argv[1])));
return 1;
}