1. Whenever a player gets a fresh turn, for the first roll (7 , 11) wins and (2,3,12) loses. However (4,5,6,8,9,10) gets another chance.
2. From second roll onwards in any turn, only (11 )wins and (2,3,7,12) loses. Again (4,5,6,8,9,10) gets another chance.
#include < stdio.h >
#include < conio.h >
#include < math.h >
#include < stdlib.h >
void main()
{
int flaga,flagb,chancea=1,chanceb=1,wa=0,wb=0,sum,r1,r2,i;
char c;
clrscr();
randomize();
flaga=rand()%2;
flagb=1-flaga;
printf("Throw No Player Dice-1 Dice-2 Total Point(A) Point(B)\n\n");
for(i=1;i<=100;i++)
{
r1=(rand()%6)+1;
r2=(rand()%6)+1;
sum=r1+r2;
if(flaga==1)
{
if(chancea==1)
{
if((sum==7)||(sum==11))
{
wa++;
chancea++;
c='A';
goto L;
}
if((sum==2)||(sum==3)||(sum==12))
{
flaga=0;
flagb=1;
c='A';
goto L;
}
}
if((chancea>1) && (sum==7))
{
flaga=0;
flagb=1;
chancea=1;
c='A';
goto L;
}
if((chancea>1) && (sum==11))
{
wa++;
chancea++;
c='A';
goto L;
}
if( (sum==2)||(sum==3)||(sum==12))
{
flaga=0;
flagb=1;
chancea=1;
c='A';
goto L;
}
if((sum==4)||(sum==5)||(sum==6)||(sum==8)||(sum==9)||(sum==10))
{
chancea++;
c='A';
goto L;
}
}
if(flagb==1)
{
if(chanceb==1)
{
if((sum==7)||(sum==11))
{
wb++;
chanceb++;
c='B';
goto L;
}
if ((sum==2) || (sum==3) ||(sum==12))
{
flagb=0;
flaga=1;
c='B';
goto L;
}
}
if((chanceb>1) && (sum==7))
{
flagb=0;
flaga=1;
chanceb=1;
c='B';
goto L;
}
if((chanceb>1) && (sum==11))
{
wb++;
chanceb++;
c='B';
goto L;
}
if((sum==2)||(sum==3)||(sum==12))
{
flagb=0;
flaga=1;
chanceb=1;
c='B';
goto L;
}
if((sum==4)||(sum==5)||(sum==6)||(sum==8)||(sum==9)||(sum==10))
{
chanceb++;
c='B';
goto L;
}
}
L:printf("%4d%10c%7d%8d%8d%8d%8d\n\n",i,c,r1,r2,sum,wa,wb);
}
printf(" The number of points won by A and B are %3d and%3d",wa,wb);
getch();
}
OUTPUT
Throw No
Player Dice-1 Dice-2
Total Point(A) Point(B)
1 A
2 2 4
0 0
2 A
6 4 10
0 0
3 A
4 4 8
0 0
4 A
2 5
7 0 0
5 B
1 2 3
0 0
6 A
1 5 6
0 0
7 A
6 2 8
0 0
8 A
3 3 6
0 0
9 A
3 5 8
0 0
10 A
6 5 11
1 0
11 A
6 2 8
1 0
12 A
2 4 6
1 0
13 A
1 4 5
1 0
14 A
4 5 9
1 0
15 A
1 1 2
1 0
16 B
4 1 5
1 0
17 B
4 2 6
1 0
18 B
4 1 5
1 0
19 B
6 6 12
1 0
20 A
3 3 6
1 0
21 A
6 5 11
2 0
22 A
5 2 7
2 0
23 B
3 6 9
2 0
24 B
4 3 7
2 0
25 A
1 2 3
2 0
26 B
5 4 9
2 0
27 B
1 4 5
2 0
28 B
3 5 8
2 0
29 B
6 1 7
2 0
30 A
6 5 11
3 0
31 A
3 5 8
3 0
32 A
1 3 4
3 0
33 A
1 3 4
3 0
34 A
6 4 10
3 0
35 A
1 1 2
3 0
36 B
1 1 2
3 0
37 A
3 4 7
4 0
38 A
1 6 7
4 0
39 B
5 6 11
4 1
40 B
5 3
8 4 1
41 B
2 3 5
4 1
42 B
5 2 7
4 1
43 A
5 4 9
4 1
44 A
4 5 9
4 1
45 A
5 4 9
4 1
46 A
4 4 8
4 1
47 A
3 4 7
4 1
48 B
6 4 10
4 1
49 B
3 1
4 4 1
50 B
1 5 6
4 1
51 B
5 2 7
4 1
52 A
3 4 7
5 1
53 A
5 3 8
5 1
54 A
6 5 11
6 1
55 A
5 3 8
6 1
56 A
1 4 5
6 1
57 A
1 3 4
6 1
58 A
5 3
8 6 1
59 A
6 5 11
7 1
60 A
6 1 7
7 1
61 B
2 2 4
7 1
62 B
3 4 7
7 1
63 A
6 1 7
8 1
64 A
4 1 5
8 1
65 A
1 2 3
8 1
66 B
2 2 4
8 1
67 B
3 6
9 8 1
68 B
2 4 6
8 1
69 B
4 5 9
8 1
70 B
1 4 5
8 1
71 B
2 2 4
8 1
72 B
5 4 9
8 1
73 B
2 1 3
8 1
74 A
2 1 3
8 1
75 B
6 6 12
8 1
76 A 4
5 9 8
1
77 A
6 6 12
8 1
78 B
3 2 5
8 1
79 B
6 3 9
8 1
80 B
5 2 7
8 1
81 A
1 1 2
8 1
82 B
4 3 7
8 2
83 B
2 5 7
8 2
84 A
1 3 4
8 2
85 A
5 1 6
8 2
86 A
3 5 8
8 2
87 A
4 5 9
8 2
88 A
1 1 2
8 2
89 B
2 1 3
8 2
90 A
3 4 7
9 2
91 A
3 2 5
9 2
92 A
2 3 5
9 2
93 A
3 6 9
9 2
94 A
5 2 7
9 2
95 B
5 5 10
9 2
96 B
2 5 7
9 2
97 A
1 1 2
9 2
98 B
3 2 5
9 2
99 B
4 5 9
9 2
100 B
3 1 4
9 2
The number of
points won by A and B are 9 and 2
No comments:
Post a Comment