2021-01 submission: Paula Spinola#5
Open
PaulaSpinola wants to merge 1 commit intoIHI-Code-Club:mainfrom
Open
Conversation
codequest 2021-01: Rock-Paper-Scissors Contents - ./game.R: main code program
stefpiatek
approved these changes
Feb 24, 2021
stefpiatek
left a comment
There was a problem hiding this comment.
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.
Fine for your own usage but probably don't remove everything in my R environment or I'll cry
Comment on lines
+6
to
+8
| # installing packages | ||
| #install.packages("azuremlsdk") | ||
| library(azuremlsdk) |
There was a problem hiding this comment.
Suggested change
| # installing packages | |
| #install.packages("azuremlsdk") | |
| library(azuremlsdk) |
Comment on lines
+24
to
+57
| 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.
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.
Suggested change
| computer_play <- options[sample(1:3, 1)] # did not manage to use randint() | |
| computer_play <- options[sample(1:3, 1)] |
Comment on lines
+11
to
+65
| 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.
could have the options as all lower case and then transform the input to lower case text here.
Comment on lines
+49
to
+50
| } | ||
| if(p2 == "Rock") { |
There was a problem hiding this comment.
Suggested change
| } | |
| if(p2 == "Rock") { | |
| } else if(p2 == "Rock") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
codequest 2021-01: Rock-Paper-Scissors
Contents