Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Anvil Comparisons
- % Edoweiss
- % 2018-05-25
- % 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 = 20000;
- available_potential = 8;
- initial_level = 5; % initial level for the gold anvil case
- d_anvils_init = 30; % number of diamond anvils available
- d_price = 50; % price of a diamond anvil
- g_price = 4; % price of a golden anvil
- g_anvils_init = d_anvils_init*d_price/g_price; % golden anvil equivalent
- %% Setup
- pTable = [ 1
- 1
- 1
- 1
- 1
- 0.88
- 0.78
- 0.68
- 0.59
- 0.51
- 0.50
- ];
- %% Initialize Output Arrays
- n_levels = []; % levels from using just normal anvils
- g_levels = []; % levels from using just golden anvils
- d_levels = []; % levels from using just diamond anvils
- %% Normal Anvils
- % we keep trying until we run out of available potential
- for i = 1:trials;
- pot = available_potential; % potential remaining
- lvl = initial_level; % current enhancement level
- while pot > 0
- if lvl < length(pTable)
- check = pTable(lvl+1);
- else
- check = 0.50;
- end
- if rand < check % success
- lvl = lvl + 1;
- else % failure
- lvl = lvl - 1;
- pot = pot - 1;
- end
- end
- n_levels = [n_levels; lvl];
- end
- %% Golden Anvils
- % we keep trying until we run out of golden anvils
- for i = 1:trials;
- lvl = initial_level; % current enhancement level
- g_anvils = g_anvils_init; % number of golden anvils at our disposal
- while g_anvils > 0
- g_anvils = g_anvils - 1;
- if lvl < length(pTable)
- check = pTable(lvl+1);
- else
- check = 0.50;
- end
- if rand < check % success
- lvl = lvl + 1;
- else %failure
- if lvl > 11
- lvl = 10;
- else
- lvl = lvl - 1;
- end
- end
- end
- g_levels = [g_levels; lvl];
- end
- %% Diamond Anvils
- % we keep trying until we run out of golden anvils
- for i = 1:trials;
- pot = available_potential; % potential remaining
- lvl = initial_level; % current enhancement level
- d_anvils = d_anvils_init; % number of golden anvils at our disposal
- while pot > 0 && d_anvils > 0
- d_anvils = d_anvils - 1;
- if lvl < length(pTable)
- check = pTable(lvl+1);
- else
- check = 0.50;
- end
- if rand < check % success
- lvl = lvl + 1;
- else %failure
- pot = pot - 1;
- end
- end
- d_levels = [d_levels; lvl];
- end
- %% Compute histograms
- % diamond anvil case
- [h_n,e_n] = histcounts(n_levels,'Normalization','pdf');
- for i = 1:length(e_n)-1 % get centers of bins
- c_n(i) = (e_n(i)+e_n(i+1))/2;
- end
- % golden anvils case
- [h_g,e_g] = histcounts(g_levels,'Normalization','pdf');
- for i = 1:length(e_g)-1 % get centers of bins
- c_g(i) = (e_g(i)+e_g(i+1))/2;
- end
- % diamond anvils case
- [h_d,e_d] = histcounts(d_levels,'Normalization','pdf');
- for i = 1:length(e_d)-1 % get centers of bins
- c_d(i) = (e_d(i)+e_d(i+1))/2;
- end
- %% Plot
- fig1 = figure; hold on
- plot(c_n,h_n,'k')
- plot(c_g,h_g,'color',[1 0.7 0])
- plot(c_d,h_d,'color',[0 0.5 1])
- legend('normal','golden','diamond')
- ylabel('Probability Density')
- xlabel('enhancement level')
- saveas(fig1,'3pdf.png')
Advertisement
Add Comment
Please, Sign In to add comment