Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Genshin Impact wish simulator
- # "Walking through wish space, 160 primos at a time"
- # Based on a discrete-time Markov chain.
- # Essentially a dumbed-down version of gacha in Genshin.
- # TODO: actually make banners and add names
- # TODO: simulate losing and winning 50/50, useful for event banners.
- init <- function() { # Reset the simulator.
- x <<- 0 # 4* pity
- y <<- 0 # 5* pity
- vx <<- c() # vector for tallying 4* pity
- vy <<- c() # vector for tallying 5* pity
- vt <<- c() # vector for showing the tier of item obtained
- }
- wishonce <- function() { # Use one wish.
- iter() # iterate once; takes care of vt.
- vx <<- append(vx,x) # add new x
- vy <<- append(vy,y) # and new y
- }
- wish <- function(w) { # Use w wishes.
- for (i in 1:w) {
- wishonce() # this takes care of vx and vy as well
- }
- }
- iter <- function() { # Iterate once.
- r <- runif(1,0,1) # Draw a random number, uniformly dist. on [0,1]
- if(x < 9 && y < 89) {
- if(r <= .943) { # getting a 3*
- x <<- x + 1
- y <<- y + 1
- vt <<- append(vt,3)
- } else if(r <= .994) { # getting a 4*
- x <<- 0
- y <<- y + 1
- vt <<- append(vt,4)
- } else { # getting a 5*
- x <<- x + 1
- y <<- 0
- vt <<- append(vt,5)
- }
- } else if(x >= 9 && y < 89) {
- if(r <= .994) { # getting 4* by hard pity
- x <<- 0
- y <<- y + 1
- vt <<- append(vt,4)
- } else { # getting a 5*
- x <<- x + 1
- y <<- 0
- vt <<- append(vt,5)
- }
- } else if(y == 89) { # getting a 5* by hard pity
- x <<- x + 1
- y <<- 0
- vt <<- append(vt,5)
- } else { # do nothing... this shouldn't happen.
- print("Something is off!")
- vt <<- append(vt,0)
- }
- }
- init() # and make sure to init the sim!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement