Guest User

Untitled

a guest
May 25th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.61 KB | None | 0 0
  1. %% Anvil Comparisons
  2. % Edoweiss
  3. % 2018-05-25
  4.  
  5. % In this script we perform a monte carlo simulations to estimate the cost
  6. % of making a brand new weapon versus attempting over and over on an
  7. % existing weapon using golden anvils
  8.  
  9. close all; clear all; clc
  10.  
  11. %% Simulations Targets/Parameters
  12. trials = 20000;
  13. available_potential = 8;
  14. initial_level = 5; % initial level for the gold anvil case
  15.  
  16. d_anvils_init = 30; % number of diamond anvils available
  17. d_price = 50; % price of a diamond anvil
  18. g_price = 4; % price of a golden anvil
  19. g_anvils_init = d_anvils_init*d_price/g_price; % golden anvil equivalent
  20.  
  21. %% Setup
  22. pTable = [  1
  23.             1
  24.             1
  25.             1
  26.             1
  27.             0.88
  28.             0.78
  29.             0.68
  30.             0.59
  31.             0.51
  32.             0.50
  33.             ];
  34.        
  35. %% Initialize Output Arrays
  36. n_levels = []; % levels from using just normal anvils
  37. g_levels = []; % levels from using just golden anvils
  38. d_levels = []; % levels from using just diamond anvils
  39.  
  40. %% Normal Anvils
  41. % we keep trying until we run out of available potential
  42. for i = 1:trials;
  43.     pot = available_potential; % potential remaining
  44.     lvl = initial_level; % current enhancement level
  45.     while pot > 0
  46.         if lvl < length(pTable)
  47.             check = pTable(lvl+1);
  48.         else
  49.             check = 0.50;
  50.         end
  51.         if rand < check % success
  52.             lvl = lvl + 1;
  53.         else % failure
  54.             lvl = lvl - 1;
  55.             pot = pot - 1;
  56.         end
  57.     end
  58.     n_levels = [n_levels; lvl];
  59. end
  60.    
  61. %% Golden Anvils
  62. % we keep trying until we run out of golden anvils
  63. for i = 1:trials;
  64.     lvl = initial_level; % current enhancement level
  65.     g_anvils = g_anvils_init; % number of golden anvils at our disposal
  66.     while g_anvils > 0
  67.         g_anvils = g_anvils - 1;
  68.         if lvl < length(pTable)
  69.             check = pTable(lvl+1);
  70.         else
  71.             check = 0.50;
  72.         end
  73.         if rand < check % success
  74.             lvl = lvl + 1;
  75.         else %failure
  76.             if lvl > 11
  77.                 lvl = 10;
  78.             else
  79.                 lvl = lvl - 1;
  80.             end
  81.         end
  82.     end
  83.     g_levels = [g_levels; lvl];
  84. end
  85.  
  86. %% Diamond Anvils
  87. % we keep trying until we run out of golden anvils
  88. for i = 1:trials;
  89.     pot = available_potential; % potential remaining
  90.     lvl = initial_level; % current enhancement level
  91.     d_anvils = d_anvils_init; % number of golden anvils at our disposal
  92.     while pot > 0 && d_anvils > 0
  93.         d_anvils = d_anvils - 1;
  94.         if lvl < length(pTable)
  95.             check = pTable(lvl+1);
  96.         else
  97.             check = 0.50;
  98.         end
  99.         if rand < check % success
  100.             lvl = lvl + 1;
  101.         else %failure
  102.             pot = pot - 1;
  103.         end
  104.     end
  105.     d_levels = [d_levels; lvl];
  106. end
  107.  
  108. %% Compute histograms
  109. % diamond anvil case
  110. [h_n,e_n] = histcounts(n_levels,'Normalization','pdf');
  111.  
  112. for i = 1:length(e_n)-1 % get centers of bins
  113.     c_n(i) = (e_n(i)+e_n(i+1))/2;
  114. end
  115.  
  116. % golden anvils case
  117. [h_g,e_g]  = histcounts(g_levels,'Normalization','pdf');
  118.  
  119. for i = 1:length(e_g)-1 % get centers of bins
  120.     c_g(i) = (e_g(i)+e_g(i+1))/2;
  121. end
  122.  
  123. % diamond anvils case
  124. [h_d,e_d]  = histcounts(d_levels,'Normalization','pdf');
  125.  
  126. for i = 1:length(e_d)-1 % get centers of bins
  127.     c_d(i) = (e_d(i)+e_d(i+1))/2;
  128. end
  129.  
  130. %% Plot
  131. fig1 = figure; hold on
  132. plot(c_n,h_n,'k')
  133. plot(c_g,h_g,'color',[1 0.7 0])
  134. plot(c_d,h_d,'color',[0 0.5 1])
  135. legend('normal','golden','diamond')
  136. ylabel('Probability Density')
  137. xlabel('enhancement level')
  138.  
  139. saveas(fig1,'3pdf.png')
Advertisement
Add Comment
Please, Sign In to add comment