Last active
January 13, 2021 08:01
-
-
Save guipenedo/6791ef6f57ff6e8971fde86e90d0a1ec to your computer and use it in GitHub Desktop.
Script to calculate best scavenging splits - TribalWars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% script to calculate best scavenging splits - TribalWars | |
% author: PhilipsNostrum (@guipenedo) | |
% calculate best split using fmincon for 1 spear, up to *upper* spears | |
upper=500; | |
% scavenge time (C is the loot capacity, for instance, 1 spear = 25 loot capacity) | |
% ((C*LF*10)^(2*DE)+DIS)*DF | |
global c_tot LF DE DIS DF | |
% these factors may be found on TW's source code (search for "ScavengeScreen") | |
LF = [0.1, 0.25, 0.5, 0.75]; % loot factor | |
DE = 0.45; % duration exponent | |
DIS = 1800; % duration initial seconds | |
DF = 0.6830201284; % duration factor | |
x0 = ones(4,1); % initial point: 1 (close to 0) | |
options = optimoptions('fmincon','Display','iter','Algorithm','sqp','MaxFunctionEvaluations',100000,'MaxIterations',2000); | |
res = zeros(4,upper); | |
for sp=1:upper | |
c_tot = 25*sp; | |
x = floor(fmincon(@f, x0, [], [], [], [], zeros(4,1), [], @g, options)/25); | |
res(:,sp) = x; | |
end | |
function [cost] = f(c) | |
global LF | |
cost = 0; | |
for i=1:4 | |
cost = cost + (c(i)*LF(i))/(t(c(i),LF(i))); | |
end | |
cost = 1/cost; | |
end | |
function [v] = t(ci,LFi) | |
global DE DIS DF | |
v = ((ci*ci*LFi*LFi*100).^DE+DIS)*DF; | |
end | |
function [c, ceq] = g(cs) | |
global c_tot | |
c = 0; | |
ceq = -c_tot; | |
for i=1:4 | |
ceq = ceq + cs(i); | |
end | |
end |
hey! can you tell us how to use it? for example my world is 1.2 speed and the troop speed is 0.8. Now whats next? :D
Just open up Matlab and run this script. But as I said this isn't meant to be used except for programmers looking to create scripts
Could you explain the formula for time calculation of scavenging trips. I am trying to understand what are the variables involved.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kirgizmustafa17 this is not a tampermonkey script. It's only meant to calculate optimal distributions for later use on scripts