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: simulate losing and winning 50/50, useful for event banners.
- init.items <- function() {
- v3 <<- c("Raven Bow", "Sharpshooter's Oath", "Slingshot", "Emerald Orb",
- "Magic Guide", "Thrilling Tales of Dragon Slayers",
- "Bloodtainted Greatsword", "Debate Club", "Ferrous Shadow",
- "Black Tassel", "Cool Steel", "Harbinger of Dawn", "Skyrider Sword")
- v4 <<- c("Favonius Warbow", "Rust", "Sacrificial Bow", "The Stringless",
- "Eye of Perception", "Favonius Codex", "Sacrificial Fragments",
- "The Widsith", "Favonius Greatsword", "Rainslasher",
- "Sacrificial Greatsword", "The Bell", "Dragon's Bane",
- "Favonius Lance", "Favonius Sword", "Lion's Roar",
- "Sacrificial Sword", "The Flute", "Sayu", "Sucrose", "Chongyun",
- "Diona", "Kaeya", "Rosaria", "Beidou", "Fischl", "Kujou Sara", "Lisa",
- "Razor", "Gorou", "Ningguang", "Noelle", "Yun Jin", "Barbara", "Xingqiu",
- "Amber", "Bennett", "Thoma", "Xiangling", "Xinyan", "Yanfei")
- v5 <<- c("Jean", "Qiqi", "Keqing", "Mona", "Diluc", "Amos' Bow", "Skyward Harp",
- "Lost Prayer to the Sacred Winds", "Skyward Atlas", "Skyward Pride",
- "Wolf's Gravestone", "Primordial Jade-Winged Spear", "Skyward Spine",
- "Aquila Favonia", "Skyward Blade")
- }
- init.chain <- 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
- vitems <<- c() # vector that stores items obtained
- }
- 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*
- t <- 3
- } else if(r <= .994) { # getting a 4*
- t <- 4
- } else { # getting a 5*
- t <- 5
- }
- } else if(x >= 9 && y < 89) {
- if(r <= .994) { # getting 4* by hard pity
- t <- 4
- } else { # getting a 5*
- t <- 5
- }
- } else if(y == 89) { # getting a 5* by hard pity
- t <- 5
- } else { # do nothing... this shouldn't happen.
- print("Something is off!")
- t <- 0
- }
- if(t == 3) { # if you got 3*
- x <<- x + 1
- y <<- y + 1
- } else if(t == 4) { # 4*
- x <<- 0
- y <<- y + 1
- } else if(t == 5) { # 5*
- x <<- x + 1
- y <<- 0
- } else { # this shouldn't happen
- }
- vx <<- append(vx,x) # add new x
- vy <<- append(vy,y) # and new y
- vt <<- append(vt,t)
- vitems <<- append(vitems,banner.standard.item(t))
- }
- wishonce <- function() { # Use one wish.
- iter() # iterate once
- }
- wish <- function(w) { # Use w wishes.
- for (i in 1:w) {
- wishonce() # this takes care of vx and vy as well
- }
- }
- # Convert one item t into a standard banner item.
- banner.standard.item <- function(t) {
- if(t == 3) {
- sample(v3,1)
- } else if(t == 4) {
- sample(v4,1)
- } else if(t == 5) {
- sample(v5,1)
- } else {
- "weird"
- }
- }
- # Convert your vector of items vt into standard banner items.
- # Not useful anymore.
- banner.standard.vector <- function(vt) {
- lapply(vt,banner.standard.item)
- }
- init.items()
- init.chain() # and make sure to init the sim!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement