Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 6.12 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];
  15. initial_level = 6; % initial level for the gold anvil case
  16.  
  17. % costs in millions
  18. remakeCost_List = [8];
  19. goldenCost_List = [2.5 5 7.5 10];
  20.  
  21. %% Upgrade Costs
  22. cTable = [  52469
  23.             75104
  24.             97739
  25.             120374
  26.             143009
  27.             165643
  28.             188278
  29.             210913
  30.             233548
  31.             256183
  32.             348522
  33.             452179
  34.             567153
  35.             693445
  36.             831054
  37.             979980
  38.             1140224
  39.             1311785
  40.             1494664
  41.             1688860
  42.             1894373];
  43.        
  44. %% Setup
  45. pTable = [  1
  46.             1
  47.             1
  48.             1
  49.             1
  50.             0.88
  51.             0.78
  52.             0.68
  53.             0.59
  54.             0.51
  55.             0.50
  56.             0.50
  57.             0.50
  58.             0.50
  59.             0.50
  60.             0.50
  61.             0.50
  62.             0.50
  63.             0.50
  64.             0.50
  65.             0.50
  66.             0.50
  67.             0.50
  68.             0.50
  69.             0.50
  70.             0.50 ];
  71.        
  72. %% Perform Simulations across many different target levels
  73.  
  74. attempt_Array_1 = [];
  75. attempt_Array_2 = [];
  76. silver_Array_1 = [];
  77. silver_Array_2 = [];
  78.  
  79. for target_level = targetLevel_List
  80.    
  81. %% Normal Anvils, Remaking Weapon
  82.  
  83. attempt_List_1 = []; % number of new weapons made
  84. silver_List_1 = []; % amount of silver expended
  85. for i = 1:trials
  86.     % initiate trial
  87.     pot = available_potential; % potential of the weapon
  88.     lvl = 0; % current enhancement level
  89.     silver = 0;
  90.     attempts = 1; % total attempts using a new weapon
  91.     while lvl < target_level % keep trying until we make the target
  92.         if pot > 0
  93.             check = pTable(lvl+1);
  94.             silver = silver + cTable(lvl+1);
  95.             if rand < check % success
  96.                 lvl = lvl + 1; % increase the level
  97.             else % failure
  98.                 lvl = lvl - 1;
  99.                 pot = pot - 1;
  100.             end
  101.         end
  102.         if pot == 0 % weapon broke
  103.             attempts = attempts + 1; % make a new weapon
  104.             pot = available_potential;
  105.         end
  106.     end
  107.     attempt_List_1 = [attempt_List_1; attempts];
  108.     silver_List_1 = [silver_List_1; silver];
  109. end
  110.  
  111. %% Gold Anvils, One Weapon
  112.  
  113. attempt_List_2 = [];
  114. silver_List_2 = [];
  115.  
  116. for i = 1:trials
  117.     lvl = initial_level; %
  118.     silver = 0;
  119.     attempts = 0;
  120.     while lvl < target_level % keep trying until we make the target
  121.         attempts = attempts + 1;
  122.         check = pTable(lvl+1);
  123. %         silver = silver + cTable(lvl+1);
  124.         if rand < check % success
  125.             lvl = lvl + 1;
  126.         else % failure
  127.             if lvl > 11
  128.                 lvl = 10; % forces level to 10 when you fail at > 11
  129.             else
  130.                 lvl = lvl - 1;
  131.             end
  132.         end
  133.     end
  134.     attempt_List_2 = [attempt_List_2; attempts];
  135.     silver_List_2 = [silver_List_2; silver];
  136. end
  137.    
  138. attempt_Array_1 = [attempt_Array_1 attempt_List_1];
  139. attempt_Array_2 = [attempt_Array_2 attempt_List_2];
  140. silver_Array_1 = [silver_Array_1 silver_List_1];
  141. silver_Array_2 = [silver_Array_2 silver_List_2];
  142.  
  143. end
  144.  
  145. % convert silver to millions
  146. silver_Array_1 = silver_Array_1/10^6;
  147. silver_Array_2 = silver_Array_2/10^6;
  148.        
  149. %% Plot Results - attempts and enhancement cost
  150. % remaking weapons
  151. fig1 = figure; hold on
  152. xlabel('target enhancement')
  153.  
  154. yyaxis left
  155. errorbar(targetLevel_List, mean(attempt_Array_1,1), std(attempt_Array_1,1))
  156. ylabel('weapons made')
  157.  
  158. yyaxis right
  159. errorbar(targetLevel_List, mean(silver_Array_1,1), std(silver_Array_1,1))
  160. ylabel('cost of enhancements (million silver)')
  161. grid on
  162. hold off
  163. saveas(fig1,'remaking_01.png')
  164.  
  165. % using golden anvils
  166. fig2 = figure; hold on
  167. xlabel('target enhancement')
  168.  
  169. yyaxis left
  170. errorbar(targetLevel_List, mean(attempt_Array_2,1), std(attempt_Array_2,1))
  171. ylabel('golden anvils consumed')
  172.  
  173. yyaxis right
  174. errorbar(targetLevel_List, mean(silver_Array_2,1), std(silver_Array_2,1))
  175. ylabel('cost of enhancements (million silver)')
  176. grid on
  177. grid minor
  178. hold off
  179. saveas(fig2,'goldens_01.png')
  180.  
  181. %% Plot Results - total costs
  182. % calculate total costs
  183. totalCost_Cell_1 = [];
  184. totalCost_Cell_2 = [];
  185. for i = 1:length(remakeCost_List)
  186.     remakeCost = remakeCost_List(i);
  187.     totalCost_Cell_1{i} = attempt_Array_1*remakeCost + silver_Array_1;
  188. end
  189. for i = 1:length(goldenCost_List)
  190.     goldenCost = goldenCost_List(i);
  191.     totalCost_Cell_2{i} = attempt_Array_2*goldenCost + silver_Array_2;
  192. end
  193.        
  194. % plot a variety of different costs values
  195. fig3 = figure; hold on
  196. A = [];
  197. B = [];
  198. xlabel('target enhancement')
  199. ylabel('total cost (million silver)')
  200. for i = 1:length(remakeCost_List)
  201.     plotData = totalCost_Cell_1{i};
  202.     A{i} = plot(targetLevel_List, mean(plotData,1),'-',...
  203.         'color',[1,0.5,1-i/length(remakeCost_List)]);
  204. end
  205. for i = 1:length(goldenCost_List)
  206.     plotData = totalCost_Cell_2{i};
  207.     B{i} = plot(targetLevel_List, mean(plotData,1),'--',...
  208.         'color',[0,0.5,i/length(goldenCost_List)]);
  209. end
  210. legend([A{1} B{1}],{'remaking','goldens'},'location','northwest')
  211. set(gca,'XTick',11:16)
  212. grid on
  213. hold off
  214. saveas(fig3,'multi_comparisons.png')
  215.  
  216. % plotting a particular cost value
  217. fig4 = figure; hold on
  218. xlabel('target enhancement')
  219. ylabel('total cost (million silver)')
  220. ylim([0 1800])
  221. i = 1;
  222. plotData = totalCost_Cell_1{i};
  223. errorbar(targetLevel_List, mean(plotData,1),std(plotData,1),'o-',...
  224.     'color',[1,0.5,1-i/length(remakeCost_List)]);
  225. i = 1;
  226. plotData = totalCost_Cell_2{i};
  227. errorbar(targetLevel_List, mean(plotData,1),std(plotData,1),'o--',...
  228.         'color',[0,0.5,i/length(goldenCost_List)]);
  229. legend('remaking','goldens','location','northwest')
  230. grid on
  231. hold off
  232. saveas(fig4,'my_case.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement