1
# rm(list=ls())
Ace <- c(rep("Waterfall", 4))
Two <- c(rep("For You",4))
Three <- c(rep("For Me",4))
Four <- c(rep("On The Floor",4))
Five <- c(rep("For Guys",4))
Six <- c(rep("For Chicks",4))
Seven <- c(rep("Heaven",4))
Eight <- c(rep("Pick A Mate",4))
Nine <- c(rep("Make A Rime",4))
Ten <- c("Cars","Bands","Books","Capital Cities")
Jack <- c(rep("Make A Rule",4))
Queen <- c(rep("You're The Quizmaster",4))
King <- c(rep("Fill Up The Cup",4))
deck <- c(Ace,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King)
shuffle <- function(deck) {return(sample(deck,length(deck)))}
readinteger <- function(){
n<- readline("Continuing?")
}
repeat
{
response <- as.character(readinteger())
if(response=="no")
{
print("Game Over");
break
} else {
sample(deck,1,replace=TRUE)
}
}
我們模擬紙牌遊戲kingscup一個隨機變量,我們必須適應在其他功能的樣品有問題,因爲它沒有給我們一個隨機卡,因爲我們希望。創建IF ... ELSE功能
我已經評論了危險的'rm'。 –
你想用'sample(deck,1,replace = TRUE)'來做什麼?(現在你不會把它保存在一個對象中)。如果你只想要一個隨機的話,爲什麼你要設置'replace = TRUE'? – jogo
我們認爲如果我們設置replace = True,那麼該變量將被替換。 我們如何得到一個隨機? –