Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Anvil Comparisons
- % Edoweiss
- % 2018-04-12
- % In this script we perform a monte carlo simulations to estimate the cost
- % of making a brand new weapon versus attempting over and over on an
- % existing weapon using golden anvils
- close all; clear all; clc
- %% Simulations Targets/Parameters
- trials = 10000;
- available_potential = 8;
- targetLevel_List = [11 12 13 14 15 16];
- initial_level = 6; % initial level for the gold anvil case
- % costs in millions
- remakeCost_List = [8];
- goldenCost_List = [2.5 5 7.5 10];
- %% Upgrade Costs
- cTable = [ 52469
- 75104
- 97739
- 120374
- 143009
- 165643
- 188278
- 210913
- 233548
- 256183
- 348522
- 452179
- 567153
- 693445
- 831054
- 979980
- 1140224
- 1311785
- 1494664
- 1688860
- 1894373];
- %% Setup
- pTable = [ 1
- 1
- 1
- 1
- 1
- 0.88
- 0.78
- 0.68
- 0.59
- 0.51
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50
- 0.50 ];
- %% Perform Simulations across many different target levels
- attempt_Array_1 = [];
- attempt_Array_2 = [];
- silver_Array_1 = [];
- silver_Array_2 = [];
- for target_level = targetLevel_List
- %% Normal Anvils, Remaking Weapon
- attempt_List_1 = []; % number of new weapons made
- silver_List_1 = []; % amount of silver expended
- for i = 1:trials
- % initiate trial
- pot = available_potential; % potential of the weapon
- lvl = 0; % current enhancement level
- silver = 0;
- attempts = 1; % total attempts using a new weapon
- while lvl < target_level % keep trying until we make the target
- if pot > 0
- check = pTable(lvl+1);
- silver = silver + cTable(lvl+1);
- if rand < check % success
- lvl = lvl + 1; % increase the level
- else % failure
- lvl = lvl - 1;
- pot = pot - 1;
- end
- end
- if pot == 0 % weapon broke
- attempts = attempts + 1; % make a new weapon
- pot = available_potential;
- end
- end
- attempt_List_1 = [attempt_List_1; attempts];
- silver_List_1 = [silver_List_1; silver];
- end
- %% Gold Anvils, One Weapon
- attempt_List_2 = [];
- silver_List_2 = [];
- for i = 1:trials
- lvl = initial_level; %
- silver = 0;
- attempts = 0;
- while lvl < target_level % keep trying until we make the target
- attempts = attempts + 1;
- check = pTable(lvl+1);
- % silver = silver + cTable(lvl+1);
- if rand < check % success
- lvl = lvl + 1;
- else % failure
- if lvl > 11
- lvl = 10; % forces level to 10 when you fail at > 11
- else
- lvl = lvl - 1;
- end
- end
- end
- attempt_List_2 = [attempt_List_2; attempts];
- silver_List_2 = [silver_List_2; silver];
- end
- attempt_Array_1 = [attempt_Array_1 attempt_List_1];
- attempt_Array_2 = [attempt_Array_2 attempt_List_2];
- silver_Array_1 = [silver_Array_1 silver_List_1];
- silver_Array_2 = [silver_Array_2 silver_List_2];
- end
- % convert silver to millions
- silver_Array_1 = silver_Array_1/10^6;
- silver_Array_2 = silver_Array_2/10^6;
- %% Plot Results - attempts and enhancement cost
- % remaking weapons
- fig1 = figure; hold on
- xlabel('target enhancement')
- yyaxis left
- errorbar(targetLevel_List, mean(attempt_Array_1,1), std(attempt_Array_1,1))
- ylabel('weapons made')
- yyaxis right
- errorbar(targetLevel_List, mean(silver_Array_1,1), std(silver_Array_1,1))
- ylabel('cost of enhancements (million silver)')
- grid on
- hold off
- saveas(fig1,'remaking_01.png')
- % using golden anvils
- fig2 = figure; hold on
- xlabel('target enhancement')
- yyaxis left
- errorbar(targetLevel_List, mean(attempt_Array_2,1), std(attempt_Array_2,1))
- ylabel('golden anvils consumed')
- yyaxis right
- errorbar(targetLevel_List, mean(silver_Array_2,1), std(silver_Array_2,1))
- ylabel('cost of enhancements (million silver)')
- grid on
- grid minor
- hold off
- saveas(fig2,'goldens_01.png')
- %% Plot Results - total costs
- % calculate total costs
- totalCost_Cell_1 = [];
- totalCost_Cell_2 = [];
- for i = 1:length(remakeCost_List)
- remakeCost = remakeCost_List(i);
- totalCost_Cell_1{i} = attempt_Array_1*remakeCost + silver_Array_1;
- end
- for i = 1:length(goldenCost_List)
- goldenCost = goldenCost_List(i);
- totalCost_Cell_2{i} = attempt_Array_2*goldenCost + silver_Array_2;
- end
- % plot a variety of different costs values
- fig3 = figure; hold on
- A = [];
- B = [];
- xlabel('target enhancement')
- ylabel('total cost (million silver)')
- for i = 1:length(remakeCost_List)
- plotData = totalCost_Cell_1{i};
- A{i} = plot(targetLevel_List, mean(plotData,1),'-',...
- 'color',[1,0.5,1-i/length(remakeCost_List)]);
- end
- for i = 1:length(goldenCost_List)
- plotData = totalCost_Cell_2{i};
- B{i} = plot(targetLevel_List, mean(plotData,1),'--',...
- 'color',[0,0.5,i/length(goldenCost_List)]);
- end
- legend([A{1} B{1}],{'remaking','goldens'},'location','northwest')
- set(gca,'XTick',11:16)
- grid on
- hold off
- saveas(fig3,'multi_comparisons.png')
- % plotting a particular cost value
- fig4 = figure; hold on
- xlabel('target enhancement')
- ylabel('total cost (million silver)')
- ylim([0 1800])
- i = 1;
- plotData = totalCost_Cell_1{i};
- errorbar(targetLevel_List, mean(plotData,1),std(plotData,1),'o-',...
- 'color',[1,0.5,1-i/length(remakeCost_List)]);
- i = 1;
- plotData = totalCost_Cell_2{i};
- errorbar(targetLevel_List, mean(plotData,1),std(plotData,1),'o--',...
- 'color',[0,0.5,i/length(goldenCost_List)]);
- legend('remaking','goldens','location','northwest')
- grid on
- hold off
- saveas(fig4,'my_case.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement