-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_project.cpp
More file actions
3405 lines (3188 loc) · 79.3 KB
/
main_project.cpp
File metadata and controls
3405 lines (3188 loc) · 79.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
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
#include <math.h>
char teamNames[480]={};
char teamNamesandNums[32][40]={};
int matchTable[4][8]={{1324,1323,1311,1101,1104,1312,1303,1322},{4225,2328,4202,3313,2330,2517,4520,3426},{3409,4418,2121,2307,3106,3329,3431,2105},{2132,3214,3308,4419,4327,4216,2310,4215}};
int groupTable[4][8]={};//////this ganna update after one proceed
char selectedTeam[25]={};
int gPlan[32][15]={};
int exitt=0;
int proceed=0;
int worldCupnewGrouping=0;
typedef struct players{
int number;
char name[20];
int age;
char nation[20];
char mainPost[2];
char tempPost[2];
int skill;
int form;
int fitness;
int goals;
int passGoals;
struct players *next;
}player_node;
typedef struct teams{
char teamName[15];
char group[2];
int state;
char confed[15];
int seed;
int pointOfteam;
int goalsRecev;
int goalsScoerds;
int wins;
int losses;
int draws;
struct teams *next;
}teams_node;
void loadPlayersInformationFirstTime(player_node * head_players);
void teamsReadInfofromGlobal(FILE *t,teams_node *p);
void playerWriteInfo(player_node *pp);
player_node * playersReadInfo(FILE *t,player_node *p,const char * teamNamee);
void gamePlan(player_node * head,teams_node *tt);
int doAbility(int skill,int form, int fitness);
void bestPlanForManagment(player_node *pp,int t,int selectedTeam);
void selectTeamsToManagement();
void updateGamePlan(player_node *pp);
void printList(player_node *head);
void bubbleSort(int **a,int n);
void sortTotalPoints(int totalpoint[][2]);
void sortGroups(teams_node * headt);
player_node *search_post(player_node *head,const char* post,const char* teamName);
player_node *search_teamName(player_node *head,const char* teamName);
player_node *search_post(player_node *head,const char* post,const char* teamName);
player_node *search_post_temp(player_node *head,const char* post,const char* teamName);
player_node *search_playerNumber(player_node *head,int n);
player_node *search_playerNumber_teams(player_node *head,int n,const char *teamName);
player_node *search_teamName_forPlayer(player_node *head,const char* teamName);
teams_node * search_team(teams_node * headt,const char * teamName);
char* append(const char* name,const char* extension);
void splash();
void doSkills(teams_node * head_team,player_node * head_player);
void customization(player_node *headp,teams_node * headt);
void CustomizationManualform(player_node * headp,teams_node * headt);
void showPlayersofUser(player_node * headp);
void changingPlayerofUser(player_node * headp,teams_node *headt);
void doSubstitution(player_node * headp,teams_node * headt,int x,int y);
void printtable();
void printGroupTable(int groupTable[][8]);
void totalPointNULL(int totalpoint[][2]);
void groupTableNULL();
void startNewWorldCup();
void loadRecentWorldCup();
void mainMenu(player_node *headp,teams_node * headt);
void loadGrouping(teams_node * head_teams);
void loadPlayersInformationFirstTime();
void playerReadInfo(player_node *pp);
void newGrouping(teams_node * head_team);
int check(int place,int group,int teamNumber);
int checkNULL();
void copyTeams(int teamsOrginal[],int teams[]);
void tableToNULL();
void setTempNull(player_node * head);
void setTempPosts(player_node * pp,teams_node * pt);
void randomizeTeams();
void balloting();
///////////////////matchs
void matchControllerGroups(player_node * headp,teams_node * headt,int v);
/////////////////
int goalNumber(double attackPower1, double defencePower2);
int winer(int goal1,int goal2);/////////////////////////////////////to do ***********
int goalzan( int tarkib);
int passgoal(int tarkib);
teams_node * searchTeamForGrouping(teams_node * head_team,const char * teamName);
void writegPlans_MatchTable_selectedTeam();
void writeTeamsInfo(teams_node * headt);
void readgPlans_MatchTable_selectedTeam();
void readTeamsInfo(teams_node * headt);
void updateAllPlayersOutGameFormFitness(player_node * headp,teams_node * headt,const char * teamName1,const char * teamName2);
void updateFormWinnerLoss(player_node * headp,teams_node * headt,const char * teamName,int winner);
void updateFormGoalZan(player_node * headp,teams_node * headt,const char * teamName);
void updateFormGoalKhor(player_node * headp,teams_node * headt,const char * teamName);
void updateIfCleanSheet(player_node * headp,teams_node * headt,const char * teamName);
void fixture();
void mainTable(teams_node * headt);
int main()
{
srand((unsigned)time(NULL));
////////////////splash screen
//clock_t clockk0=clock();
//while(clock()<clockk0+2000);
//splash();
//clockk0=clock();
//while(clock()<clockk0+3000);
//system("cls");
////////////////new WorldCup or recent WorldCup?
printf("\n\n\n\n\n\tEnter What do you want : (write 'exit' to close the program)");
printf("\n\n\t1.New WorldCup.");
printf("\t\t\t\t2.Load Recent WorldCup.\n");//////////to do ******************
int a=1;
while(a)
{
char *n=(char *)calloc(10,sizeof(char));
scanf("%s",n);
if (strcmp(n,"1")==0 || strcmp(n,"2")==0 ||strcmp(n,"exit")==0)
{
if(strcmp(n,"1")==0)
{
system("cls");
startNewWorldCup();
a=0;
}
else if(strcmp(n,"2")==0)
{
loadRecentWorldCup();
a=0;
}
else if(strcmp(n,"exit")==0)
{
a=0;
}
}
else
{
puts("Choose your number from list please!");
}
free(n);
n=NULL;
}
}
void loadRecentWorldCup()
{
FILE *proceeds=fopen("Proceeds.txt","r");
if(proceeds)
{
fscanf(proceeds,"%d",&proceed);
fclose(proceeds);
proceeds=NULL;
FILE *managment1=fopen("teamNames.txt","r");
char line[5000]={};
int team=0;
int i=0;
while(i<32)
{
fscanf(managment1,"%s",teamNamesandNums[i]);
i++;
}
fclose(managment1);
managment1=NULL;
////////head of player here !!!!!!!!!!!!!!!!!!!
player_node *head_player=(player_node *)calloc(1,sizeof(player_node));
teams_node * head_teams=(teams_node *)calloc(1,sizeof(teams_node));
playerReadInfo(head_player);
loadGrouping(head_teams);
readTeamsInfo(head_teams);
readgPlans_MatchTable_selectedTeam();
sortGroups(head_teams);
mainMenu(head_player,head_teams);
}
}
void startNewWorldCup()
{
proceed=0;
/*FILE *result = fopen("ResultOfGroupingGames.txt","w");
fclose(result);
result=NULL; VERY IMPORTANT
FILE *teamsInfo = fopen("teamsInfo.txt","w");
fclose(teamsInfo);
teamsInfo=NULL;
*/
////////head of player here !!!!!!!!!!!!!!!!!!!
player_node *head_player=(player_node *)calloc(1,sizeof(player_node));
teams_node * head_teams=(teams_node *)calloc(1,sizeof(teams_node));
system("cls");
printf("\n\n\n\n\n\tEnter What do you want : (write 'exit' to close the program)");
printf("\n\n\t1.New group balloting for WorldCup.");
printf("\t\t\t\t2.Load the WorldCup's groups.\n");
int a=1;
while(a)
{
char *n=(char *)calloc(10,sizeof(char));
scanf("%s",n);
if (strcmp(n,"1")==0 || strcmp(n,"2")==0 ||strcmp(n,"exit")==0)
{
if(strcmp(n,"1")==0)
{
system("cls");
worldCupnewGrouping=1;
loadGrouping(head_teams);
a=0;
}
else if(strcmp(n,"2")==0)
{
worldCupnewGrouping=0;
loadGrouping(head_teams);
a=0;
}
else if(strcmp(n,"exit")==0)
{
exitt=1;
a=0;
}
}
else
{
puts("Choose your number from list please!");
}
free(n);
n=NULL;
}
if(!exitt)
{
loadGrouping(head_teams);
selectTeamsToManagement();
FILE *managment=fopen("teamNames.txt","r");
int i=0;
while(i<32)
{
fscanf(managment,"%s",teamNamesandNums[i]);
i++;
}
loadPlayersInformationFirstTime(head_player);
doSkills(head_teams,head_player);
gamePlan(head_player,head_teams);
setTempPosts(head_player,head_teams);
mainMenu(head_player,head_teams);
//playerWriteInfo(head_player);
//writegPlans_MatchTable_selectedTeam();
//readgPlans_MatchTable_selectedTeam();
}
if(!exitt)
{
customization(head_player,head_teams);
//playerWriteInfo(head_player);
//writegPlans_MatchTable_selectedTeam();
}
//if(!exitt)
//matchControllerGroups(head_player,head_teams);
}
void mainMenu(player_node *headp,teams_node * headt)
{
player_node * pp=(player_node *)calloc(1,sizeof(player_node));
teams_node * pt=(teams_node *)calloc(1,sizeof(teams_node));
pp=headp;
pt = headt;
int a=1;
int v=0;
while(a)
{
system("cls");
puts("\t\t\t\t\t ======= Main Menu =======");
puts("\n\n");
puts("\t\tEnter what do you want :");
puts("\t\t\tlineup\n\t\t\ttable\n\t\t\tfixture\n\t\t\tproceed (number of proceeds)\n\t\t\tsave\n\t\t\texit");
char *n=(char *)calloc(15,sizeof(char));
scanf("%s",n);
if (strcmp(n,"lineup")==0 || strcmp(n,"table")==0 ||strcmp(n,"fixture")==0 || strcmp(n,"proceed")==0 || strcmp(n,"save")==0 || strcmp(n,"exit")==0)
{
if(strcmp(n,"lineup")==0)
{
system("cls");
customization(pp,pt);
//a=0;
}
else if(strcmp(n,"table")==0)
{
system("cls");
mainTable(pt);
//a=0;
}
else if(strcmp(n,"fixture")==0)
{
system("cls");
fixture();
//a=0;
}
else if(strcmp(n,"proceed")==0)
{
int w=1;
scanf("%d",&v);
while (w)
{
if(v<8 && v >0)
{
system("cls");
matchControllerGroups(pp,pt,v);
w=0;
}
else
{
printf("proceed needs a 0<number<8 !!!!!");
}
}
}
else if(strcmp(n,"save")==0)
{
system("cls");
playerWriteInfo(pp);
writeTeamsInfo(pt);
writegPlans_MatchTable_selectedTeam();
//a=0;
}
else if(strcmp(n,"exit")==0)
{
system("cls");
exitt=1;
a=0;
}
}
else
{
puts("Choose your order from list please!");
}
free(n);
n=NULL;
}
}
void customization(player_node *headp,teams_node * headt)
{
player_node * pp=(player_node *)calloc(1,sizeof(player_node));
teams_node * pt=(teams_node *)calloc(1,sizeof(teams_node));
pt = headt;
pp=headp;
system("cls");
printf("\n\n\t\t\t\t ====Customization form====");
printf("\n\n\n\tEnter What do you want : (write 'exit' to close the program)");
printf("\n\n\t1.Manual GamePlan.");
printf("\t\t\t\t2.Automatical Best game plan.\n");
int a=1;
while(a)
{
char *n=(char *)calloc(10,sizeof(char));
scanf("%s",n);
if (strcmp(n,"1")==0 || strcmp(n,"2")==0 ||strcmp(n,"exit")==0)
{
if(strcmp(n,"1")==0)
{
system("cls");
CustomizationManualform(pp,pt);
a=0;
}
else if(strcmp(n,"2")==0)
{
a=0;
}
else if(strcmp(n,"exit")==0)
{
exitt=1;
a=0;
}
}
else
{
puts("Choose your number from list please!");
}
free(n);
n=NULL;
}
}
void CustomizationManualform(player_node * headp,teams_node *headt)
{
player_node * pp=(player_node *)calloc(1,sizeof(player_node));
teams_node * pt=(teams_node *)calloc(1,sizeof(teams_node));
pt = headt;
pp = headp;
int gameSystem[4]={442,352,541,433};
system("cls");
printf("\n\n\t\t\t\t ====Customization Manual form====");
printf("\n\n\n\tEnter What do you want : (write 'exit' to close the program)");
printf("\n\n\t1.4-4-2");
printf("\t\t2.3-5-2");
printf("\t\t3.5-4-1");
printf("\t\t4.4-3-3\n");
int r=0;
for(r=0;strcmp(teamNamesandNums[r],selectedTeam);r++);
int a=1;
int order=0;
while(a)
{
char *n=(char *)calloc(10,sizeof(char));
scanf("%s",n);
if (strcmp(n,"1")==0 || strcmp(n,"2")==0 ||strcmp(n,"exit")==0 ||strcmp(n,"3")==0||strcmp(n,"4")==0)
{
if(strcmp(n,"1")==0)
{
order=1;
bestPlanForManagment(pp,gameSystem[order-1],r+1);
setTempNull(pp);
setTempPosts(pp,pt);
system("cls");
a=0;
}
else if(strcmp(n,"2")==0)
{
order=2;
bestPlanForManagment(pp,gameSystem[order-1],r+1);
setTempNull(pp);
setTempPosts(pp,pt);
system("cls");
a=0;
}
else if(strcmp(n,"3")==0)
{
order=3;
bestPlanForManagment(pp,gameSystem[order-1],r+1);
setTempNull(pp);
setTempPosts(pp,pt);
system("cls");
a=0;
}
else if(strcmp(n,"4")==0)
{
order=4;
bestPlanForManagment(pp,gameSystem[order-1],r+1);
setTempNull(pp);
setTempPosts(pp,pt);
system("cls");
a=0;
}
else if(strcmp(n,"exit")==0)
{
exitt=1;
system("cls");
a=0;
}
}
else
{
puts("Choose your number from list please!");
}
free(n);
n=NULL;
}
if(exitt==0)
{
system("cls");
printf("\n\n\t\t\t\t ====Customization Substitution form====");
printf("\n\n\n\tEnter What do you want : (write 'exit' to close the program)");
printf("\n\n\t1.I don't want Substitutions.");
printf("\t\t\t2.Change my players in game\n ");
}
///////////////save gPlan and balloting
char np=0;
if(exitt==0)
a=1;
while(a)
{
char *n=(char *)calloc(10,sizeof(char));
scanf("%s",n);
if (strcmp(n,"1")==0 || strcmp(n,"2")==0 ||strcmp(n,"exit")==0)
{
if(strcmp(n,"1")==0)
{
//setTempPosts(pp,pt);
/////show the players is in game
system("cls");
showPlayersofUser(pp);
puts("Enter any key to continue . . .");
np=getchar();
a=0;
}
else if(strcmp(n,"2")==0)
{
/////go to changing players system
system("cls");
pp=headp;
showPlayersofUser(pp);
pp=headp;
changingPlayerofUser(pp,pt);
a=0;
}
else if(strcmp(n,"exit")==0)
{
exitt=1;
system("cls");
a=0;
}
}
else
{
puts("Choose your number from list please!");
}
free(n);
n=NULL;
}
}
void changingPlayerofUser(player_node * headp,teams_node *headt)
{
printf("\n\t\t\t\t ====Substitution Mode====");
player_node * pp=(player_node *)calloc(1,sizeof(player_node));
teams_node * pt=(teams_node *)calloc(1,sizeof(teams_node));
pp=headp;
pt = headt;
int a=1;
int x=0,y=0;
int r=0;
int counter=0;
for(r=0;strcmp(teamNamesandNums[r],selectedTeam);r++);
while(a)
{
counter=0;
pp=headp;
pt = headt;
printf("\n\t\tTo do Substitution First Choose player is in the plan then Choose player is out of plan please(player's Number in plan / player's Number out of plan)\n");
scanf("%d%d",&x,&y);
for(int u=0;u<11;u++)
{
if(gPlan[r][u]==x)
{
counter++;
}
}
for(int u=0;u<11;u++)
{
if(gPlan[r][u]==y)
{
counter=2;
}
}
if(counter==1)
{
int q=0;
for(q=0;gPlan[r][q]!=x;q++);
gPlan[r][q]=y;
//////////////
doSubstitution(pp,pt,x,y);
pp=headp;
updateGamePlan(pp);
system("cls");
pp=headp;
showPlayersofUser(pp);
}
else
{
continue;
}
///////////////
printf("\n\t\tDo you have more Substitution?(Yes -> 1 / No -> 0)\n");
scanf("%d",&a);
}
}
void doSubstitution(player_node * headp,teams_node * headt,int x,int y)
{
player_node * pp=(player_node *)calloc(1,sizeof(player_node));
teams_node * pt=(teams_node *)calloc(1,sizeof(teams_node));
pp=headp;
pt = headt;
int istrue=0;
player_node * ppp=(player_node *)calloc(1,sizeof(player_node));
player_node * pppp=(player_node *)calloc(1,sizeof(player_node));
char * postt=(char *)calloc(2,sizeof(char));
////////////////
int r=0;
for(r=0;strcmp(teamNamesandNums[r],selectedTeam);r++);
char *teamName = (char *)calloc(30,sizeof(char));
strcpy(teamName,selectedTeam);
/////////////
ppp=search_playerNumber_teams(pp,x,teamName);
printf("%s\n",ppp->name);
pppp=search_playerNumber_teams(pp,y,teamName);
strcpy(postt,ppp->tempPost);
strcpy(ppp->tempPost,"N");
strcpy(pppp->tempPost,postt);
printf("%s",pppp->name);
}
void showPlayersofUser(player_node * headp)
{
printf("\t\t\t\t ====Players In Game====");
player_node * pp=(player_node *)calloc(1,sizeof(player_node));
pp=headp;
player_node * ppp=(player_node *)calloc(1,sizeof(player_node));
int counter=0;
while(pp && counter <11)
{
ppp=search_teamName_forPlayer(pp,selectedTeam);
printf("\n\t\t%3d-%-25s | Skill : %3d | Form : %3d | Fitness : %3d | Main Post : %s | Post : %s |",ppp->number,ppp->name,ppp->skill,ppp->form,ppp->fitness,ppp->mainPost,ppp->tempPost);
counter++;
pp= ppp->next;
}
pp=headp;
ppp=NULL;
int istrue=0;
printf("\n===========================================================================================================");
printf("\n\t\t\t\t ====Players Out Game====");
while(pp && istrue!=2)
{
if(strcmp(pp->nation,selectedTeam)==0)
{
ppp=search_post_temp(pp,"N",selectedTeam);
if(ppp)
{
printf("\n\t\t%2d-%-25s | Skill : %3d | Form : %3d | Fitness : %3d | Main Post : %s | Post : %s |",ppp->number,ppp->name,ppp->skill,ppp->form,ppp->fitness,ppp->mainPost,ppp->tempPost);
pp= ppp->next;
istrue=1;
if(strcmp(pp->nation,selectedTeam)!=0)
istrue=2;
}
else
{
istrue=2;
}
}
else if(istrue==0)
{
pp= pp->next;
}
}
}
void loadPlayersInformationFirstTime(player_node * head_players)
{
int teamsNumber=32;
FILE *teams = fopen("teamNames.txt","r");
const char * formatt=".txt";
const char *dir="players\\";
if (!teams) {
perror("fopen failed : \nCheck Files and then run program again!");
return;
}
//player_node *head_players = (player_node *)calloc(1, sizeof(player_node));
player_node *pp =(player_node*)calloc(1,sizeof(player_node));
pp=head_players;////////////////////////********
while(teamsNumber)
{
char *teamsName=(char *)calloc(15,sizeof(char));
char *teamNamee=(char *)calloc(15,sizeof(char));
fscanf(teams,"%s",teamsName);
strcat(teamNamee,append(append(dir,teamsName),formatt));
FILE *tp = fopen(teamNamee,"r");
if (!tp) {
perror("fopen failed : \nCheck Files and then run program again!");
return;
}
pp=playersReadInfo(tp,pp,teamsName);
fclose(tp);
tp=NULL;
teamsName=NULL;
teamsNumber--;
}
}
void newGrouping(teams_node * head_team)
{
char line[100]={};
int counter=0;
teams_node *pt=(teams_node*)calloc(1,sizeof(teams_node));
pt=head_team;
teams_node *pd=(teams_node *)calloc(1,sizeof(teams_node));
/////////do balloting for new grouping
tableToNULL();
balloting();
////////////////
printtable();
char *teamName=(char *)calloc(25,sizeof(char));
//char teamNamesandNums[32][25]={};
char *statee=(char*)calloc(2,sizeof(char));
for(int i=0;i<4;i++)
{
for(int j=0;j<8;j++)
{
strcpy(teamName,teamNamesandNums[matchTable[i][j]%100-1]);
pd=searchTeamForGrouping(pt,teamName);
if(j==0)
strcpy(statee,"A");
else if(j==1)
strcpy(statee,"B");
else if (j==2)
strcpy(statee,"C");
else if(j==3)
strcpy(statee,"D");
else if(j==4)
strcpy(statee,"E");
else if (j==5)
strcpy(statee,"F");
else if(j==6)
strcpy(statee,"G");
else if(j==7)
strcpy(statee,"H");
/////////////////
strcpy(pd->group,statee);
pd->state=i+1;
/////////////////
}
}
free(teamName);
teamName=NULL;
}
teams_node *searchTeamForGrouping(teams_node * head_team,const char * teamName)
{
teams_node *p=(teams_node *)calloc(1,sizeof(teams_node));
p=head_team;
while(p)
{
if(strcmp(p->teamName,teamName)==0)
{
return p;
}
else
p=p->next;
}
return NULL;
}
void loadGrouping(teams_node * head_teams)
{
/////////first this ganna run
FILE *tt = fopen("players\\teams.txt","r");
teams_node *pt=(teams_node *)calloc(1,sizeof(teams_node));///////////////////////*****************
pt=head_teams;
//////////////////teams info grouping and ... from file ***********
teamsReadInfofromGlobal(tt,pt);
///loadGroupingInfo
if(worldCupnewGrouping==1)
newGrouping(pt);
}
player_node * playersReadInfo(FILE *t,player_node *p,const char * teamNamee)
{
char line[100]={};
int counter=0;
//////this ganna change
for(int i=0;fgets(line,100,t)!=NULL;i++)
{
int num;
char *namee=(char *)calloc (25,sizeof(char));
char *postt=(char *)calloc (1,sizeof(char));
char *postt_temp=(char *)calloc (1,sizeof(char));
int age;
fscanf(t,"%d%s%d%s",&num,namee,&age,postt);
counter++;
/////////////file of players
p->number=num;
strcpy(p->name,namee);
strcpy(p->mainPost,postt);
strcpy(p->tempPost,postt_temp);
p->age=age;
/////////////our calculations
strcpy(p->nation,teamNamee);
////////////
p->next = (player_node *)calloc(1, sizeof(player_node));
p = p->next;
free(namee);
postt_temp=NULL;
postt=NULL;
namee=NULL;
}
return p;
}
void teamsReadInfofromGlobal(FILE *t,teams_node *p)///////sould copy this to our grouping system
{
char line[100]={};
int counter=0;
const char * space=" ";
for(int i=0;fgets(line,100,t)!=NULL;i++)
{
char *namee=(char *)calloc (20,sizeof(char));
char groupp[1]={};
int statee;
char *confidd=(char *)calloc (15,sizeof(char));
int seedd;
fscanf(t,"%s%s%d%s%d",namee,groupp,&statee,confidd,&seedd);
counter++;
/////////////file of teams
strcpy(p->teamName,namee);
strcpy(p->group,groupp);
p->state=statee;
strcpy(p->confed,confidd);
p->seed=seedd;
/////////////our calculations
strcat(teamNames,append(namee,space));
////////////
namee=NULL;
confidd=NULL;
p->next = (teams_node *)calloc(1, sizeof(teams_node));
p = p->next;
}
FILE *set=fopen("teamNames.txt","w");
fprintf(set,"%s",teamNames);
fclose(set);
set=NULL;
}
void splash()
{
clock_t clockk0=0;
puts("=========================================================================================================================");
puts("=========================================================================================================================");
puts("");
puts("");
clockk0=clock();
while(clock()<clockk0+300);
puts("WW WW WW OOOOOOOOOO RRRRRRRRRR LL DDDDDDDD CCCCCCCCC UU UU PPPPPPPPPP");
clockk0=clock();
while(clock()<clockk0+300);
puts(" WW WW WW WW OO OO RR RR LL DD D CC UU UU PP PP");
clockk0=clock();
while(clock()<clockk0+300);
puts(" WW WW WW WW OO OO RR RR LL DD D CC UU UU PP PP");
clockk0=clock();
while(clock()<clockk0+300);
puts(" WW WW WW WW OO OO RRRRRRRR LL DD D CC UU UU PPPPPPPPP");
clockk0=clock();
while(clock()<clockk0+300);
puts(" WW WW WW WW OO OO RR RR LL DD D CC UU UU PP");
clockk0=clock();
while(clock()<clockk0+300);
puts(" WW WW OOOOOOOOOO RR RR LLLLLLLL DDDDDDD CCCCCCCCC UUUUUUUUUU PP");
clockk0=clock();
while(clock()<clockk0+300);
puts("");
puts("");
clockk0=clock();
while(clock()<clockk0+300);
puts("=========================================================================================================================");
puts("");
puts("");
clockk0=clock();
while(clock()<clockk0+300);
puts(" 2222222222222 0000000000000 11 8888888888888");
clockk0=clock();
while(clock()<clockk0+300);
puts(" 22 00 00 11 88 88");
clockk0=clock();
while(clock()<clockk0+300);
puts(" 22 00 00 11 88 88");
clockk0=clock();
while(clock()<clockk0+300);
puts(" 2222222222222 00 00 11 8888888888888");
clockk0=clock();
while(clock()<clockk0+300);
puts(" 22 00 00 11 88 88");
clockk0=clock();
while(clock()<clockk0+300);
puts(" 22 00 00 11 88 88");
clockk0=clock();
while(clock()<clockk0+300);
puts(" 2222222222222 0000000000000 11 8888888888888");
clockk0=clock();
while(clock()<clockk0+300);
puts("");
puts("");
puts("=========================================================================================================================");
puts("=========================================================================================================================");
}
char* append(const char* name,const char* extension)
{
char* name_with_extension;
name_with_extension =(char *) malloc(strlen(name)+1+4);
strcpy(name_with_extension, name);
strcat(name_with_extension, extension);
return name_with_extension;
}
void selectTeamsToManagement()
{
FILE *managment=fopen("teamNames.txt","r");
char line[5000]={};
int team=0;
int numTeams=1,i=0;
puts("Enter Number of your team that you want to manage");
while(numTeams<33)
{
fscanf(managment,"%s",teamNamesandNums[i]);
printf("%2d.%s\n",numTeams,teamNamesandNums[i]);
numTeams++;
i++;
}
fclose(managment);
managment=NULL;
while(1)
{
scanf("%d",&team);
if( team<33 && team>0)
{
break;
}
else
{
puts("choose team number from list!!");
}
}
printf("Your team is : %s", teamNamesandNums[team-1]);
strcpy(selectedTeam,teamNamesandNums[team-1]);
return;
}
void balloting()
{
//srand((unsigned)time(NULL));
int teamsOrginal[32]={1101,1303,1104,1311,1312,1322,1323,1324,2105,2307,2310,2517,2121,2328,2330,2132,3506,3308,3409,3313,3214,3426,3329,3431,4202,4215,4216,4418,4419,4520,4225,4327};
int teams[32]={1101,1303,1104,1311,1312,1322,1323,1324,2105,2307,2310,2517,2121,2328,2330,2132,3506,3308,3409,3313,3214,3426,3329,3431,4202,4215,4216,4418,4419,4520,4225,4327};
int group=0;
int checkTable=1;
while(checkTable)
{
copyTeams(teamsOrginal,teams);
tableToNULL();
int team=0;
int counter=0;
for(;counter!=8;)
{
team=rand()%8;
if(matchTable[0][counter]==0&&teams[team]!=0)
{
matchTable[0][counter]=teams[team];
teams[team]=0;
counter++;
}
}
counter=0;
int counter2=0;
for(;counter2!=8;)
{
if(matchTable[1][counter]==0)
{
team=rand()%8+8;
if(teams[team]!=0)
{
if(check(1,counter,teams[team]))
{
matchTable[1][counter]=teams[team];
teams[team]=0;
counter2++;
counter=0;
}
else
{
counter++;
}
}
}
else
{
counter++;
}
}
counter2=0;