-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_project_v3.cpp
More file actions
1044 lines (875 loc) · 26 KB
/
Copy pathmini_project_v3.cpp
File metadata and controls
1044 lines (875 loc) · 26 KB
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// the goal of this is to build a working serve tracker for volleyball players
// using a map I will assign each player a vert, standing reach, and serve type.
// I will use random number to pick their serve type if they have multiple serves.
// 1) return the starting line up of each team
// 2) have a map between players and serve represented by 1 for top, 2 for float, 3 for either, 4 for hybrid which adds confusion but hard to execute
// 3) use the serve code to see if they serve in, out or ace
// 4) if they serve in, use the quality of the serve to determine who wins the rally with a random number generator
// 5) make this a loop until one team wins 25 points and is ahead by 2 points
// 6) have a way to keep track of the score and display it after each rally
// 7) have a way to keep track of the number of aces, errors, and points scored by each player
// 8) coin flip to determine which team serves first
#include <iostream>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <que>
#include <algorithm>
#include <iterator>
#include <utility>
#include <cmath>
using namespace std;
struct players {
string team;
string name;
string position;
int spikeHeight;
int serveType;
int maxPower;
};
/* ex Jpn_1;
jpn1.team = japan
jpn1.name = mashahiro Seketa
jpn1.position = setter
jpn1.spikeHeight = 128
jpn1.servetype = 3
jpn1.maxPower = 95
*/
vector<players> loadPlayers()
{
vector<players> roster;
ifstream myfile("player_data.csv");
if (!myfile.is_open())
{
cout << "Could not open player_data.csv\n";
return roster;
}
string line;
// Skip header
getline(myfile, line);
while (getline(myfile, line))
{
stringstream ss(line);
players p;
string temp;
getline(ss, p.team, ',');
getline(ss, p.name, ',');
getline(ss, p.position, ',');
getline(ss, temp, ',');
p.spikeHeight = stoi(temp); //turns string to int
getline(ss, temp, ',');
p.serveType = stoi(temp);
getline(ss, temp, ',');
p.maxPower = stoi(temp);
// this will add these strings to a vector p using the player class and
// assoliate each var to the name then push them back to use p for the next one
roster.push_back(p);
}
myfile.close();
return roster;
}
int teamLineUp(const string& y, const vector<players>& roster, vector<string> V0)
{
// check if player team == string y
// if yes add to line up vector if no skip
// print final line up vector
cout << "introducing your starting line up for team " << y << endl;
for (int i = 0; i < roster.size(); i++)
{
if (roster[i].team == y)
{
V2.push_back(roster[i]);
std::cout << roster[i].name << " " << roster[i].position << std::endl;
}
}
cout << endl;
return 0;
}
int teamSelect(const vector<players>& roster, vector<string> V2, vector<string> V1, vector<string> V0)
{
// reference CVS file for player names and serve types
// ask for what team is playing by printing an array of teams
// user picks team then removes that team from the array and prints the remaining teams
// user picks the second team and then the program prints the starting line up of each team
vector<string> team = {"italy","brazil","japan","USA","poland"};
cout << "wow, your about to watch the vnl FINALS! " ;
cout << "What team are you supporting?" ;
cout << "(" ;
for (const std::string& s : team)
{
std::cout << s << " ";
}
cout << ")" ;
string team1;
cin >> team1;
cout << "what team are they playing against" ;
cout << "(" ;
// Finds and erases the chosen team from the vector
team.erase(remove(team.begin(), team.end(), team1), team.end());
// Prints the remaining 4 teams to the console
for (const std::string& s : team)
{
std::cout << s << " ";
}
cout << ")" << endl;
string team2;
cin >> team2;
teamLineUp(team1,roster);
V1 = std::move(V0);
teamLineUp(team2,roster);
V2 = std::move(V0);
return 0;
}
players getServer(V1, V2)
{
que<players> order;
int coin = rand() % 2 + 1; // generates a random number between 1 and 2
if (coin == 1)
{
for (int i = 0; i <8 ; i++)
{
order.push(V1[i])
order.push(V2[i])
}
}
if (coin == 2)
{
for (int i = 0; i <8 ; i++)
{
order.push(V2[i])
order.push(V1[i])
}
}
return order;
}
int floater(int h, int v )
{
int angle = rand() % 11 ; // generates a random number between 10 and 0
float O = angle * 3.14159f / 180.0f; // convert angle to radians for trig functions
float g = 9.8f // gravity
float k = 0.0385f // drag constant
float e =2.718281f
float y_at_30m = h + (tan(O) / k) * (exp(k * x) - 1) - (g / 2.0f) * pow((exp(k * x) - 1) / (k * v), 2);
// A,B,C, and discriminate is just used to calculate where the ball lands with x1 & x2
float A = -g / (2.0f * pow(k, 2) * pow(v, 2));
float B = tan(O) / k + g / (pow(k, 2) * pow(v, 2));
float C = h - tan(O) / k - g / (2.0f * pow(k, 2) * pow(v, 2));
float discriminant = pow(B, 2) - 4.0f * A * C; //makes math simpilar
float x = NAN;
if (discriminant >= 0) {
float insideLog = (-B + sqrt(discriminant)) / (2.0f * A);
if (insideLog > 0) {
x = log(insideLog) / k;
}
}
if (y_at_30m >= height)
{
std::cout << "the ball is over the net" << std::endl;
if (x < 60)
{
// use this for the passer function to run if this function returns 0
return 0;
}
else
{
std::cout << "900 SQUARE FEET AND YOU" << std::endl;
std::cout << "CAN'T" << std::endl << "HIT" << std::endl;
std::cout << "ONE" << std::endl;
}
return 1;
}
else
{
std::cout << "THER'S A NET THERE" << std::endl;
return 1;
}
}
int topper(int h, int v)
{
int angle = rand() % 11 ; // generates a random number between 10 and 0
float O = angle * 3.14159f / 180.0f; // convert angle to radians for trig functions
float g = 9.8f
float k = 0.0385f
float C_spin = 0.5f // magnus effect
float e =2.718281fr second
float w = /* spin in rad/s 10-15 rpm = 62.83-94.25 rad/s; */
// Position equation:
// y = ax^3 + bx^2 + cx + d
float a = -(g + C_spin * w) /
(50.0f * pow(v, 2) * pow(cos(O), 2));
float b = -(g + C_spin * w) /
(2.0f * pow(v, 2) * pow(cos(O), 2));
float c = tan(O);
float d = h;
float y_at_30m = a * pow(x, 3) + b * pow(x, 2) + c * x + d;
float p = (3.0f * a * c - pow(b, 2)) /
(3.0f * pow(a, 2));
float q = (27.0f * pow(a, 2) * d
- 9.0f * a * b * c
+ 2.0f * pow(b, 3)) /
(27.0f * pow(a, 3));
float discriminant =
pow(q / 2.0f, 2) +
pow(p / 3.0f, 3);
float x =
-b / (3.0f * a)
+ cbrt(-q / 2.0f + sqrt(discriminant))
+ cbrt(-q / 2.0f - sqrt(discriminant));
if (y_at_30m >= height )
{
std::cout << "the ball is over the net" << std::endl;
if (x < 60)
{
return 0; // return 0 to indicate the ball landed in used for passes function
}
else
{
std::cout << "the ball goes looooooooong" << std::endl;
return 1; // return 1 to indicate the ball went long
}
}
else
{
std::cout << "THERE'S A NET THERE" << std::endl;
return 1; // return 1 to indicate the ball hit the net
}
}
int serve(order, float h, int v)
{
int coin = rand() % 2 + 1; // generates a random number between 1 and 2
if (order.top().servetype = 1 || order.top().servetype = 3 && coin =1)
{
cout <<order.top().name << " with the jump serve"<<endl;
topper(float h, int v);
topper_Score(int v, order);
}
if (order.top().servetype = 2 || order.top().servetype = 3 && coin = 2)
{
cout <<order.top().name << " with the float serve"<<endl;
floater(float h, int v);
floater_Score(order);
}
// get spike height
// get serve type from map
// for top take 115 +/- 10 kph and set the angle randomly between -1 and 5 degrees (random number to the first decimal place)
// for float take 90 +/- 10 kph and set the angle randomly between 1 and 9 degrees ((random number to the first decimal place))
// determine if serve is in, out or ace based on serve speed and max touch height
// return result of serve
// if ace add ace to teams stats ( stats will be a vector <kills, blocks, digs, aces, errors)
return 0;
}
int topper_Score(int v, order)
{
// use the speed and calculate efficentcy
int passer = rand() % 5 + 1; // generates a random number between 1 and 5
int recive = rand() % 100 + 1; // generates a random number between 1 and 100
if (passer == 1)
{
std::cout << "ACE ACE ACE ACEEEE" << std::endl;
return 2;
}
else if (passer == 2)
{
if (recive < v * 0.9f)
{
std::cout << "ACE ACE ACE ACEEEE" << std::endl;
return 2;
}
else
{
//the serve was out of system
return 1;
}
}
else if (passer == 3)
{
if (recive < v * 0.75f)
{
std::cout << "ITS AN ACEEEE FROM"<< order.top().name << std::endl;
return 2;
}
else
{
//the serve was out of system, good serve!
return 1;
}
}
else if (passer == 4)
{
if (recive < v * 0.5f)
{
//the serve was out of system
return 1;
}
else
{
//the serve was in system
return 0;
}
}
else if (passer == 5)
{
//the serve was in system
return 0;
}
}
int floater_Score(order)
{
// use rand num 1-7 for the serve and compair it to the passer to get the score
int serve = rand() % 7 + 1; // generates a random number between 1 and 7
int passer = rand() % 7 + 1; // generates a random number between 1 and 7
if (serve - passer == 0 || serve - passer == 1)
{
return 0; //in system
}
else if (serve - passer == -2 || serve - passer == -1 || serve - passer == 2 || serve - passer == 3)
{
return 0; //in system
}
else if (serve - passer == -4 || serve - passer == -3 || serve - passer == 4 || serve - passer == 5)
{
return 1; //out of system
}
else if (serve - passer == -6 || serve - passer == -5 || serve - passer == 6)
{
cout << "ACE FROM " << order.top().name <<endl;
return 2;
}
}
// 0 insystem, 1 out of system, 2 ace
//since the first one is based on serve recive I think I gotta write is at a var then do set(y)
// then uses which ever then start the loop with the block since the set is always the same
int set(y,Set_probability)
{
int luck = rand() % 5 + 1; // generates a random number between 1 and 5
// this one should be easy just take the value passer() returns and use a randomizer to give the set a score out of 10
if (y = 0)
{
if (luck = 5)
{
// best pass 75% chance in system, 20% perfect, 5% setter dump
if (Set_probability > 5)
{
return 0;
}
if (5 >= Set_probability > 1)
{
return 1;
}
if (Set_probability = 1)
{
return 2;
}
}
else
{
// ok pass 75% chance in system, 15% perfect, 10% high ball
if (Set_probability > 5)
{
return 0;
}
if (4 >= Set_probability > 1)
{
return 1;
}
if (2 >= Set_probability )
{
return 3;
}
}
}
if (y = 1) // bad pass 35% chance in ststem, 65% high ball
{
if (Set_probability > 13)
{
return 0;
}
else
{
return 3;
}
}
if (y = 2) // don't run fuction point is already over
{
break;
}
}
// 0 in system, 1 perfect, 2 point, 3 high ball
int block(y)
{
int probability = rand() % 20 + 1; // generates a random number between 1 and 20
// the worse the set the easier the block will be
// this one should be easy just take the value passer() returns and use a randomizer to give the set a score out of 10
if (y = 0 ) // best set: 25% open net, 50% single block, 25% double block
{
if (probability > 15)
{
return 2; //double block
}
if (15 >= probability > 5)
{
return 1; //single block
}
if (5 >= probability )
{
return 0; // open net
}
}
if (y = 1) // in system: 75% double block, 20% single block, 5% no block
{
if (probability > 5)
{
return 2; //double block
}
if (5 >= probability > 1)
{
return 1; //single block
}
if (1 = probability )
{
return 0; // open net
}
}
if (y = 3) // high ball: 70% tripple block, 30% double block
{
if (probability > 6)
{
return 2; //double block
}
else
{
return 3; // tripple block
}
}
}
// 0 open net, 1 single block, 2 double block, 3 tripple block
int hit(y, set_probability)
{
int probability = rand() % 20 + 1; // generates a random number between 1 and 20
int option = rand() 5 + 1; // random numb between 1 and 5
// if the block is normal swing
// if the block is good and the set is not good the have a chance to tool or recycle with a chance to tool, recycle, or kill block
/* logic:
look at set determine open, single, double, or tripple block
randomly pick an option (swing, High hands, tool, recycle, tip)
run the probability of the outcome
if fails then either kill block or error ex: fail high hands = swing out or fail recycle = kill block
*/
if (y= 3) // tripple block
{
// rand choice and sucsess rates set > 10 (high hands 75%, tool 45%, recycle 60%, swing 20%, tip 45%)
if (set_probabilitu >10)
{
if (option = 1) //high hands & posetion changes
{
if (probability > 5)
{
return 1; //block touch
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
}
if (option = 2) //tool posetion changes
{
if (probability > 11)
{
return 0; // tool kill (error for blocking team, point hitting team)
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
if (option = 3) // recycle
{
if (probability > 8)
{
return 3; //recycle
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
if (option = 4) // swing
{
if (probability > 16)
{
return 0; //kill (point hitting team)
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
if (option = 5) // tip
{
if (probability > 11 )
{
return 4; // tip
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
}
// rand choice and sucsess rates set 10 =< (high hands 35%, tool 45%, recycle 60%, swing 20%, tip 35%)
else
{
if (option = 1) //high hands
{
if (probability > 13)
{
return 1; //block touch
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
if (option = 2) //tool
{
if (probability > 11)
{
return 0; // tool kill (error for blocking team, point hiting team)
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
if (option = 3) // recyc;e
{
if (probability > 8)
{
return 3; //recycle
}
else
{
return 2; //kill (error for hitting team, point bloccking team)
}
}
if (option = 4) // swing
{
if (probability > 16)
{
return 0; //kill (point hitting team)
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
if (option = 5) // tip
{
if (probability > 13 )
{
return 4; // tip
}
else
{
return 2; //kill block (error for hitting team, point bloccking team)
}
}
}
if ( y= 2 ) // double block (high hands 85%, tool 65%, recycle 70%, swing 70%, tip 35%)
{
if (option = 1) //high hands
{
if (probability > 3)
{
return 1; //block touch
}
else
{
return 2; // swing out
}
}
if (option = 2) //tool
{
if (probability > 7)
{
return 0; // tool kill
}
else
{
return 2; //kill block
}
}
if (option = 3) // recycle
{
if (probability > 6)
{
return 3; //recycle
}
else
{
return 2; //kill block
}
}
if (option = 4) // swing
{
if (probability > 6)
{
return 0; //kill
}
else
{
return 2; //kill block
}
}
if (option = 5) // tip
{
if (probability > 13 )
{
return 4; // tip
}
else
{
return 5; //free ball ( guarenteed perfect pass)
}
}
}
if ( y= 1) // single block (high hands 90%, tool 85%, recycle 70%, swing 85%, 15%)
{
if (option = 1) //high hands
{
if (probability > 2)
{
return 1; //block touch
}
else
{
return 2; //kill block
}
}
if (option = 2) //tool
{
if (probability > 3)
{
return 0; // tool kill
}
else
{
return 2; //kill block
}
}
if (option = 3) // recycle
{
if (probability > 6)
{
return 3; //recycle
}
else
{
return 2; //kill block
}
}
if (option = 4) // swing
{
if (probability > 3)
{
return 0; //kill
}
else
{
return 2; //kill block
}
}
if (option = 5) // tip
{
if (probability > 17 )
{
return 4; // tip
}
else
{
return 5; // free ball
}
}
}
if (y= 0) //no block or late block ( tool 99%, swing 99%)
{
if (option = 1 || 2) //tool
{
if (probability > 1)
{
return 0; // tool kill
}
else
{
return 3; //recycle
}
}
else // swing
{
if (probability > 1)
{
return 0; //kill
}
else
{
return 3; //block touch
}
}
}
}
// 0 kill, 1 block touch, 2 kill block, 3 recycle, 4 tip
int blocktouch(x,y) // x = block, y = hit change these names bro too many x and y & posetion changes
{
// only if hit is a swing, tool, or recycle
int v = rand() % 120 + 90// between 90-120 km/p
if (y= 1 ) //block touch: slowes v down by 10% to 75%
{
if (x = 1)
{
// slows by 10% - 30%
int stopage = rand() 30 + 10
v= v * (1-(stopage / 100 ))
return v;
}
if (x = 2)
{
// slows by 25% - 50%
int stopage = rand() 50 + 25
v= v * (1-(stopage / 100 ))
return v;
}
if (x = 3)
{
// slows by 40% - 60%
int stopage = rand() 60 + 40
v= v * (1-(stopage / 100 ))
return v;
}
}
if (y = 4)//tip
{
return 0;
}
else
{
//no block touch
return v;
}
}
int dig(x,v) // x = hit, v= block touch (speed of ball 90-120) change var name too much x and y
{
//basiclly just topper score code just slightly re worked, I need to a make an if else statment to check for top/ spike or float
// use the speed and calculate efficentcy
int recive = rand() % 100 + 1; // generates a random number between 1 and 100
if (x == 0) // open net move to hit function
{
// small chance to dig & posetion changes
// return /*smth */ gotta keep track of points
}
else if (x == 1) //high hands
{
if (recive < v )
{
std::cout << "Whata kill" << std::endl;
//return smth ; -> point other team
}
else
{
//the dig was out of system
return 1; //give team posetion
}
}
else if (hit == 4 ) tip
{
int luck = rand () 5 + 1
if (5> luck > 1)
{
// out of system give passing team posetion
}
if (luck = 5)
{
//in system good to perfect set gar and get posetion
}
else
{
// tip gets a kill
}
}
}
int rally()
{
set(/*serve recive*/); //(posesion stays same)
While (true)
{
int Set_probability = rand() % 20 + 1; // generates a random number between 1 and 20
block(); //(posesion stays same)
hit(); //(posesion stays same)
blocktouch(); //(possesion changes kill block/block/tool touch or same if recycle)
dig(); //(If no block posession change if hit/tool doesn't end rally, same if recycle)
set(); //(posesion stays same)
/*
logic: Serving team = A Possesion = A
when ball is sent over and controlled Possesion is changed
when possesioin changes: revice and kill block
does not change: spike, set, soft block, recycle, tool
basically boolian logic
*/
}
}
/*
int score()
{
// take return value from rally() and determine who wins the point
on an ace, kill, kill block, or setter dump give team with posesion a point
on tool give other team a point
smth like after a rally
return 0;
}
int stats()
{
// keep track of the number of aces, errors(tooled, blocked, aced, and missed serves), and points scored by each team using an array
// use variables to add to in each function
// use who had possesion to count states
// then that determins who got the point and how and I can use that in serve to determine when to move in the que
return 0;
}
*/
int main()
{
cout << endl;
vector<players> roster = loadPlayers();