Advertisement
martinm07

Untitled

Nov 2nd, 2023 (edited)
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 2.97 KB | None | 0 0
  1. using Random
  2.  
  3. struct Card
  4.     embers::Number
  5.     quickdraw::Number
  6.     stumbles::Number
  7.     skip::Number
  8.     isColdSnap::Bool
  9.     function Card(isColdSnap::Bool)
  10.         new(0, 0, 0, 0, isColdSnap)
  11.     end
  12.     function Card(embers; quickdraw = 0, stumbles = 0, skip = 0)
  13.         new(embers, quickdraw, stumbles, skip, false)
  14.     end
  15. end
  16.  
  17. STU = Card(0)
  18. SNE = Card(0)
  19. STA = Card(0)
  20. TRH = Card(0)
  21. EMS = Card(2)
  22. EVA = Card(0)
  23. TRL = Card(0)
  24. FRF = Card(4)
  25. LAS = Card(0)
  26. SEW = Card(0)
  27. BST = Card(0)
  28. REC = Card(10)
  29. SPT = Card(0)
  30. NIL = Card(0)
  31. SAG = Card(0)
  32. QUI = Card(0, quickdraw = 1)
  33. EES = Card(0, skip = 1)
  34. SWA = Card(10, stumbles = 2)
  35. COS = Card(true)
  36.  
  37. ethos_deck = [
  38.     repeat([SNE], 4)...,
  39.     repeat([STA], 4)...,
  40.     repeat([TRH], 5)...,
  41.     repeat([EMS], 5)...,
  42.     repeat([EVA], 3)...,
  43.     TRL,
  44.     repeat([FRF], 2)...,
  45.     repeat([LAS], 3)...,
  46.     SEW,
  47.     repeat([BST], 2)...,
  48.     REC,
  49.     repeat([SPT], 2)...,
  50.     NIL,
  51.     SAG,
  52.     QUI,
  53.     repeat([EES], 2)...,
  54.     SWA,
  55.     COS
  56. ]
  57.  
  58. function simulate_run(starting_deck::Vector{Card})
  59.     deck = deepcopy(starting_deck)
  60.     total_embers = 0
  61.  
  62.     double_embers = 0
  63.     quickdraw = 0
  64.     stumble_timer = 3
  65.     skip = 0
  66.     while length(deck) > 0
  67.         if skip > 0
  68.             skip -= 1
  69.             continue
  70.         end
  71.         card = popat!(deck, rand(1:length(deck)))
  72.         total_embers += double_embers > 0 ? card.embers * 2 : card.embers
  73.  
  74.         quickdraw += card.quickdraw
  75.         push!(deck, repeat([STU], card.stumbles)...)
  76.         skip = card.skip
  77.  
  78.         double_embers > 0 && (double_embers -= 1)
  79.         card.isColdSnap && (double_embers += 3)
  80.  
  81.         if quickdraw > 0
  82.             if stumble_timer == 0
  83.                 push!(deck, STU)
  84.                 stumble_timer = 3
  85.             else
  86.                 stumble_timer -= 1
  87.             end
  88.         end
  89.         quickdraw > 0 && (quickdraw -= 1)
  90.     end
  91.     total_embers
  92. end
  93.  
  94. data = [simulate_run(ethos_deck) for _ in 1:10000]
  95.  
  96. using Statistics
  97.  
  98. exp_data = map(x -> x - minimum(data), data)
  99. println("The average value of COS is $(mean(exp_data)) ± $(std(exp_data)), making the overall deck ember average $(mean(data)). The 50th percentile (median) is $(median(exp_data))")
  100.  
  101. using CairoMakie
  102.  
  103. f, _, _ = hist(data; normalization = :pdf, color = :values, bar_labels = :x,
  104.      label_formatter = x -> Integer(floor(x)), label_size = 15,
  105.      strokewidth = 0.5, strokecolor = (:black, 0.5), colormap = :blues,
  106.      axis = (; title = "Frost Embers of Etho's Deck incl. Cold Snap", titlesize = 20,
  107.              subtitle = "Note: Without COS, the frost embers of the deck are 38 ± 0 (no variation)",
  108.              subtitlevisible = true,
  109.              xlabel = "Total Resulting Frost Embers", ylabel = "Probability Density",
  110.              xgridvisible = false, topspinevisible = false, rightspinevisible = false,
  111.              bottomspinevisible = false, xticks = [0], yticks = LinearTicks(8)))
  112. save("COS_histogram.png", f)
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement