# 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,我们在else功能中遇到了样本问题,因为它没有为我们提供随意的卡片。
答案 0 :(得分:0)
您需要插入print语句才能实际输出:
repeat
{
response <- as.character(readinteger())
if(response=="no")
{
print("Game Over");
break
} else {
out = sample(deck,1,replace=TRUE)
print(out)
}
}
你走了:
Continuing?
[1] "Fill Up The Cup"
Continuing?
[1] "For Chicks"
Continuing?
[1] "Pick A Mate"
Continuing?
[1] "On The Floor"
Continuing?no
[1] "Game Over"
享受!