Advertisement
60E1CluBSteP127

genshin impact wish simulator (DTMC)

Jun 3rd, 2022
1,844
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.74 KB | None | 0 0
  1. # Genshin Impact wish simulator
  2. # "Walking through wish space, 160 primos at a time"
  3.  
  4. # Based on a discrete-time Markov chain.
  5. # Essentially a dumbed-down version of gacha in Genshin.
  6. # TODO: actually make banners and add names
  7. # TODO: simulate losing and winning 50/50, useful for event banners.
  8.  
  9. init <- function() { # Reset the simulator.
  10.   x <<- 0 # 4* pity
  11.   y <<- 0 # 5* pity
  12.   vx <<- c() # vector for tallying 4* pity
  13.   vy <<- c() # vector for tallying 5* pity
  14.   vt <<- c() # vector for showing the tier of item obtained
  15. }
  16.  
  17. wishonce <- function() { # Use one wish.
  18.   iter() # iterate once; takes care of vt.
  19.   vx <<- append(vx,x) # add new x
  20.   vy <<- append(vy,y) # and new y
  21. }
  22.  
  23. wish <- function(w) { # Use w wishes.
  24.   for (i in 1:w) {
  25.     wishonce() # this takes care of vx and vy as well
  26.   }
  27. }
  28.  
  29.  
  30. iter <- function() { # Iterate once.
  31.   r <- runif(1,0,1) # Draw a random number, uniformly dist. on [0,1]
  32.   if(x < 9 && y < 89) {
  33.      if(r <= .943) { # getting a 3*
  34.        x <<- x + 1
  35.        y <<- y + 1
  36.        vt <<- append(vt,3)
  37.      } else if(r <= .994) { # getting a 4*
  38.        x <<- 0
  39.        y <<- y + 1
  40.        vt <<- append(vt,4)
  41.      } else { # getting a 5*
  42.        x <<- x + 1
  43.        y <<- 0
  44.        vt <<- append(vt,5)
  45.      }
  46.   } else if(x >= 9 && y < 89) {
  47.     if(r <= .994) { # getting 4* by hard pity
  48.       x <<- 0
  49.       y <<- y + 1
  50.       vt <<- append(vt,4)
  51.     } else { # getting a 5*
  52.       x <<- x + 1
  53.       y <<- 0
  54.       vt <<- append(vt,5)
  55.     }
  56.   } else if(y == 89) { # getting a 5* by hard pity
  57.     x <<- x + 1
  58.     y <<- 0
  59.     vt <<- append(vt,5)
  60.   } else { # do nothing... this shouldn't happen.
  61.     print("Something is off!")
  62.     vt <<- append(vt,0)
  63.   }
  64. }
  65.  
  66. init() # and make sure to init the sim!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement