-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
1696 lines (1690 loc) · 44.3 KB
/
main.cpp
File metadata and controls
1696 lines (1690 loc) · 44.3 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
// CRICKET SIMULATOR
// ---------------------
// -------------------------
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<iomanip.h>
#include<math.h>
char String[26][5][6];
void AssignString()
{strcpy(String[0][0],"AAAAA");
strcpy(String[0][1],"A A");
strcpy(String[0][2],"AAAAA");
strcpy(String[0][3],"A A");
strcpy(String[0][4],"A A");
strcpy(String[1][0],"BBBBB");
strcpy(String[1][1],"B B");
strcpy(String[1][2],"BBBB ");
strcpy(String[1][3],"B B");
strcpy(String[1][4],"BBBBB");
strcpy(String[2][0],"CCCCC");
strcpy(String[2][1],"C ");
strcpy(String[2][2],"C ");
strcpy(String[2][3],"C ");
strcpy(String[2][4],"CCCCC");
strcpy(String[3][0],"DDDD ");
strcpy(String[3][1],"D D");
strcpy(String[3][2],"D D");
strcpy(String[3][3],"D D");
strcpy(String[3][4],"DDDD ");
strcpy(String[4][0],"EEEEE");
strcpy(String[4][1],"E ");
strcpy(String[4][2],"EEEEE");
strcpy(String[4][3],"E ");
strcpy(String[4][4],"EEEEE");
strcpy(String[5][0],"FFFFF");
strcpy(String[5][1],"F ");
strcpy(String[5][2],"FFFFF");
strcpy(String[5][3],"F ");
strcpy(String[5][4],"F ");
strcpy(String[6][0],"GGGGG");
strcpy(String[6][1],"G ");
strcpy(String[6][2],"G GGG");
strcpy(String[6][3],"G G");
strcpy(String[6][4],"GGGGG");
strcpy(String[7][0],"H H");
strcpy(String[7][1],"H H");
strcpy(String[7][2],"HHHHH");
strcpy(String[7][3],"H H");
strcpy(String[7][4],"H H");
strcpy(String[8][0],"IIIII");
strcpy(String[8][1]," I ");
strcpy(String[8][2]," I ");
strcpy(String[8][3]," I ");
strcpy(String[8][4],"IIIII");
strcpy(String[9][0],"JJJJJ");
strcpy(String[9][1]," J ");
strcpy(String[9][2]," J ");
strcpy(String[9][3]," J ");
strcpy(String[9][4],"JJJ ");
strcpy(String[10][0],"K K");
strcpy(String[10][1],"K K ");
strcpy(String[10][2],"KK ");
strcpy(String[10][3],"K K ");
strcpy(String[10][4],"K K");
strcpy(String[11][0],"L ");
strcpy(String[11][1],"L ");
strcpy(String[11][2],"L ");
strcpy(String[11][3],"L ");
strcpy(String[11][4],"LLLLL");
strcpy(String[12][0],"M M");
strcpy(String[12][1],"MM MM");
strcpy(String[12][2],"M M M");
strcpy(String[12][3],"M M");
strcpy(String[12][4],"M M");
strcpy(String[13][0],"N N");
strcpy(String[13][1],"NN N");
strcpy(String[13][2],"N N N");
strcpy(String[13][3],"N NN");
strcpy(String[13][4],"N N");
strcpy(String[14][0],"OOOOO");
strcpy(String[14][1],"O O");
strcpy(String[14][2],"O O");
strcpy(String[14][3],"O O");
strcpy(String[14][4],"OOOOO");
strcpy(String[15][0],"PPPPP");
strcpy(String[15][1],"P P");
strcpy(String[15][2],"PPPPP");
strcpy(String[15][3],"P ");
strcpy(String[15][4],"P ");
strcpy(String[16][0],"QQQQQ");
strcpy(String[16][1],"Q Q");
strcpy(String[16][2],"Q Q Q");
strcpy(String[16][3],"QQ QQ");
strcpy(String[16][4],"QQQQQ");
strcpy(String[17][0],"RRRRR");
strcpy(String[17][1],"R R");
strcpy(String[17][2],"RRRRR");
strcpy(String[17][3],"R R ");
strcpy(String[17][4],"R R ");
strcpy(String[18][0],"SSSSS");
strcpy(String[18][1],"S ");
strcpy(String[18][2],"SSSSS");
strcpy(String[18][3]," S");
strcpy(String[18][4],"SSSSS");
strcpy(String[19][0],"TTTTT");
strcpy(String[19][1]," T ");
strcpy(String[19][2]," T ");
strcpy(String[19][3]," T ");
strcpy(String[19][4]," T ");
strcpy(String[20][0],"U U");
strcpy(String[20][1],"U U");
strcpy(String[20][2],"U U");
strcpy(String[20][3],"U U");
strcpy(String[20][4],"UUUUU");
strcpy(String[21][0],"V V");
strcpy(String[21][1],"V V");
strcpy(String[21][2],"V V");
strcpy(String[21][3]," V V ");
strcpy(String[21][4]," V ");
strcpy(String[22][0],"W W");
strcpy(String[22][1],"W W");
strcpy(String[22][2],"W W W");
strcpy(String[22][3],"WW WW");
strcpy(String[22][4],"W W");
strcpy(String[23][0],"X X");
strcpy(String[23][1]," X X ");
strcpy(String[23][2]," X ");
strcpy(String[23][3]," X X ");
strcpy(String[23][4],"X X");
strcpy(String[24][0],"Y Y");
strcpy(String[24][1]," Y Y ");
strcpy(String[24][2]," Y ");
strcpy(String[24][3]," Y ");
strcpy(String[24][4]," Y ");
strcpy(String[25][0],"ZZZZZ");
strcpy(String[25][1]," Z ");
strcpy(String[25][2]," Z ");
strcpy(String[25][3]," Z ");
strcpy(String[25][4],"ZZZZZ");
}
void Delay(double limit=5000000)
{double delay;
for(delay=0;delay<limit;delay++)
if(delay==-1)
cout<<"BUG?";
}
void PrintCharacter(char Alphabet, int j)
{int i;
if(int(Alphabet)>96 && int(Alphabet)<123)
Alphabet=int(Alphabet)-32;
i=int(Alphabet)-65;
cout<<String[i][j];
}
void Print(char Sentence[500])
{int i=0,j,k;
while(Sentence[i]==' ')
i++;
k=i;
cout<<endl;
for(j=0;j<5;j++)
{for(;Sentence[i]!='\0';i++)
{if(Sentence[i]==' ')
break;
Delay(100000);
cout<<" ";
PrintCharacter(Sentence[i],j);
cout<<" ";
}
cout<<endl;
if(Sentence[i]==' ' && j==4)
{j=-1;
while(Sentence[i]==' ')
i++;
k=i;
if(Sentence[i]=='\0')
break;
cout<<endl;
}
else
i=k;
}
}
void About()
{cout<<"\nWelcome to CRICKET SIMULATOR!! Follow the instructions to proceed the Simulator.";
cout<<"The process of Simulation is machine controlled. Just need to give some basic inputs when asked.";
cout<<"\nThe Simulator has a fixed speed which can not be changed at all.";
cout<<"\nAll the values shown by the Simulator are random and generated on the time of execution only.";
cout<<"\nThese values can not be manipulated.";
}
void Credits()
{cout<<"\nFully Developed and Maintained by\n";
Print("ABHIMANYU GUPTA");
}
void Countdown()
{int count=9;
cout<<"\nMatch begins in ";
for(;count>0;count--)
{cout<<count<<"......\b\b\b\b\b\b\b";
Delay(1000000);
}
cout<<".\nLet's Go\n";
}
void Name_Short(char f_name[26], char s_name[26])
{int i,j=-1,k=0;
for(i=0;i<strlen(f_name);i++)
if(f_name[i]==' ' && f_name[i+1]!=' ' && f_name[i+1]!='\0')
j=i;
for(i=0;i<=j;i++)
if((i==0 && f_name[i]!=' ') || (f_name[i-1]=='.' && f_name[i]!=' ' && f_name[i]!='\0') || (f_name[i]!=' ' && f_name[i-1]==' '))
{s_name[k++]=f_name[i];
s_name[k++]='.';
}
if(j!=-1)
s_name[k++]=' ';
for(;i<strlen(f_name);i++,k++)
s_name[k]=f_name[i];
s_name[k]='\0';
}
void PrintGraph(int overs, int runs[20], int wickets[20])
{int i,r,maxR=0,w,maxW=0;
cout<<"\n\n RUNS| ";
for(i=0;i<overs;i++)
{cout<<setw(3)<<runs[i];
maxR=(runs[i]>maxR)?runs[i]:maxR;
maxW=(wickets[i]>maxW)?wickets[i]:maxW;
}
cout<<endl;
for(r=maxR;r>0;r-=(maxR*0.1))
{cout<<setw(6)<<r<<" | ";
for(i=0;i<overs;i++)
if(runs[i]>=r)
cout<<"-- ";
else
cout<<" ";
cout<<endl;
}
for(i=0;i<(11+3*overs);i++)
cout<<"-";
cout<<endl;
cout<<" OVERS| ";
for(i=0;i<overs;i++)
cout<<setw(3)<<i+1;
cout<<"\n";
for(i=0;i<(11+3*overs);i++)
cout<<"-";
cout<<endl;
for(w=1;w<=maxW;w+=ceil(maxW*0.2))
{cout<<setw(6)<<w<<" | ";
for(i=0;i<overs;i++)
if(wickets[i]>=w)
cout<<"** ";
else
cout<<" ";
cout<<endl;
}
cout<<"WICKETS| ";
for(i=0;i<overs;i++)
cout<<setw(3)<<wickets[i];
cout<<endl;
}
void Check(char runs[20], int s, int t)
{int r;
r=t-s;
if(runs[3]!='6' && (runs[3]!='4' || (runs[3]=='4' && runs[4]=='o')))
{if(runs[0]!='l')
runs[3]=char(r-1+48);
else
runs[3]=char(r+48);
}
runs[2]='n';
runs[4]='\0';
runs[5]='\0';
}
void Swap(int &a, int &b)
{a=a+b;
b=a-b;
a=a-b;
}
struct Extra
{int wides;
int byes;
int leg_byes;
int no_balls;
};
struct Toss
{int team;
int choice1;
int face;
int won;
int choice2;
};
class Batsman
{public:
int runs_scored;
int balls_faced;
int dots;
int singles;
int doubles;
int triples;
int fours;
int fives;
int sixes;
float strike_rate;
char batted;
Batsman();
void ScoreRuns(char runs[20]);
void DisplayBatStats();
};
Batsman::Batsman()
{runs_scored=0;
balls_faced=0;
dots=0;
singles=0;
doubles=0;
triples=0;
fours=0;
fives=0;
sixes=0;
strike_rate=0;
batted='n';
}
void Batsman::ScoreRuns(char runs[20])
{int score=-1;
if(runs[0]!='w')
{balls_faced++;
score=0;
}
if(runs[2]=='w' && (runs[4]!='r' || (runs[4]=='r' && runs[5]=='0')))
batted='o';
if(runs[1]=='b')
{score=int(runs[3])-48;
runs_scored+=score;
}
if(score==0)
dots++;
else if(score==1)
singles++;
else if(score==2)
doubles++;
else if(score==3)
triples++;
else if(score==4 && runs[4]!='o')
fours++;
else if(score==5)
fives++;
else if(score==6)
sixes++;
strike_rate=(runs_scored+0.0)/balls_faced*100;
}
void Batsman::DisplayBatStats()
{cout<<endl<<setw(46)<<"Batting Stats\n";
cout<<"\nBalls Faced"<<setw(19)<<balls_faced<<setw(10)<<" ";
cout<<"Runs Scored"<<setw(19)<<runs_scored;
cout<<"\nDot Balls"<<setw(21)<<dots<<setw(10)<<" ";
cout<<"Strike Rate"<<setw(19)<<strike_rate;
cout<<"\nSingles"<<setw(23)<<singles<<setw(10)<<" ";
cout<<"Doubles"<<setw(23)<<doubles;
cout<<"\nTriples"<<setw(23)<<triples<<setw(10)<<" ";
cout<<"Fours"<<setw(25)<<fours;
cout<<"\nFives"<<setw(25)<<fives<<setw(10)<<" ";
cout<<"Sixes"<<setw(25)<<sixes;
}
class Bowler
{public:
char bowled;
int overs;
int balls;
int maiden_overs;
int runs_conceeded;
int wickets;
float economy;
int dot_balls;
Extra extras;
int extra;
int runs_overs[4];
int wickets_overs[4];
Bowler();
void TakeWickets(char runs[20]);
void DisplayBowlStats();
};
Bowler::Bowler()
{overs=0;
balls=0;
runs_conceeded=0;
wickets=0;
maiden_overs=0;
dot_balls=0;
economy=0;
bowled='n';
extra=0;
extras.wides=0;
extras.no_balls=0;
for(int i=0;i<4;i++)
{runs_overs[i]=0;
wickets_overs[i]=0;
}
}
void Bowler::TakeWickets(char runs[20])
{int r=0;
float o;
bowled='y';
if(runs[1]=='b' || runs[0]!='l')
{r=int(runs[3])-48;
if(runs[0]!='l')
r++;
runs_conceeded+=r;
runs_overs[overs]+=r;
}
if(runs[2]=='w' && runs[4]!='r')
{wickets++;
wickets_overs[overs]++;
}
if(runs[0]=='l' && (runs[3]=='0' || runs[1]!='b' || runs[2]=='w'))
dot_balls++;
if(runs[0]=='w')
{extras.wides++;
extra+=r;
}
else if(runs[0]=='n')
{extras.no_balls++;
extra+=r;
}
if(runs[0]=='l' && balls<6)
balls++;
o=overs*6+balls;
if(o==0)
o=1;
economy=runs_conceeded/o*6;
if(balls==6)
{if(runs_overs[overs]==0)
maiden_overs++;
balls=0;
overs++;
}
}
void Bowler::DisplayBowlStats()
{int o;
cout<<endl<<setw(46)<<"Bowling Stats\n";
cout<<"\nOvers Bowled"<<setw(16)<<overs<<"."<<balls<<setw(10)<<" ";
cout<<"Runs Conceeded"<<setw(16)<<runs_conceeded;
cout<<"\nEconomy"<<setw(23)<<setprecision(2)<<economy<<setw(10)<<" ";
cout<<"Dot Balls"<<setw(21)<<dot_balls;
cout<<"\nWickets"<<setw(23)<<wickets<<setw(10)<<" ";
cout<<"Maiden Overs"<<setw(18)<<maiden_overs;
cout<<"\nExtras"<<setw(24)<<extra<<" (W-"<<extras.wides<<",N-"<<extras.no_balls<<")";
o=overs;
if(balls!=0)
o++;
Delay(3000000);
PrintGraph(o,runs_overs,wickets_overs);
}
class Fielder
{public:
int catches;
int stumps;
int run_outs;
char field_effort;
Fielder();
void PushLimits(char);
void DisplayFieldStats();
};
Fielder::Fielder()
{catches=0;
stumps=0;
run_outs=0;
field_effort='n';
}
void Fielder::PushLimits(char w)
{if(w=='c')
catches++;
else if(w=='s')
stumps++;
else
run_outs++;
field_effort='y';
}
void Fielder::DisplayFieldStats()
{cout<<endl<<setw(47)<<"Fielding Stats"<<endl;
if(stumps!=0)
cout<<"\nStumps"<<setw(24)<<stumps<<endl;
if(catches!=0)
cout<<"Catches"<<setw(23)<<catches<<endl;
if(run_outs!=0)
cout<<"Run Outs"<<setw(22)<<run_outs<<endl;
}
class Player: public Batsman, public Bowler, public Fielder
{public:
char type[10];
char name[26];
Player();
void AsignName(char Name[26]);
void AsignType(char Type[10]);
void DisplayStats();
};
Player::Player()
{strcpy(name,NULL);
strcpy(type,NULL);
}
void Player::AsignName(char Name[26])
{strcpy(name,Name);
}
void Player::AsignType(char Type[10])
{strcpy(type,Type);
}
void Player::DisplayStats()
{clrscr();
cout<<endl<<setw(40+strlen(name)/2)<<name<<endl<<endl;
if(batted=='n')
cout<<name<<" didn't batted in the macth\n";
else
DisplayBatStats();
cout<<endl<<endl;
Delay(3000000);
if(bowled=='n' && strcmp(type,"Bowl")==0 && strcmp(type,"Bat/Bowl")==0)
cout<<name<<" didn't bowled in the match\n";
else if(bowled=='y')
DisplayBowlStats();
if(field_effort=='y')
DisplayFieldStats();
Delay(3000000);
}
class Team
{public:
char team_name[30];
Player players[11];
Team();
void AsignTeamName(char name[30]);
void InputPlayerNames();
};
Team::Team()
{strcpy(team_name,NULL);
}
void Team::AsignTeamName(char name[30])
{strcpy(team_name,name);
}
void Team::InputPlayerNames()
{int i,j;
char name[26];
for(i=0;i<11;i++)
{gets(name);
players[i].AsignType(NULL);
players[i].AsignName(name);
for(j=0;j<strlen(players[i].name);j++)
if(players[i].name[j]=='(' && players[i].name[j+2]==')')
{if(players[i].name[j+1]=='0')
players[i].AsignType("Bowl");
else if(players[i].name[j+1]=='1')
players[i].AsignType("Bat");
else if(players[i].name[j+1]=='2')
players[i].AsignType("Bat/Bowl");
else if(players[i].name[j+1]=='3')
players[i].AsignType("Bat/Wk");
if(players[i].type!=NULL)
{players[i].name[j]='\0';
break;
}
}
}
}
class Inning
{private:
int dots;
int singles;
int doubles;
int triples;
int fours;
int fives;
int sixes;
int maiden_overs;
public:
int score;
int wickets;
int overs;
int balls;
int runs_overs[20];
int wickets_overs[20];
long int wickets_pair[11];
Extra extras;
int extra;
float run_rate;
Inning();
void MaintainStats(char runs[20],int &s,int &n_s,int b,int &out);
void DisplayStats();
};
Inning::Inning()
{int i;
score=0;
wickets=0;
dots=0;
singles=0;
doubles=0;
triples=0;
fours=0;
fives=0;
sixes=0;
run_rate=0;
maiden_overs=0;
overs=0;
balls=0;
extras.wides=0;
extras.byes=0;
extras.no_balls=0;
extras.leg_byes=0;
extra=0;
for(i=0;i<20;i++)
{runs_overs[i]=0;
wickets_overs[i]=0;
if(i<11)
wickets_pair[i]=-1;
}
}
void Inning::MaintainStats(char runs[20], int &s, int &n_s, int b, int &out)
{int SCORE,n;
float o;
if(runs[0]=='l' && balls<6)
balls++;
SCORE=int(runs[3])-48;
if(runs[3]=='1')
singles++;
else if(runs[3]=='2')
doubles++;
else if(runs[3]=='3')
triples++;
else if(runs[3]=='4' && runs[4]!='o')
fours++;
else if(runs[3]=='5')
fives++;
else if(runs[3]=='6')
sixes++;
if(runs[0]=='n')
extras.no_balls++;
else if(runs[0]=='w')
extras.wides++;
if(runs[1]=='n')
extras.byes+=SCORE;
else if(runs[1]=='l')
extras.leg_byes+=SCORE;
if(runs[0]!='l')
SCORE++;
if(runs[0]!='l' || runs[1]!='b')
extra+=SCORE;
if(SCORE==0)
dots++;
score+=SCORE;
runs_overs[overs]+=SCORE;
SCORE=int(runs[3])-48;
if(runs[2]=='n' && SCORE%2==1)
Swap(s,n_s);
if(runs[2]=='w')
{wickets++;
wickets_overs[overs]++;
if(runs[4]=='b')
wickets_pair[s]=10000+b;
else if(runs[4]=='l')
wickets_pair[s]=20000+b;
else if(runs[4]=='s')
wickets_pair[s]=30000+b;
else if(runs[4]=='c')
wickets_pair[s]=40000+100*random(11)+b; //40000+100*Fielder_who_took_catch+Bowler
else if(runs[4]=='h')
wickets_pair[s]=50000+b;
else if(runs[4]=='r')
{if(runs[5]=='0')
wickets_pair[s]=60000+random(11);
else if(runs[5]=='1')
wickets_pair[n_s]=60000+random(11);
}
n=(s>n_s)?s:n_s;
n++;
if(runs[4]=='r' && runs[5]=='1')
{out=n_s;
n_s=n;
}
else
{out=s;
s=n;
}
if(runs[4]=='c' && runs[5]=='1')
Swap(s,n_s);
}
o=overs*6+balls;
if(o==0)
o=1;
run_rate=score/o*6;
if(balls==6)
{balls=0;
if(runs_overs[overs]==0)
maiden_overs++;
overs++;
}
}
void Inning::DisplayStats()
{int o;
cout<<"\nScore"<<setw(25)<<score<<setw(10)<<" ";
cout<<"Wickets"<<setw(23)<<wickets;
cout<<"\nOvers"<<setw(23)<<overs<<"."<<balls<<setw(10)<<" ";
cout<<"Run Rate"<<setw(22)<<run_rate;
cout<<"\nDot Balls"<<setw(21)<<dots<<setw(10)<<" ";
cout<<"Maiden Overs"<<setw(18)<<maiden_overs;
cout<<"\nSingles"<<setw(23)<<singles<<setw(10)<<" ";
cout<<"Doubles"<<setw(23)<<doubles;
cout<<"\nTriples"<<setw(23)<<triples<<setw(10)<<" ";
cout<<"Fours"<<setw(25)<<fours;
cout<<"\nFives"<<setw(25)<<fives<<setw(10)<<" ";
cout<<"Sixes"<<setw(25)<<sixes;
cout<<"\nExtras "<<extra<<" (Wides- "<<extras.wides<<", No Balls- "<<extras.no_balls<<", Byes- "<<extras.byes<<", Leg Byes- "<<extras.leg_byes<<")\n";
Delay();
o=overs;
if(balls!=0)
o++;
PrintGraph(o,runs_overs,wickets_overs);
}
class Cricket
{private:
Team teams[2];
Inning innings[2];
int target;
float req_run_rate;
int bowler_overs_limit;
int won;
Toss toss;
void DefaultNames();
void UserInputs();
void UserPlayerNames();
void CheckInputs();
void Toss();
void StartMatch();
void StartInnings();
void StartOver(int &s,int &n_s,int b);
void PlayBowl(char runs[20], int p);
void Commentary(char runs[20],int s,int n_s,int b,int out);
void PrintOnPitchPlayers(int s, int n_s, int b);
void SearchStats();
public:
int Match_Code;
int current_inning;
int batting;
int bowling;
int overs_limit;
Cricket();
void LetsPlay();
void DisplayToss();
void Display_Teams_Players();
void ScoreCard();
void DisplayStats();
void Won();
void Search();
};
Cricket::Cricket()
{Match_Code=-1;
current_inning=-1;
toss.team=-1;
toss.choice1=-1;
toss.face=-1;
toss.won=-1;
toss.choice2=-1;
batting=-1;
bowling=-1;
target=30000;
req_run_rate=0;
overs_limit=20;
bowler_overs_limit=ceil(overs_limit*0.2);
won=-1;
}
void Cricket::DefaultNames()
{int j;
teams[0].AsignTeamName("India");
teams[0].players[0].AsignName("Rohit Sharma");
teams[0].players[1].AsignName("Shikar Dhawan");
teams[0].players[2].AsignName("Virat Kohli");
teams[0].players[3].AsignName("Suresh Raina");
teams[0].players[3].AsignType("Bat/Bowl");
teams[0].players[4].AsignName("Manish Pandey");
teams[0].players[5].AsignName("M.S. Dhoni");
teams[0].players[5].AsignType("Bat/Wk");
teams[0].players[6].AsignName("Hardik Pandya");
teams[0].players[7].AsignName("Ravindra Jadeja");
teams[0].players[8].AsignName("Ravichandra Ashwin");
teams[0].players[9].AsignName("Bhuvneshwar Kumar");
teams[0].players[10].AsignName("Jasprit Bumraha");
teams[0].players[10].AsignType("Bowl");
for(j=0;j<5;j++)
{if(j==3)
continue;
teams[0].players[j].AsignType("Bat");
}
for(j=6;j<10;j++)
teams[0].players[j].AsignType("Bat/Bowl");
teams[1].AsignTeamName("South Africa");
teams[1].players[0].AsignName("Hashim Amla");
teams[1].players[1].AsignName("Quinton De Kock");
teams[1].players[1].AsignType("Bat/Wk");
teams[1].players[2].AsignName("Faf Du Plessis");
teams[1].players[3].AsignName("A.B. De Villiers");
teams[1].players[4].AsignName("David Miller");
teams[1].players[5].AsignName("J.P. Duminy");
teams[1].players[6].AsignName("Christropher Morris");
teams[1].players[7].AsignName("Imran Tahir");
teams[1].players[8].AsignName("Kagiso Rabada");
teams[1].players[9].AsignName("Morne Morkel");
teams[1].players[10].AsignName("Dale Styen");
for(j=0;j<5;j++)
{if(j==1)
continue;
teams[1].players[j].AsignType("Bat");
}
for(j=5;j<7;j++)
teams[1].players[j].AsignType("Bat/Bowl");
for(j=7;j<11;j++)
teams[1].players[j].AsignType("Bowl");
}
void Cricket::UserInputs()
{char choice='n',t_name[30];
int o;
cout<<"\nEnter the match overs (max-20)\n";
cin>>o;
if(o<1 || o>20)
{cout<<"Invalid value for overs, Default Value Set (20)\n";
o=20;
}
overs_limit=o;
bowler_overs_limit=ceil(o*0.2);
cout<<"\nDo you want to change teams names (y/n)\n";
cin>>choice;
if(choice=='y' || choice=='Y')
{cout<<"\nEnter first team's name\n";
gets(t_name);
teams[0].AsignTeamName(t_name);
cout<<"Enter second team's name\n";
gets(t_name);
teams[1].AsignTeamName(t_name);
}
cout<<"\nDo you want to use your own player names (y/n)\n";
cin>>choice;
if(choice=='y' || choice=='Y')
UserPlayerNames();
}
void Cricket::UserPlayerNames()
{cout<<"\nINSTRUCTIONS::\n";
cout<<"1.Team Size : 11 players each team\n";
cout<<"2.Player name : Max. 25 characters long\n";
cout<<"3.Bowler : Min. 6\n";
cout<<"4.Wicket Keeper : 1\n";
cout<<"5.Batsman & All-rounders : any number\n";
cout<<"6.Enter player name as : Player_name(player_type)\n Player_type --> Bowler=0, Batsman=1, All Rounder=2, Wicket Keeper=3\n";
cout<<"\nEnter first team's players name\n";
teams[0].InputPlayerNames();
cout<<"\nEnter second team's players name\n";
teams[1].InputPlayerNames();
CheckInputs();
}
void Cricket::CheckInputs()
{int i,j;
char o;
int bowl[2]={0,0},wk[2]={0,0};
for(i=0;i<2;i++)
for(j=0;j<11;j++)
{if(strcmp(teams[i].players[j].type,"Bowl")==0)
bowl[i]++;
else if(strcmp(teams[i].players[j].type,"Bat/Bowl")==0)
bowl[i]++;
else if(strcmp(teams[i].players[j].type,"Bat/Wk")==0)
wk[i]++;
}
i=-1;
if(bowl[0]<6 || bowl[1]<6)
{cout<<"\nEnter atleast 6 Bowlers in each team\n";
i=0;
}
else if(wk[0]!=1 || wk[1]!=1)
{cout<<"\nThere should be excatly 1 Wkicket Keeper in each team\n";
i=0;
}
if(i==0)
{cout<<"Enter all values again or Enter 0 to use default values\n";
cin>>o;
if(o=='0')
DefaultNames();
else
UserPlayerNames();
}
}
void Cricket::Toss()
{toss.team=random(2);
toss.choice1=random(2);
toss.face=random(2);
if(toss.choice1==toss.face)
toss.won=toss.team;
else
toss.won=(toss.team==0)?1:0;
toss.choice2=random(2);
if(toss.choice2==0)
{batting=toss.won;
bowling=(toss.won==0)?1:0;
}
else
{bowling=toss.won;
batting=(toss.won==0)?1:0;
}
}
void Cricket::DisplayToss()
{char Face[2][10]={"Heads","Tails"},Choice[2][10]={"Bat","Field"};
cout<<"\nTOSS TIME\n";
cout<<teams[toss.team].team_name<<" calls "<<Face[toss.choice1]<<"\n";
Delay();
if(toss.choice1!=toss.face)
cout<<"UN";
cout<<"LUCKY "<<Face[toss.choice1]<<"\n";
cout<<teams[toss.won].team_name;
cout<<" won the toss and decided to "<<Choice[toss.choice2]<<" first\n";
}
void Cricket::Display_Teams_Players()
{int i,j,s;
cout<<endl<<teams[0].team_name;
for(s=0;s<(40-strlen(teams[0].team_name));s++)
cout<<" ";
cout<<teams[1].team_name<<endl<<endl;
for(i=0;i<11;i++)
{cout<<teams[0].players[i].name<<" ("<<teams[0].players[i].type<<")";
s=strlen(teams[0].players[i].name)+strlen(teams[0].players[i].type)+3;
for(j=0;j<(40-s);j++)
cout<<" ";
cout<<teams[1].players[i].name<<" ("<<teams[1].players[i].type<<")\n";
}
}
void Cricket::StartMatch()
{current_inning=0;
StartInnings();
Delay(3000000);
ScoreCard();
Delay(3000000);
DisplayStats();
Delay(3000000);
current_inning=1;
Swap(batting,bowling);
StartInnings();
Delay(3000000);
ScoreCard();
Delay(3000000);
DisplayStats();
Delay(3000000);
}
void Cricket::StartInnings()
{int striker=0,non_striker=1,bowler,last_bowler=-1;
clrscr();
cout<<endl<<setw(40)<<"Start of ";
if(current_inning==0)
cout<<"First";
else
cout<<"Second";
cout<<" Inning\n";
while(innings[batting].wickets!=10 && innings[batting].overs!=overs_limit && innings[batting].score<target)
{do
{bowler=random(11);
}while(strcmp(teams[bowling].players[bowler].type,"Bat")==0 || strcmp(teams[bowling].players[bowler].type,"Bat/Wk")==0 || teams[bowling].players[bowler].overs==bowler_overs_limit || bowler==last_bowler);
StartOver(striker,non_striker,bowler);
last_bowler=bowler;
}
cout<<endl<<setw(40)<<"End of ";
if(current_inning==0)
cout<<"First";
else
cout<<"Second";
cout<<" Inning\n";
if(current_inning==0)
{target=innings[batting].score+1;
req_run_rate=(target+0.0)/overs_limit;
}
}
void Cricket::StartOver(int &s, int &n_s, int b)
{char runs[20],ch[3]="th";
int o,p,out,fair_balls=0;
//runs [type_of_ball,contact?,wicket?,runs,mode_of_wicket,strike_change?]
cout<<endl;
while(fair_balls!=6 && innings[batting].wickets!=10 && innings[batting].overs!=overs_limit && innings[batting].score<target)
{strcpy(runs,NULL);
do
{p=(strcmp(teams[bowling].players[s].type,"Bowl")==0)?2:0;
out=-1;
Delay(2000000);
cout<<innings[batting].overs<<"."<<innings[batting].balls+1<<" ";
if(innings[batting].overs<10)
cout<<" ";
PrintOnPitchPlayers(s,n_s,b);
teams[batting].players[s].batted='y';
teams[batting].players[n_s].batted='y';
PlayBowl(runs,p);
if(current_inning==1)
{if(runs[0]!='l')
p=1;
else
p=0;
if(innings[batting].score+p+int(runs[3])-48>target)
Check(runs,innings[batting].score,target);
}
teams[bowling].players[b].TakeWickets(runs);