-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
143 lines (127 loc) · 2.41 KB
/
Source.cpp
File metadata and controls
143 lines (127 loc) · 2.41 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
#include<stdio.h>
int main()
{
int a[21];
int i, j = 0;
int p1, p2, t;
for (i=0;i<21; i++)
{
a[i] = 21-i;
}
printf("\n\n\n\t\t\t\t21 FLAGS\n\n\t\t\t\tInstructions.\nThere are 21 flags. Each player can take 1,2 or 3 flags in each turn.The player to take the last flag wins.\n\n\t\t\t|");
for (i = 0; i<21; i++)
{
if (a[i] == 0)
{
printf("*|");
}
else
printf("%d|", a[i]);
}
printf("\n\n\t\tYou have to play this game against the computer. Are you smarter than a Machine?\n\t\tPress 1 if you want to start or press 2 if you want the computer to start.\n");
scanf_s("%d", &t);
if (t == 2)
{
while (1)
{
if ((21 - j) <= 3)
{
printf("\n\n\t\t\t\tCOMPUTER WINS.");
break;
}
p1 = (21 - j) % 4;
for (i = 0; i<p1; i++)
a[j++] = 0;
printf("\nComp took %d flags.\n\n\t\t\t\t |", p1);
for (i = 0; i<21; i++)
{
if (a[i] == 0)
{
printf("*|");
}
else
printf("%d|", a[i]);
}
if ((21 - j) <= 3)
{
printf("\n\n\n\t\t\t\tYOU WIN.");
break;
}
printf("\n\nEnter your choice:");
while (1)
{
scanf_s("%d", &p2);
if (p2 == 1 || p2 == 2 || p2 == 3)
break;
printf("\nInvalid choice. Enter again:");
}
for (i = 0; i<p2; i++)
{
a[j++] = 0;
}
printf("\n\t\t\t\t");
for (i = 0; i<21; i++)
{
if (a[i] == 0)
{
printf("*|");
}
else
printf("%d|", a[i]);
}
printf("\n\nComputer's turn");
}
}
else if (t == 1)
{
while (1)
{
if ((21 - j) <= 3)
{
printf("\n\n\t\t\t\tYOU WIN.");
break;
}
printf("\nEnter your choice:");
scanf_s("%d", &p2);
for (i = 0; i<p2; i++)
{
a[j++] = 0;
}
printf("\n\t\t\t |");
for (i = 0; i<21; i++)
{
if (a[i] == 0)
{
printf("*|");
}
else
printf("%d|", a[i]);
}
//printf("\n\nComputers turn:press n key");
if ((21 - j) <= 3)
{
printf("\n\n\t\t\t\tCOMPUTER WINS.");
break;
}
if (((21 - j) % 4) == 0)
p1 = 1;
else
p1 = (21 - j) % 4;
for (i = 0; i<p1; i++)
a[j++] = 0;
printf("\n\n Computer took %d flags.\n", p1);
printf("\n\n\t\t\t |");
for (i = 0; i<21; i++)
{
if (a[i] == 0)
{
printf("*|");
}
else
printf("%d|", a[i]);
}
}
}
getchar();
getchar();
}