-
Notifications
You must be signed in to change notification settings - Fork 2
2021-01 submission: Paula Spinola #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
codequest 2021-01: Rock-Paper-Scissors Contents - ./game.R: main code program
stefpiatek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, some tiding up and streamlining
| # This script codes the interactive game Rock-Paper-Scissors between a user and the computer | ||
| # Author: Paula Spinola | ||
| # Date: 20th Jan 2021 | ||
| rm(list=ls()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine for your own usage but probably don't remove everything in my R environment or I'll cry
| # installing packages | ||
| #install.packages("azuremlsdk") | ||
| library(azuremlsdk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # installing packages | |
| #install.packages("azuremlsdk") | |
| library(azuremlsdk) |
| if(p1== "Rock") { | ||
| if(p2 == "Scissors") { | ||
| p1_output <- "Rock crushes scissors. You won :)" | ||
| } | ||
| if(p2 == "Paper") { | ||
| p1_output <- "Paper covers rock. You lost :(" | ||
| } | ||
| else{ | ||
| p1_output <- "Tie. No one wins :|" | ||
| } | ||
| } | ||
| if(p1== "Paper") { | ||
| if(p2 == "Rock") { | ||
| p1_output <- "Paper covers rock. You won :)" | ||
| } | ||
| if(p2 == "Scissors") { | ||
| p1_output <- "Scissors cut paper. You lost :(" | ||
| } | ||
| else{ | ||
| p1_output <- "Tie. No one wins :|" | ||
| } | ||
| } | ||
| if(p1== "Scissors") { | ||
| if(p2 == "Paper") { | ||
| p1_output <- "Scissors cut paper. You won :)" | ||
| } | ||
| if(p2 == "Rock") { | ||
| p1_output <- "Rock crushes scissors. You lost :(" | ||
| } | ||
| else{ | ||
| p1_output <- "Tie. No one wins :|" | ||
| } | ||
| } | ||
| return(p1_output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be done by dataframe lookup (row player 1, column for player 2 and outcome string in the cell)
|
|
||
|
|
||
| # generate computer play option | ||
| computer_play <- options[sample(1:3, 1)] # did not manage to use randint() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| computer_play <- options[sample(1:3, 1)] # did not manage to use randint() | |
| computer_play <- options[sample(1:3, 1)] |
| options <- c("Rock","Paper","Scissors") | ||
|
|
||
| # function that gets user input | ||
| user_question <- function() { | ||
| user_play <- readline(prompt="Enter play option: ") | ||
| while(!user_play %in% options){ | ||
| user_play <-readline(prompt = "Please choose between Rock, Paper and Scissors: ") | ||
| } | ||
| return(user_play) | ||
| } | ||
|
|
||
| # function that simulates the game | ||
| game_simulation <- function(p1,p2) { | ||
| if(p1== "Rock") { | ||
| if(p2 == "Scissors") { | ||
| p1_output <- "Rock crushes scissors. You won :)" | ||
| } | ||
| if(p2 == "Paper") { | ||
| p1_output <- "Paper covers rock. You lost :(" | ||
| } | ||
| else{ | ||
| p1_output <- "Tie. No one wins :|" | ||
| } | ||
| } | ||
| if(p1== "Paper") { | ||
| if(p2 == "Rock") { | ||
| p1_output <- "Paper covers rock. You won :)" | ||
| } | ||
| if(p2 == "Scissors") { | ||
| p1_output <- "Scissors cut paper. You lost :(" | ||
| } | ||
| else{ | ||
| p1_output <- "Tie. No one wins :|" | ||
| } | ||
| } | ||
| if(p1== "Scissors") { | ||
| if(p2 == "Paper") { | ||
| p1_output <- "Scissors cut paper. You won :)" | ||
| } | ||
| if(p2 == "Rock") { | ||
| p1_output <- "Rock crushes scissors. You lost :(" | ||
| } | ||
| else{ | ||
| p1_output <- "Tie. No one wins :|" | ||
| } | ||
| } | ||
| return(p1_output) | ||
| } | ||
|
|
||
|
|
||
| # generate computer play option | ||
| computer_play <- options[sample(1:3, 1)] # did not manage to use randint() | ||
|
|
||
| # ask user play option | ||
| user_play <- user_question() # why R sometimes transforms first character as lower case? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could have the options as all lower case and then transform the input to lower case text here.
| } | ||
| if(p2 == "Rock") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| if(p2 == "Rock") { | |
| } else if(p2 == "Rock") { |
codequest 2021-01: Rock-Paper-Scissors
Contents