Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Playset Drawing Simulations (to determine how best to model ICR chances for rare playsets)
- #Written: 2021-0704 by Emil Karpinski
- #Setting up some variables
- #cards - tracks the cards that have been obtained in each method (no duplicates)
- #ItCount - tracks how many random ICRs were needed to complete each set (i.e. 1:100 x 4 in the Four_Off method; 1:400 x 1 in the Individual Card method)
- #Iteration - tracks how many times you've gotten an ICR
- #i and a - general all purpose counters for the while and for loops
- cards <- vector()
- ItCount <- vector()
- iteration <- 0
- i <- 0
- #Does 1000 simulations tracking the time needed to obtain a set of 100 rares (in full playsets, 4 of each). This is done two ways.
- #The first way simulates more closely the actual game. It requires you to collect 4x 100 rares, represented by the numbers 1:100 (i.e. requires four instances of the value 1, four instances of the value 2, ..., four instances of the value 100).
- #The second way treats each rare as unique; so the first rare playset requires values 1, 2, 3, and 4. This way is easier to code, but takes longer.
- #Sets up the loop for the 1000 simulations
- for (a in 1:10000)
- {
- #Runs until the set is complete - denoted by the flag (i) changing from 0 to 1
- while (i < 1)
- {
- #Counts how many times we've been through this loop. i.e. how many times have we drawn a card and checked if we have it or not.
- iteration <- iteration + 1
- #Samples a random number from 1:100 (where 100 is the number of rares). Replace does nothing here.
- x <- sample(1:100, 1, replace=T)
- #Checks if the chosen number has been drawn less than 4 cards. If so then it adds that entry to the list of cards drawn (cards vector).
- #Then checks to see if there are 400 entries in that vector (which would denote a full playset of all 100 rares). If so it trips the i flag to leave the loop.
- if (sum(cards == x) < 4)
- {
- cards <- c(cards,x)
- #Records the iterations at which unique cards (i.e. those for which we don't have a playset are drawn)
- if (length(cards) == 400)
- {
- i <- 1
- }
- }
- }
- #Extends the vector ItCount (stores the number of draws it took to get a full playset - i.e. iteration), and adds the last value of iteration to it.
- ItCount <- c(ItCount, iteration)
- #Cleans up the cards vector (sets it to empty), sets iterations to 0, and resets the flag to re-enable the while loop.
- cards <- vector()
- iteration <- 0
- i <- 0
- }
- #Since I copied and pasted the above in the below version, I'm just creating a new vector here (Four_Off_Comp_Count) to store the values within ItCount so I don't need to Ctrl+F and replace it in the loops below. Then wipe ItCount so it can be used in the second batch of simulations.
- Four_Off_Comp_Count <- ItCount
- ItCount <- vector()
- #Sets up the loop for 1000 simulations
- for (b in 1:10000)
- {
- #As before
- while (i < 1)
- {
- #As before, but not sampling from the numbers 1:400 with sets of 4 representing a playset.
- x <- sample(1:400, 1, replace=T)
- #As before, but checks if that number is present. If it isn't it's added, and we check to see all 400 unique entries are present. If so the i flag gets set to 1 to escape the loop.
- if (sum(cards == x) < 1)
- {
- cards <- c(cards,x)
- if (length(cards) == 400)
- {
- i <- 1
- }
- }
- #Regardless iterations are increased by 1
- iteration <- iteration + 1
- }
- #Stores the number of cards you needed to draw to get a complete set of 400 rares.
- ItCount <- c(ItCount, iteration)
- #Resets everything like before
- cards <- vector()
- iteration <- 0
- i <- 0
- }
- #For consistencies sake, also outputting the values in ItCount to a vector for this method, then wiping it.
- Ind_Card_Comp_Count <- ItCount
- ItCount <- vector()
- #outputs some basic summary stats for the two approaches.
- summary(Four_Off_Comp_Count)
- summary(Ind_Card_Comp_Count)
- plot(Four_Off_Comp_Count, type = "p", xlab = "Simulation Number", ylab = "Iterations", main = "Draws until Rare Completion", col = "blue", ylim = c(400,6000))
- points(Ind_Card_Comp_Count, col = "red")
- lines(c(c(1:10000)), rep(mean(Four_Off_Comp_Count), 10000), col = "yellow", lwd = 3)
- lines(c(c(1:10000)), rep(mean(Ind_Card_Comp_Count), 10000), col = "green", lwd = 3)
Advertisement
Add Comment
Please, Sign In to add comment