-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStonePaperScissor.c
142 lines (139 loc) · 4.84 KB
/
StonePaperScissor.c
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
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
//Harsh Shrivastava
int main()
{
int hihi;
int score[3];
int choice;
int re;
printf("\"Welcome To Stone Paper Scissor Game\"\n");
printf("RULES-1)Match will going to be a best of three\n 2)Enter choice as option\n 3)result will be displayed at end\n");
printf(" 4)won,tie,loose give you score 1,0,-1\n");
rematch:
for (int i = 0; i < 3; i++)
{
printf("\n");
printf("----------------------\n");
printf("Match number %d starts\n", i + 1);
restat:
fflush(stdin);
printf("choose one out of A)stone B)paper C)scissor\n");
printf("Enter your choice as a,b,c- ");
scanf("%d", &choice);
// for human choice
switch (choice)
{
case 1: // human choice stone
// Generating random number between 0 to 17 increasing range to increase different output probabilities
srand(time(NULL));
hihi = rand() % 17;
// printf("%d\n", hihi);
printf("\n");
if (hihi == 2 || hihi == 7 || hihi == 5 || hihi == 11 || hihi == 15 || hihi == 16)
{
printf("Computer chooses \"stone\"\n");
printf("you also chooses stone\n");
printf("Round TIE\n");
score[i] = 0;
}
else if (hihi == 3 || hihi == 8 || hihi == 6 || hihi == 12 || hihi == 13 || hihi == 17)
{
printf("Computer chooses \"paper\"\n");
printf("OOPS! you chooses stone\n");
printf("You LOOSE this round\n");
score[i] = -1;
}
else
{
printf("Computer chooses \"scissor\"\n");
printf("you choose stone congrats\n");
printf("You WON this round\n");
score[i] = 1;
}
break;
case 2: // human choice paper
// Generating random number between 0 to 17 increasing range to increase different output probabilities
srand(time(NULL));
hihi = rand() % 17;
//printf("%d\n", hihi);
printf("\n");
if (hihi == 2 || hihi == 7 || hihi == 5 || hihi == 11 || hihi == 15 || hihi == 16)
{
printf("Computer chooses \"stone\"\n");
printf("you made great choice\n");
printf("You WON this round\n");
score[i] = 1;
}
else if (hihi == 3 || hihi == 8 || hihi == 6 || hihi == 12 || hihi == 13 || hihi == 17)
{
printf("Computer chooses \"paper\"\n");
printf("clever choice\n");
printf("round TIE\n");
score[i] = 0;
}
else
{
printf("Computer chooses \"scissor\"\n");
printf("You loose this round\n");
printf("better luck next round\n");
score[i] = -1;
}
break;
case 3: // human choice scissor
// Generating random number between 0 to 17 increasing range to increase different output probabilities
srand(time(NULL));
hihi = rand() % 17;
//printf("%d\n", hihi);
printf("\n");
if (hihi == 2 || hihi == 7 || hihi == 5 || hihi == 11 || hihi == 15 || hihi == 16)
{
printf("Computer chooses \"stone\"\n");
printf("Good trying but,\n");
printf("You loose this round\n");
score[i] = -1;
}
else if (hihi == 3 || hihi == 8 || hihi == 6 || hihi == 12 || hihi == 13 || hihi == 17)
{
printf("Computer chooses \"paper\"\n");
printf("You won this round\n");
printf("Wow great round\n");
score[i] = 1;
}
else
{
printf("Computer chooses scissor\n");
printf("Match tie in this round\n");
printf("well done\n");
score[i] = 0;
}
break;
default:
printf("choose correct option\n");
goto restat;
break;
}
}
printf("\n");
printf("Match over your final score is %d out of 3\n", score[0] + score[1] + score[2]);
printf("wanna have a rematch\n");
correct:
printf("1)yes 0)no\n");
scanf("%d", &re);
if (re == 1)
{
goto rematch;
}
else if (re == 0)
{
exit(1);
}
else
{
printf("Choose correct option\n");
goto correct;
}
return 0;
}