/*
Name : Shreyashka Mhanedra Patel
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int generateRandomNumber(int n)
{
srand(time(NULL));
return rand() % n ;
}
int greater(char c1, char c2)
{
if(c1 == c2){
return -1;
}
else if((c1 == 'r') && (c2 == 's')){
return 1;
}
else if((c2 == 'r') && (c1 == 's')){
return 0;
}
else if((c1 == 'p') && (c2 == 'r')){
return 1;
}
else if((c2 == 'p') && (c1 == 'r')){
return 0;
}
if((c1 == 's') && (c2 == 'p')){
return 1;
}
else if ((c2 == 's') && (c1 == 'p')){
return 0;
}
}
int main()
{
int p1Score = 0,comScore=0;
char pChar,comChar;
int temp;
char dict[]={'r','p','s'};
printf("*******************************Welcome to Rock Paper scissor game**************************************\n");
for(int i=0; i<3; i++){
//players turn
printf("Player 1 turn : \n");
printf("Choose\n1.For Rock\n2.For Paper\n3.For Scissor\n");
scanf("%d",&temp);
getchar();
pChar = dict[temp-1];
printf("You chose : %c\n\n",pChar);
//Computers turn
printf("Computer's turn : \n\n");
printf("Choose\n1.For Rock\n2.For Paper\n3.For Scissor\n");
temp = generateRandomNumber(3)+1;
comChar = dict[temp-1];
printf("Computer chose : %c\n",comChar);
//Score section
if(greater(comChar,pChar) == 1){
comScore +=1;
printf("Computer Got the point.\n\n");
}
else if(greater(comChar,pChar) == -1){
comScore +=1;
p1Score +=1;
printf("Tie Between You Both \n\n");
}
else{
p1Score +=1;
printf("You Got the point.\n\n");
}
printf("Your Score : %d Computer Score : %d\n\n",p1Score,comScore);
}
printf("\n\n\n\n***********************************Final results**********************************************\n");
if(p1Score > comScore){
printf("Your Score : %d\t\tComputer Score : %d\n",p1Score,comScore);
printf("Hurray ! You win.............");
}
else if (p1Score < comScore){
printf("Your Score : %d\t\tComputer Score : %d\n",p1Score,comScore);
printf("Computer Wins. Better luck next Time............");
}
else{
printf("Your Score : %d \t\tComputer Score : %d\n",p1Score,comScore);
printf("Tie Between You Both. Better luck next Time.......... ");
}
return 0;
}