forked from SR-Sunny-Raj/Hacktoberfest2021-DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock_paper_scissor.c
79 lines (47 loc) · 1.27 KB
/
Rock_paper_scissor.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
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int Game(char user_input, char AI_response)
{
if (user_input== AI_response)
return -1;
if (user_input== 's' && AI_response == 'p')
return 0;
else if (user_input== 'p' && AI_response == 's') return 1;
if (user_input== 's' && AI_response == 'z')
return 1;
else if (user_input== 'z' && AI_response == 's')
return 0;
if (user_input== 'p' && AI_response == 'z')
return 0;
else if (user_input== 'z' && AI_response == 'p')
return 1;
}
int main()
{
int n;
char you, AI_response, result;
srand(time(NULL));
n = rand() % 100;
if (n < 33)
AI_response = 's';
else if (n > 33 && n < 66)
AI_response = 'p';
else
AI_response = 'z';
printf("\n\n\n\n\t\t\t\tEnter 's' for STONE, 'p' for PAPER and 'z' for SCISSOR\n\t\t\t\t\t\t\t");
scanf("%c", &you);
result = Game(you, AI_response);
if (result == -1) {
printf("\n\n\t\t\t\tGame Draw!\n");
}
else if (result == 1) {
printf("\n\n\t\t\t\tWow! You have won the game!\n");
}
else {
printf("\n\n\t\t\t\tOh! You have lost the game!\n");
}
printf("\t\t\t\tYou choose : '%c' and Computer choose : '%c'\n", you, AI_response);
return 0;
}