-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rock_Paper_Scissors_game1.c
97 lines (96 loc) · 2.51 KB
/
Rock_Paper_Scissors_game1.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int genramdom(int n)
{
srand(time(NULL));
return rand() %n;
}
int mandy(char cmove,char pmove)
{
//returns 1 if c1>c2
//returns 0 if c1<c2
//returns -1 if c1=c2
if(cmove==pmove)
{
return -1;
}
if (cmove == 'r' && pmove == 's')
{
return 1;
}
else
{
return 0;
}
if (cmove == 'p' && pmove == 'r')
{
return 1;
}
else
{
return 0;
}
if (cmove == 's' && pmove=='p' )
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int move;
char dict[3]={'r','p','s'};
char cmove,pmove,name[10];
int cscore=0,pscore=0;
printf("hello player please enter your name (within 1-9)words:\n");
scanf("%s",name);
printf("Hello %s, \nWELCOME TO ROCK PAER SCISSORS GAME\n",name);
for(int i=0;i<3;i++)
{
//player 's move
printf("CHOSE\n1 FOR ROCK\n2 FOR PAPER\n3 FOR SCISSORS\n");
printf("%s 's turn:",name);
scanf("%d",&move);
pmove=dict[move-1];
printf("%s chose :%c\n",name,pmove);
// computer's move
printf("computer's turn:\n");
move=genramdom(3);
cmove=dict[move];
printf("computer chose :%c\n",cmove);
if(mandy(cmove,pmove)==1)
{
printf("computer got this round\n");
cscore++;
}
else if(mandy(cmove,pmove)==-1)
{
printf("Its a draw round\nboth gets 1 point\n");
cscore++;
pscore++;
}
else
{
printf("%s got this round\n",name);
pscore++;
}
}
printf("computer 's score is: %d\n",cscore);
printf("%s 's score is :%d\n",name,pscore);
if(cscore>pscore)
{
printf("computer win the match\nbetter luck next time player");
}
else if(cscore<pscore)
{
printf("player win the match\n");
}
else
{
printf("Its a draw\n");
}
}