Advertisement
60E1CluBSteP127

genshin impact wish simulator (DTMC) v2

Jun 5th, 2022
2,773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.42 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: simulate losing and winning 50/50, useful for event banners.
  7.  
  8. init.items <- function() {
  9.   v3 <<- c("Raven Bow", "Sharpshooter's Oath", "Slingshot", "Emerald Orb",
  10.            "Magic Guide", "Thrilling Tales of Dragon Slayers",
  11.            "Bloodtainted Greatsword", "Debate Club", "Ferrous Shadow",
  12.            "Black Tassel", "Cool Steel", "Harbinger of Dawn", "Skyrider Sword")
  13.   v4 <<- c("Favonius Warbow", "Rust", "Sacrificial Bow", "The Stringless",
  14.            "Eye of Perception", "Favonius Codex", "Sacrificial Fragments",
  15.            "The Widsith", "Favonius Greatsword", "Rainslasher",
  16.            "Sacrificial Greatsword", "The Bell", "Dragon's Bane",
  17.            "Favonius Lance", "Favonius Sword", "Lion's Roar",
  18.            "Sacrificial Sword", "The Flute", "Sayu", "Sucrose", "Chongyun",
  19.            "Diona", "Kaeya", "Rosaria", "Beidou", "Fischl", "Kujou Sara", "Lisa",
  20.            "Razor", "Gorou", "Ningguang", "Noelle", "Yun Jin", "Barbara", "Xingqiu",
  21.            "Amber", "Bennett", "Thoma", "Xiangling", "Xinyan", "Yanfei")
  22.   v5 <<- c("Jean", "Qiqi", "Keqing", "Mona", "Diluc", "Amos' Bow", "Skyward Harp",
  23.            "Lost Prayer to the Sacred Winds", "Skyward Atlas", "Skyward Pride",
  24.            "Wolf's Gravestone", "Primordial Jade-Winged Spear", "Skyward Spine",
  25.            "Aquila Favonia", "Skyward Blade")
  26. }
  27.  
  28. init.chain <- function() { # Reset the simulator.
  29.   x <<- 0 # 4* pity
  30.   y <<- 0 # 5* pity
  31.   vx <<- c() # vector for tallying 4* pity
  32.   vy <<- c() # vector for tallying 5* pity
  33.   vt <<- c() # vector for showing the tier of item obtained
  34.   vitems <<- c() # vector that stores items obtained
  35. }
  36.  
  37. iter <- function() { # Iterate once.
  38.   r <- runif(1,0,1) # Draw a random number, uniformly dist. on [0,1]
  39.   if(x < 9 && y < 89) {
  40.      if(r <= .943) { # getting a 3*
  41.        t <- 3
  42.      } else if(r <= .994) { # getting a 4*
  43.        t <- 4
  44.      } else { # getting a 5*
  45.        t <- 5
  46.      }
  47.   } else if(x >= 9 && y < 89) {
  48.     if(r <= .994) { # getting 4* by hard pity
  49.       t <- 4
  50.     } else { # getting a 5*
  51.       t <- 5
  52.     }
  53.   } else if(y == 89) { # getting a 5* by hard pity
  54.     t <- 5
  55.   } else { # do nothing... this shouldn't happen.
  56.     print("Something is off!")
  57.     t <- 0
  58.   }
  59.  
  60.   if(t == 3) { # if you got 3*
  61.     x <<- x + 1
  62.     y <<- y + 1
  63.   } else if(t == 4) { # 4*
  64.     x <<- 0
  65.     y <<- y + 1
  66.   } else if(t == 5) { # 5*
  67.     x <<- x + 1
  68.     y <<- 0
  69.   } else { # this shouldn't happen
  70.    
  71.   }
  72.  
  73.   vx <<- append(vx,x) # add new x
  74.   vy <<- append(vy,y) # and new y
  75.   vt <<- append(vt,t)
  76.   vitems <<- append(vitems,banner.standard.item(t))
  77. }
  78.  
  79. wishonce <- function() { # Use one wish.
  80.   iter() # iterate once
  81. }
  82.  
  83. wish <- function(w) { # Use w wishes.
  84.   for (i in 1:w) {
  85.     wishonce() # this takes care of vx and vy as well
  86.   }
  87. }
  88.  
  89. # Convert one item t into a standard banner item.
  90. banner.standard.item <- function(t) {
  91.   if(t == 3) {
  92.     sample(v3,1)
  93.   } else if(t == 4) {
  94.     sample(v4,1)
  95.   } else if(t == 5) {
  96.     sample(v5,1)
  97.   } else {
  98.     "weird"
  99.   }
  100. }
  101.  
  102. # Convert your vector of items vt into standard banner items.
  103. # Not useful anymore.
  104. banner.standard.vector <- function(vt) {
  105.   lapply(vt,banner.standard.item)
  106. }
  107.  
  108. init.items()
  109. init.chain() # and make sure to init the sim!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement