-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
1191 lines (1100 loc) · 34.9 KB
/
main.cpp
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 <cstdlib> //necessary for system function
#include <conio.h> //necessary for getch();
#include <stdio.h> //necessary for fundemental C codes (scanf printf etc.)
#include <time.h> // necessary for TIME function ---> random (srand TIME NULL) to roll different dices
// Author: VK
// Date: 2012.12.02
void rolldice(int zarlar[]); //function that rolls dices
void boardd(char pullar[24][15]); //function that shows screen
void pullaridiz(char pullar[24][15]); //it sets pieces
void informasiyon(int zarlar[], int wbr, int bbr, int wcl, int bcl, char turn); //informations about situation of the game at the end of the screen
void oyna(char pullar[24][15], int n1, int hamle, char sira); // function that moves the pieces
int hamlekontrol(char pullar[24][15], int n1, int hamle, char sira, int bbr, int wbr, int wcl, int bcl); //function that control the moves
void siradegis(char *sira); // function that changes the order of game to one player to the other
int zarkontrol(int zarlar[], int hamle); //function that controls whether the numbers of dices and movements of pieces are same or not
void pulkir(char pullar[24][15], int n1, int hamle, char sira, int* wbr, int* bbr); //function that is necessary to play for breaking pieces
int kirikkont(char sira, int wbr, int bbr); //function that controls whether there is a broken piece or not. if so, it doesn't allow to play as a normal
void ozpulkir(char pullar[24][15], int hamle, char sira, int* wbr, int* bbr); //function that allows to broke pieces when we have a broken pieces that is outside
void ozoyna(char pullar[24][15], int hamle, char sira, int* wbr, int* bbr); // function that allows to play when we have a broken piece
int tkontrol(char pullar[24][15], char sira); //function that controls whether we collect the pieces or not
int tkontrol2(char pullar[24][15], char sira, int n1, int hamle); //if we can collect the pieces, it allows to collect only possible pieces
void topla(char pullar[24][15], int n1, int *wcl, int *bcl, char sira); //function that collects pieces
void Vk(char pullar[24][15], char sira, int bbr, int wbr, int wcl, int bcl, int zarlar[], int* kats, int* pbbr, int* pwbr, int* pwcl, int* pbcl); //Artifical intellegent
int hamlebul(int olasi[24][2], char pullar[24][15], int zarlar[], int wbr, char sira); // function that finds possible movements
int hamleyapabilirmi(char pullar[24][15], int zarlar[], int bbr, char sira); /*if a player can not move or he do not have a possible movements, this
function change the order of game*/
int fkontrol1(char pullar[24][15], int n1, char *fsira); // Controls move for HOMEWORK
int TestMali(char pullar[24][15], int n1, int hamle, int *bbr, int *wbr, int *wcl, int *bcl); //Homework function
int main(int argc, char *argv[])
{
int zarlar[2]; //dice
int n1,hamle; //position and move
int wbr=0; //broken whites
int bbr=0; //broken blacks
int wcl=0; //collected whites
int bcl=0; //collected blacks
char sira=' '; //turn
int kats=0; //to play with couple dices (cift zar)
char pullar[24][15]; // list of pieces
int style;
int uuu =1;
pullaridiz(pullar);
rolldice(zarlar);
if(zarlar[0]>=zarlar[1]) //a player that has a big number of dieces can start first
{
sira = 'B';
}else
{
sira = 'W';
}
printf("---------------------- WELCOME TO THE BACKGAMMON GAME ----------------------\n\n");
printf("! Please read the instructions TO PLAY CORRECTLY !\n\n\n");
printf("If it is your turn(i.e., Blacks), enter your numbers in form of a,b to play:\n");
printf("a= location of the piece you will play and b= number of change in location\n\n");
printf("If it is CPU's turn (e.g., Whites), just click any button to see and pass its move\n\n");
printf("And in your turn, please DO NOT ENTER A STRING\n\n\n\n");
printf("If you have a broken piece and you want to go in, you should play like: \na=0 and b is the dice you want to start with (e.g. 0,4) \n\n");
printf("If you do not have a possible move:\nEnter a random number and a NEGATIVE NUMBER (e.g. 2,-4)\n\n");
printf("VK, 2012.12.02\n\n");
printf("------------------------- CLICK ANY BUTTON TO START -------------------------\n\n");
getch();
system("CLS"); //to clean the screen
printf("Please enter 1 for normal game,\n2 for homework type game,\nother number to exit game : ");
scanf("%d",&style);
if((style==1)||(style==2))
{}
else
{ printf("You inputted other value, game will exit\n"); getch(); exit(EXIT_FAILURE);}
system("CLS"); //to clean the screen
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl, sira);
system("color 27"); //to change the background color and the text color (2 = background, 7 = text color)
while(!(wcl==15 || bcl==15)) // loop that continues until the end of the game
{
if(style==1)
{
if(kats==7)
{
kats=0;
}else
{
if(((zarlar[0]!=0)||(zarlar[1]!=0))&&(zarlar[0]==zarlar[1]))
{
kats=zarlar[0];
}
}
if((zarlar[0]!=0)||(zarlar[1]!=0))
{
if(sira=='B')
{
printf("Move : ");
scanf("%d,%d",&n1,&hamle); //it asks how many location you want to move
}else
{
Vk(pullar, sira, bbr, wbr, wcl, bcl, zarlar, &kats, &bbr, &wbr, &wcl, &bcl);
}
}
if((zarlar[0]==0)&&(zarlar[1]==0))
{
if(kats==0)
{
siradegis(&sira);
rolldice(zarlar);
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(kats!=0)
{
zarlar[0]=kats;
zarlar[1]=kats;
kats=7;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}else
{if(sira=='B'){
int yap=hamleyapabilirmi(pullar, zarlar, bbr, sira);
if(hamle<0)
{
if(yap==0)
{
zarlar[0]=0; zarlar[1]=0; kats=0;
}else
{
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
printf("Invalid move! Because you can make a move.\n");
}
} //if move is negative, order will change
else if((hamlekontrol(pullar, (n1-1), hamle, sira, bbr, wbr, wcl, bcl)==0)||(zarkontrol(zarlar, hamle)==0))
{
if(sira=='B')
{
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
printf("Invalid move!\n");
}
}else
{
int x2 = hamlekontrol(pullar, (n1-1), hamle, sira, bbr, wbr, wcl, bcl);
if(x2>9)
{
if(x2==20)
{
if(hamle==zarlar[0])
{
ozpulkir(pullar, hamle, sira, &wbr, &bbr);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
ozpulkir(pullar, hamle, sira, &wbr, &bbr);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}else if(x2==10)
{
if(hamle==zarlar[0])
{
ozoyna(pullar, hamle, sira, &wbr, &bbr);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
ozoyna(pullar, hamle, sira, &wbr, &bbr);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}
}else
{
if(x2==2)
{
if(hamle==zarlar[0])
{
pulkir(pullar,(n1-1),hamle,sira, &wbr, &bbr);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
pulkir(pullar,(n1-1),hamle,sira, &wbr, &bbr);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}else if(x2==4)
{
if(hamle==zarlar[0])
{
topla(pullar, (n1-1), &wcl, &bcl, sira);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
topla(pullar, (n1-1), &wcl, &bcl, sira);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}
else
{
if(hamle==zarlar[0])
{
oyna(pullar,(n1-1),hamle,sira);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
oyna(pullar,(n1-1),hamle,sira);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}
}
}}
}
}else
{
zarlar[0] = 0;
zarlar[1] = 0;
sira ='?';
system("CLS"); //to clean the screen
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl, sira);
if(uuu==0)
{printf("Invalid Move!\n");}
printf("Move : ");
scanf("%d,%d",&n1,&hamle); //it asks how many location you want to move
uuu = TestMali(pullar, (n1-1), hamle, &bbr, &wbr, &wcl, &bcl);
if(uuu==10){ printf("Oyundan cikmak istediniz, cikmak icin bir tusa basin."); getch(); exit(EXIT_FAILURE);}
}
}
if(wcl==15)
{
printf("Whites WON\n");
}else if(bcl==15)
{
printf("Blacks WON\n");
}else
{
printf("HATA\n");
}
system("PAUSE");
return EXIT_SUCCESS;
}
int TestMali(char pullar[24][15], int n1, int hamle, int *bbr, int *wbr, int *wcl, int *bcl)
{
int zarlar[2];
zarlar[0] =0;
zarlar[1] =0;
char fsira ='?';
int fk1 = fkontrol1(pullar, n1, &fsira);
if((hamle==100)&&(n1==99))
{
return 10;
}else if(fk1==0)
{
return 0;
}else
{
int x2 = hamlekontrol(pullar, n1, hamle, fsira, *bbr, *wbr, *wcl, *bcl);
if(x2==0)
{
return 0;
}
else
{
if(x2>9)
{
if(x2==20)
{
ozpulkir(pullar, hamle, fsira, wbr, bbr);
boardd(pullar);
informasiyon(zarlar, *wbr, *bbr, *wcl, *bcl, fsira);
}else if(x2==10)
{
ozoyna(pullar, hamle, fsira, wbr, bbr);
boardd(pullar);
informasiyon(zarlar, *wbr, *bbr, *wcl, *bcl, fsira);
}
}else
{
if(x2==2)
{
pulkir(pullar, n1,hamle, fsira, wbr, bbr);
boardd(pullar);
informasiyon(zarlar, *wbr, *bbr, *wcl, *bcl, fsira);
}else if(x2==4)
{
topla(pullar, n1, wcl, bcl, fsira);
boardd(pullar);
informasiyon(zarlar, *wbr, *bbr, *wcl, *bcl, fsira);
}
else
{
oyna(pullar, n1,hamle, fsira);
boardd(pullar);
informasiyon(zarlar, *wbr, *bbr, *wcl, *bcl, fsira);
}
}
}
}
}
int fkontrol1(char pullar[24][15], int n1, char *fsira)
{
if(n1==-1)
{
return 3;
}
else if(pullar[n1][0]==' ')
{
return 0;
}else if(pullar[n1][0]=='B')
{
*fsira ='B';
return 1;
}else if(pullar[n1][0]=='W')
{
*fsira = 'W';
return 1;
}
}
int hamleyapabilirmi(char pullar[24][15], int zarlar[], int bbr, char sira)
{
int uhu=1;
if(bbr>0)
{
int a=1;
if((pullar[zarlar[0]-1][1]!='W')&&(zarlar[0]!=0))
{ a++;}
if((pullar[zarlar[1]-1][1]!='W')&&(zarlar[1]!=0))
{ a++;}
if(a==1){uhu = 0;}
}else
{
if(tkontrol(pullar, sira)==1)
{
int a=1;
int zar1,zar2;
zar1 = zarlar[0];
zar2 = zarlar[1];
bool u1,u2;
if(zar1==0)
{
u1 = false;
}else
{
u1 = (pullar[24-zar1][0]=='B');
}
if(zar2==0)
{
u2 = false;
}else
{
u2 = (pullar[24-zar2][0]=='B');
}
if(u1||u2)
{
if(u1)
{ a++;}
if(u2)
{ a++; }
}
else
{
int red=1;
if(zar1!=0)
{
for(int i=18; i<(24-zar1); i++)
{
if(pullar[i][0]=='B')
{red=0;}
}
if(red==1)
{ a++; }
}
if(zar2!=0)
{
for(int i=18; i<(24-zar2); i++)
{
if(pullar[i][0]=='B')
{red=0;}
}
if(red==1)
{ a++; }
}
}
}
else
{
int a=1;
if(zarlar[0]!=0)
{
for(int x1=(23-zarlar[0]); x1>0; x1--)
{
if(((pullar[x1+(zarlar[0])][1])!='W') &&(pullar[x1][0]=='B'))
{
a++;
}
}
}
if(zarlar[1]!=0)
{
for(int x2=(23-zarlar[1]); x2>0; x2--)
{
if((pullar[x2+(zarlar[1])][1]!='W') &&(pullar[x2][0]=='B'))
{
a++;
}
}
}
if(a==1){uhu = 0;}
}
}
return uhu;
}
void Vk(char pullar[24][15], char sira, int bbr, int wbr, int wcl, int bcl, int zarlar[], int* kats, int* pbbr, int* pwbr, int* pwcl, int* pbcl)
{
int cpu=0;
int n1,hamle;
int olasi[24][2];
olasi[0][0]=0;
olasi[0][1]=-1;
getch();
int mali = hamlebul(olasi, pullar, zarlar, wbr, sira);
n1 = olasi[mali][0];
hamle = olasi[mali][1];
while(cpu==0)
{if(hamle<0){zarlar[0]=0; zarlar[1]=0; (*kats)=0; cpu=1;//if "hamle" is negative, order will change
}else if((hamlekontrol(pullar, (n1-1), hamle, sira, bbr, wbr, wcl, bcl)==0)||(zarkontrol(zarlar, hamle)==0))
{
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
printf("Invalid move!\n");
}else
{
int x2 = hamlekontrol(pullar, (n1-1), hamle, sira, bbr, wbr, wcl, bcl);
if(x2>9)
{
if(x2==20)
{
if(hamle==zarlar[0])
{
cpu=1;
ozpulkir(pullar, hamle, sira, &wbr, &bbr);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
cpu=1;
ozpulkir(pullar, hamle, sira, &wbr, &bbr);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}else if(x2==10)
{
if(hamle==zarlar[0])
{
cpu=1;
ozoyna(pullar, hamle, sira, &wbr, &bbr);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
cpu=1;
ozoyna(pullar, hamle, sira, &wbr, &bbr);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}
}else
{
if(x2==2)
{
if(hamle==zarlar[0])
{
cpu=1;
pulkir(pullar,(n1-1),hamle,sira, &wbr, &bbr);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
cpu=1;
pulkir(pullar,(n1-1),hamle,sira, &wbr, &bbr);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}else if(x2==4)
{
if(hamle==zarlar[0])
{
cpu=1;
topla(pullar, (n1-1), &wcl, &bcl, sira);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
cpu=1;
topla(pullar, (n1-1), &wcl, &bcl, sira);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}
else
{
if(hamle==zarlar[0])
{
cpu=1;
oyna(pullar,(n1-1),hamle,sira);
zarlar[0]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}else if(hamle==zarlar[1])
{
cpu=1;
oyna(pullar,(n1-1),hamle,sira);
zarlar[1]=0;
boardd(pullar);
informasiyon(zarlar, wbr, bbr, wcl, bcl,sira);
}
}
}
}
}
*pwbr = wbr;
*pbbr = bbr;
*pwcl = wcl;
*pbcl = bcl;
}
int hamlebul(int olasi[24][2], char pullar[24][15], int zarlar[], int wbr, char sira)
{
int uhu;
if(wbr>0)
{
int a=1;
olasi[1][0] = 0;
if((pullar[24-(zarlar[0])][1]!='B')&&(zarlar[0]!=0))
{
olasi[a][0] = 0;
olasi[a][1]=zarlar[0];
a++;
}
if((pullar[24-(zarlar[1])][1]!='B')&&(zarlar[1]!=0))
{
olasi[a][0] = 0;
olasi[a][1]=zarlar[1];
a++;
}
if(a==1){uhu = 0;}
else
{
srand ( (unsigned)time( NULL ) ); // for different dices
uhu = (rand()%(a-1))+1;
}
}else
{
if(tkontrol(pullar, sira)==1)
{
int a=1;
int zar1,zar2;
zar1 = zarlar[0];
zar2 = zarlar[1];
bool u1,u2;
if(zar1==0)
{
u1 = false;
}else
{
u1 = (pullar[zar1-1][0]=='W');
}
if(zar2==0)
{
u2 = false;
}else
{
u2 = (pullar[zar2-1][0]=='W');
}
if(u1||u2)
{
if(u1)
{
olasi[a][0] = zar1;
olasi[a][1] = zar1;
a++;
}
if(u2)
{
olasi[a][0] = zar2;
olasi[a][1] = zar2;
a++;
}
if(a==1){uhu = 0;}
else
{
srand ( (unsigned)time( NULL ) );
uhu = (rand()%(a-1))+1;
}
}
else
{
int red=1;
if(zar1!=0)
{
for(int i=5; i>(zar1-1); i--)
{
if(pullar[i][0]=='W')
{red=0;}
}
if(red==1)
{
olasi[a][0] = zar1;
olasi[a][1] = zar1;
a++;
}
}
if(zar2!=0)
{
for(int i=5; i>(zar2-1); i--)
{
if(pullar[i][0]=='W')
{red=0;}
}
if(red==1)
{
olasi[a][0] = zar2;
olasi[a][1] = zar2;
a++;
}
}
if(a==1){uhu = 0;}
else
{
srand ( (unsigned)time( NULL ) );
uhu = (rand()%(a-1))+1;
}
}
}
else
{
int a=1;
if(zarlar[0]!=0)
{
for(int x1=zarlar[0]; x1<24; x1++)
{
if(((pullar[x1-(zarlar[0])][1])!='B') &&(pullar[x1][0]=='W'))
{
olasi[a][0]= x1+1;
olasi[a][1]= zarlar[0];
a++;
}
}
}
if(zarlar[1]!=0)
{
for(int x2=zarlar[1]; x2<24; x2++)
{
if((pullar[x2-(zarlar[1])][1]!='B') &&(pullar[x2][0]=='W'))
{
olasi[a][0]= x2+1;
olasi[a][1]= zarlar[1];
a++;
}
}
}
if(a==1){uhu = 0;}
else
{
srand ( (unsigned)time( NULL ) );
uhu = (rand()%(a-1))+1;
}
}
}
return uhu;
}
void topla(char pullar[24][15], int n1, int *wcl, int *bcl, char sira)
{
int kont1=0;
int kont2=14;
while(kont1==0)
{
if(pullar[n1][kont2]==sira)
{
pullar[n1][kont2]=' ';
kont1=1;
if(sira=='B')
{
(*bcl)++;
}else if(sira=='W')
{
(*wcl)++;
}
}
kont2--;
}
}
int tkontrol2(char pullar[24][15], char sira, int n1, int hamle)
{
int ret=1;
if(sira =='W')
{
if((n1-hamle)==-1)
{
ret=1;
}else
{
for(int i=5; i>(hamle-2); i--)
{
if(pullar[i][0]==sira)
{ret=0;}
}
for(int i=5; i>n1; i--)
{
if(pullar[i][0]==sira)
{ret=0;}
}
}
}else if(sira =='B')
{
if((n1+hamle)==24)
{
ret=1;
}else
{
for(int i=18; i<(25-hamle); i++)
{
if(pullar[i][0]==sira)
{ret=0;}
}
for(int i=18; i<n1; i++)
{
if(pullar[i][0]==sira)
{ret=0;}
}
}
}
return ret;
}
int tkontrol(char pullar[24][15], char sira)
{
int ret=0;
int t=0;
if(sira=='W')
{
for(int i=6; i<24; i++)
{
if(pullar[i][0]=='W')
{t++;}
}
}else if(sira=='B')
{
for(int i=0; i<18; i++)
{
if(pullar[i][0]=='B')
{t++;}
}
}
if(t==0)
{//if there are 15 pieces, this function allows to collect them
ret=1;
}
return ret;
}
void ozoyna(char pullar[24][15], int hamle, char sira, int* wbr, int* bbr)
{
int kont3=0;
int kont4=0;
while(kont3==0)
{
if(sira=='B')
{
if(pullar[hamle-1][kont4]==' ')
{
pullar[hamle-1][kont4]='B';
(*bbr)--;
kont3=1;
}
}else if(sira=='W')
{
if(pullar[24-hamle][kont4]==' ')
{
pullar[24-hamle][kont4]='W';
(*wbr)--;
kont3=1;
}
}kont4++;
}
}
int kirikkont(char sira, int wbr, int bbr)
{
int retur;
if(sira=='B')
{
if(bbr==0)
{
retur=1;
}else
{
retur=0;
}
}else
{
if(wbr==0)
{
retur=1;
}else
{
retur=0;
}
}
return retur;
}
void ozpulkir(char pullar[24][15], int hamle, char sira, int* wbr, int* bbr)
{
if(sira=='B')
{
pullar[hamle-1][0]='B';
(*bbr)--;
(*wbr)++;
}else if(sira=='W')
{
pullar[24-hamle][0]='W';
(*wbr)--;
(*bbr)++;
}
}
void pulkir(char pullar[24][15], int n1, int hamle, char sira, int* wbr, int* bbr)
{
int kont1=0;
int kont2=14;
while(kont1==0)
{
if(pullar[n1][kont2]==sira)
{
pullar[n1][kont2]=' ';
kont1=1;
if(sira=='B')
{
pullar[n1+hamle][0]='B';
(*wbr)++;
}else if(sira=='W')
{
pullar[n1-hamle][0]='W';
(*bbr)++;
}
}
kont2--;
}
}
int zarkontrol(int zarlar[], int hamle)
{
int retu;
if(!((hamle==zarlar[0])||(hamle==zarlar[1])))
{
retu=0;
}else
{
retu=1;
}
return retu;
}
void siradegis(char *sira)
{
if((*sira)=='B')
{(*sira)='W';}
else if((*sira)=='W')
{(*sira)='B';}
}
int hamlekontrol(char pullar[24][15], int n1, int hamle, char sira, int bbr, int wbr, int wcl, int bcl)
{
int ret;
int x = kirikkont(sira, wbr, bbr);
if(x==0)
{
if(n1==-1)
{
if(sira=='W')
{
if(pullar[24-hamle][1]=='B')
{
ret=0; //there is more than one another piecees, movement is invalid
}else if((pullar[24-hamle][0]=='B')&&(pullar[24-hamle][1]==' '))
{
ret=20; //they can be broken
}else
{
ret=10;
}
}else if(sira=='B')
{
if(pullar[hamle-1][1]=='W')
{
ret=0; //there is more than one another piecees, movement is invalid
}else if((pullar[hamle-1][0]=='W')&&(pullar[hamle-1][1]==' '))
{
ret=20; // they can be broken
}else
{
ret=10;
}
}
}else
{
ret=0;
}
}else
{
if(!(pullar[n1][0]==sira))
{
ret=0;
}else
{
if(sira=='W')
{
if((n1-hamle)<0)
{
if(tkontrol(pullar, sira)==1)
{
if(tkontrol2(pullar, sira, n1, hamle)==1)
{
ret=4;
}else