Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //should be moved into server.script
- // when import depth bug is fixed
- function miningRatio(servername) {
- disableLog("ALL");
- //calculation of optimal settings
- /*
- * Optimal settings are the combination of g grow calls and h hacking calls
- * where the amount replenished from growth is more or equal to the amount of money hacked.
- *
- * for this we calculate the amount of growth calls from the amount of money hacked by a single hack * the chance of success
- * this allows us to get a grow/hack ratio we then round up to be sure of having enough growth to provide enough money to hack.
- *
- */
- h = 1;
- h_percent = (hackAnalyzePercent(servername) * hackChance(servername)) / 100;
- g = growthAnalyze(servername, 1 + h_percent);
- //if we have an infinite value of growth needed (likely to be a server with 0 max money)
- if (!isFinite(g)) {
- h = 0;
- g = 0;
- w = 0;
- c = 0;
- hacked_per_hack = 0.0;
- hacked_per_second_per_hack = 0.0;
- } else {
- ////g is not necessarily > 1 yet
- // if g < 1 then we scale up h to keep up with a single grow call => h = 1/g; g = 1;
- if (g < 1) {
- h = Math.floor(1 / g);
- g = 1;
- }
- //else if g > 1, then we round up g without changing h to replenish what the hacking depletes.
- else if (g > 1) {
- h = 1;
- g = Math.ceil(g);
- }
- //cycles calculation
- /*
- * We take into account the server security, and want to achieve a specific optimum of
- * running as much grow-hack cycles as possible while keeping the security gradient below the weaken threshold (0.05)
- *
- * the calculus is simple ;
- * c*(0.004*g + 0.002*h) <= 0.05 -> c*0.002(2*g + h) <= 0.05
- * hence c <= 0.05/0.002 * 1/(2g + h) -> c <= 25/(2*g + h)
- */
- c = Math.max(1, Math.floor(25 / (2 * g + h)));
- // the amount of weaken needed to keep the security gain below or equal to zero can be calculated as such:
- // (0.004g+0.002h)c-0.05w<= 0
- // -> w >= (0.004g+0.002h)c/0.05
- w = Math.ceil((0.004 * g + 0.002 * h) * c / 0.05);
- hacked_per_hack = (getServerMaxMoney(servername) * h_percent);
- hacked_per_second_per_hack = (hacked_per_hack / getHackTime(servername));
- }
- data = {
- g: g,
- h: h,
- c: c,
- w: w,
- //PRODUCTIVITY
- hPerHack: hacked_per_hack,
- hPerSecPerHack: hacked_per_second_per_hack,
- hPerSec: (hacked_per_hack * h)/(c*(h*getHackTime(servername)+g*getGrowTime(servername))+w*getWeakenTime(servername))
- };
- //tprint("SERVER " + servername);
- //Object.keys(data).forEach(function(key) { tprint(key + " -> " + data[key]); });
- return data;
- }
- function analyze(servername, parentname) {
- disableLog("ALL");
- parentname = parentname || "";
- server = {
- //server related
- name: servername,
- RAM: getServerRam(servername)[0],
- hackLevel: getServerRequiredHackingLevel(servername),
- portsNeeded: getServerNumPortsRequired(servername),
- rootAccess: hasRootAccess(servername),
- parent: parentname,
- //Mining related
- //GROWTH-HACK-WEAKEN RATIOS as amounts of calls, always considered stable, calculated to be.
- growthPerCycle: 0,
- hackPerCycle: 0,
- growHackCycles: 0,
- weakenPostCycles: 0,
- //PRODUCTIVITY
- growthPerSec: 0,
- hackedPerSec: 0,
- //RAM USAGE considering each as a separate script thread (1.75GB for grow and weaken, 1.7GB for hack)
- growthRAM: 0,
- hackRAM: 0,
- weakenRAM: 0,
- totalRAM: 0,
- HackedPerSecondPerRAM: 0
- };
- return update(server);
- }
- function update(server) {
- if (!server.rootAccess)
- server.rootAccess = hasRootAccess(server.name);
- if (server.rootAccess) {
- mining_data = miningRatio(server.name);
- server.growthPerCycle = mining_data.g;
- server.hackPerCycle = mining_data.h;
- server.growHackCycles = mining_data.c;
- server.weakenPostCycles = mining_data.w;
- //PRODUCTIVITY
- server.growthPerSec = mining_data.gPerSec;
- server.hackedPerSec = mining_data.hPerSec;
- //RAM USAGE considering each as a separate script thread (1.75GB for grow and weaken, 1.7GB for hack)
- server.growthRAM = 1.75 * mining_data.g;
- server.hackRAM = 1.7 * mining_data.h;
- server.weakenRAM = 1.75 * mining_data.w;
- server.totalRAM = 1.75 * mining_data.g + 1.75 * mining_data.w + 1.7 * mining_data.h;
- server.HackedPerSecondPerRAM = (mining_data.hPerHack == 0) ? 0 : mining_data.hPerSec / (1.75 * mining_data.g + 1.75 * mining_data.w + 1.7 * mining_data.h);
- }
- return server;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement