-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrock_paper_scissors.R
More file actions
39 lines (37 loc) · 1003 Bytes
/
rock_paper_scissors.R
File metadata and controls
39 lines (37 loc) · 1003 Bytes
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
exit <-0
action <- c("Rock","Paper","Scissors")
num <- c(1,2,3)
#sample(action ,size = 1)
P_num <- readline(prompt="Select Action\n[1] Rock\n[2] Paper\n[3] Scissors\n")
ans <- readline(prompt="Want to exit?[Y/N]")
play <- function(){
exit <-0
action <- c("Rock","Paper","Scissors")
num <- c(1,2,3)
while (exit == 0)
{
P_num <- readline(prompt="Select Action\n[1] Rock\n[2] Paper\n[3] Scissors\n")
P_num
P_num <- as.integer(P_num)
bot_num <- sample(num ,size = 1)
print(paste("You :",action[P_num]))
if (P_num-1 == 0){
P_num <- 4
}
print(paste("Bot :",action[bot_num]))
if (P_num == bot_num){
print(paste("Draw"))
}else if (bot_num == P_num-1){
print("Win")
}
else{
print("Lose")
}
ans <- readline(prompt="Want to exit?[Y/N]\n")
ans
if (ans %in% c("Y","y")){
exit <- 1
}
}
}
play()