试图调用我的函数n次

时间:2017-11-18 16:51:22

标签: r

我的目标是调用我的骰子滚动功能n次,其中n是转弯量。这是一个垄断模拟转弯,因此双打将再次滚动,三倍将进入监狱。我无法弄清楚如何设置它,所以我的功能将是

Diceroll <- Function ( Turns, Sides) 

Diceroll <- function(Turn,sides){


      Turn = as.integer(0)
      First_roll = as.integer(0)
      Second_roll = as.integer(0)
      Third_roll = as.integer(0)
      Fourth_roll = as.integer(0)
      Fifth_roll = as.integer(0)
      Sixth_roll = as.integer(0)
      Total = as.integer(0)
      i = as.integer(1)

      for (i in 1:Turn) { 


      First_roll = sample(1:sides,size = 1)
      Second_roll = sample(1:sides,size = 1)

      if(First_roll[1] == Second_roll[1]) {
        Third_roll = sample(1:sides,size = 1)
        Fourth_roll = sample(1:sides,size = 1)

      } 

      if(Third_roll[1] == Fourth_roll[1] & Third_roll[1] + Fourth_roll[1] > 0) {
        Fifth_roll= sample(1:sides,size = 1)
        Sixth_roll = sample(1:sides,size = 1)

      }

      if(Fifth_roll[1] == Sixth_roll[1] & Fifth_roll[1] + Sixth_roll[1] > 0)   { Total = "Jail"

      }

      else {

            Total = (First_roll[1] + Second_roll[1] + Third_roll[1] + 
                       Fourth_roll[1] + Fifth_roll[1] + Sixth_roll[1]) }




       return(Total)

      }

      }

这是我的尝试,但它只列出了一卷的价值。

0 个答案:

没有答案