-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||
| # 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()) | ||||||||
|
|
||||||||
| # installing packages | ||||||||
| #install.packages("azuremlsdk") | ||||||||
| library(azuremlsdk) | ||||||||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| # option to choose from | ||||||||
| 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") { | ||||||||
|
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| p1_output <- "Rock crushes scissors. You lost :(" | ||||||||
| } | ||||||||
| else{ | ||||||||
| p1_output <- "Tie. No one wins :|" | ||||||||
| } | ||||||||
| } | ||||||||
| return(p1_output) | ||||||||
|
Comment on lines
+24
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| # ask user play option | ||||||||
| user_play <- user_question() # why R sometimes transforms first character as lower case? | ||||||||
|
Comment on lines
+11
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||
|
|
||||||||
| # running game | ||||||||
| game_decision <- game_simulation(p1=user_play,p2=computer_play) | ||||||||
| print(game_decision) # there is an issue with the code, sometimes it is outputing Tie when it should not | ||||||||
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