Skip to content

Instantly share code, notes, and snippets.

@guipenedo
Last active January 13, 2021 08:01
Show Gist options
  • Save guipenedo/6791ef6f57ff6e8971fde86e90d0a1ec to your computer and use it in GitHub Desktop.
Save guipenedo/6791ef6f57ff6e8971fde86e90d0a1ec to your computer and use it in GitHub Desktop.
Script to calculate best scavenging splits - TribalWars
% 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
@kirgizmustafa17
Copy link

How can I use this without any software installation? I did not understand the basic math of your script. Can you help me @guipenedo

Scripts are not allowed in our country.

@guipenedo
Copy link
Author

@kirgizmustafa17 this is not a tampermonkey script. It's only meant to calculate optimal distributions for later use on scripts

@pmwhyy
Copy link

pmwhyy commented Apr 13, 2020

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

@guipenedo
Copy link
Author

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

@rsk2327
Copy link

rsk2327 commented Nov 16, 2020

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