Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 5.31 KB | None | 0 0
  1. %% Anvil Comparisons
  2. % Edoweiss
  3. % 2018-04-12
  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 = 10000;
  13. available_potential = 8;
  14. targetLevel_List = [11 12 13 14 15 16 17 18 19 20 21];
  15. Level_List = [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26];
  16. initial_level = 6; % initial level for the gold anvil case
  17.  
  18. % costs in millions
  19. remakeCost_List = [8];
  20. goldenCost_List = [2.5 5 7.5 10];
  21.  
  22. %% Upgrade Costs
  23. cTable = [  52469
  24.             75104
  25.             97739
  26.             120374
  27.             143009
  28.             165643
  29.             188278
  30.             210913
  31.             233548
  32.             256183
  33.             348522
  34.             452179
  35.             567153
  36.             693445
  37.             831054
  38.             979980
  39.             1140224
  40.             1311785
  41.             1494664
  42.             1688860
  43.             1894373
  44.             2111204
  45.             2339353
  46.             2578819
  47.             2829602
  48.             3091702
  49.             3365120
  50.             3649856
  51.             3945909
  52.             4253279
  53.             4571967
  54.             4901972
  55.             5243294
  56.             5595934
  57.             5959892
  58.             6335166];
  59.        
  60. %% Setup
  61. pTable = [  1
  62.             1
  63.             1
  64.             1
  65.             1
  66.             0.88
  67.             0.78
  68.             0.68
  69.             0.59
  70.             0.51
  71.             0.50
  72.             0.50
  73.             0.50
  74.             0.50
  75.             0.50
  76.             0.50
  77.             0.50
  78.             0.50
  79.             0.50
  80.             0.50
  81.             0.50
  82.             0.50
  83.             0.50
  84.             0.50
  85.             0.50
  86.             0.50
  87.             0.50
  88.             0.50
  89.             0.50
  90.             0.50
  91.             0.50
  92.             0.50
  93.             0.50
  94.             0.50
  95.             0.50 ];
  96.        
  97. %% Perform Simulations across many different target levels
  98.  
  99. attempt_Array_1 = [];
  100. diamond_Array = [];
  101. silver_Array_1 = [];
  102.  
  103. %% Normal Anvils, Remaking Weapon
  104.  
  105. for target_level = targetLevel_List
  106. attempt_List_1 = []; % number of new weapons made
  107. silver_List_1 = []; % amount of silver expended
  108. diamond_List = []; % number of diamond anvils expended
  109. for i = 1:trials
  110.     % initiate trial
  111.     pot = available_potential; % potential of the weapon
  112.     lvl = 5; % current enhancement level
  113.     silver = sum(cTable(1:5));
  114.     attempts = 1; % total attempts using a new weapon
  115.     dmd = 0;
  116.     while lvl < target_level % keep trying until we make the target
  117.         if pot > 0
  118.             check = pTable(lvl+1);
  119.             dmd = dmd + 1;
  120.             silver = silver + 3*cTable(lvl+1);
  121.             if rand < check % success
  122.                 lvl = lvl + 1; % increase the level
  123.             else % failure
  124.                 lvl = lvl;
  125.                 pot = pot - 1;
  126.             end
  127.         end
  128.         if pot == 0 % weapon broke
  129.             attempts = attempts + 1; % make a new weapon
  130.             pot = available_potential;
  131.         end
  132.     end
  133.     attempt_List_1 = [attempt_List_1; attempts];
  134.     diamond_List = [diamond_List; dmd];
  135.     silver_List_1 = [silver_List_1; silver];
  136. end
  137.  
  138. diamond_Array = [diamond_Array diamond_List];
  139. attempt_Array_1 = [attempt_Array_1 attempt_List_1];
  140. silver_Array_1 = [silver_Array_1 silver_List_1];
  141.  
  142. end
  143.  
  144. %% Diamond Anvils, One Weapon
  145.  
  146. level_results = [];
  147. attempt_List = []; % number of new weapons made
  148. silver_List = []; % amount of silver expended
  149. for i = 1:trials
  150.     % initiate trial
  151.     pot = available_potential; % potential of the weapon
  152.     lvl = 5; % current enhancement level
  153.     silver = sum(cTable(1:5));
  154.     attempts = 0; % total diamond anvils consumed
  155.     while pot > 0 % keep trying until we make the target
  156.         check = pTable(lvl+1);
  157.         attempts = attempts + 1;
  158.         silver = silver + 3*cTable(lvl+1);
  159.         if rand < check % success
  160.             lvl = lvl + 1; % increase the level
  161.         else % failure
  162.             pot = pot - 1;
  163.         end
  164.         if lvl == 35
  165.             break
  166.         end
  167.     end
  168.     level_results = [level_results; lvl];
  169.     attempt_List = [attempt_List; attempts];
  170.     silver_List = [silver_List; silver];
  171. end
  172.  
  173. %%
  174.  
  175. silver_Array_1 = silver_Array_1/10^6;
  176.  
  177. %% Plot Results - attempts and enhancement cost
  178. % remaking weapons
  179. fig1 = figure; hold on
  180. xlabel('target enhancement')
  181.  
  182. yyaxis left
  183. errorbar(targetLevel_List, mean(attempt_Array_1,1), std(attempt_Array_1,1))
  184. ylabel('weapons made')
  185.  
  186. yyaxis right
  187. errorbar(targetLevel_List, mean(silver_Array_1,1), std(silver_Array_1,1))
  188. ylabel('cost of enhancements (million silver)')
  189. grid on
  190. hold off
  191. saveas(fig1,'remaking_diamond_01.png')
  192.  
  193. % remaking weapons
  194. fig3 = figure; hold on
  195. xlabel('target enhancement')
  196.  
  197. yyaxis left
  198. errorbar(targetLevel_List, mean(attempt_Array_1,1), std(attempt_Array_1,1))
  199. ylabel('weapons made')
  200.  
  201. yyaxis right
  202. errorbar(targetLevel_List, mean(diamond_Array,1), std(diamond_Array,1))
  203. ylabel('diamond anvils used')
  204. grid on
  205. hold off
  206. saveas(fig3,'remaking_diamond_02.png')
  207.  
  208.  
  209. % trying until you run out
  210. fig2 = figure; hold on
  211. xlabel('enhancement level')
  212. ylabel('cumulative probability')
  213.  
  214. histogram(level_results,'Normalization','cdf')
  215. saveas(fig2,'dia_cdf.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement