From 7bb3a8169e80c7822267da0b569aef40708bf860 Mon Sep 17 00:00:00 2001 From: zeddrak <57454318+zeddrak@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:54:38 -0800 Subject: [PATCH 1/7] Comment Ytop fixes Sigh, my fingers are soo old and don't work right any more... :) Thanks for the info. --- src/Server/ServerHelpers.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index 7922290d2..b96d27351 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -71,8 +71,8 @@ export function numCycleForGrowth(server: Server, growth: number, p: IPlayer, co * with parameters that are the same (for compatibility), but functionality is slightly different. * This function can ONLY be used to calculate the threads needed for a given server in its current state, * and so wouldn't be appropriate to use for formulas.exe or ns.growthAnalyze (as those are meant to - * provide theoretical scenaarios, or inverse hack respectively). Players COULD use this function with a - * custom server object with the correct moneyAvailable and moneyMax amounts, combined with a multplier + * provide theoretical scenarios, or inverse hack respectively). Players COULD use this function with a + * custom server object with the correct moneyAvailable and moneyMax amounts, combined with a multiplier * correctly calculated to bring the server to a new moneyAvailable (ie, pasing in moneyAvailable 300 and x2 * when you want the number of threads required to grow that particular server from 300 to 600), and this * function would pass back the correct number of threads. But the key thing is that it doesn't just @@ -81,8 +81,8 @@ export function numCycleForGrowth(server: Server, growth: number, p: IPlayer, co * application, so another function with different parameters is provided for that case below this one. * Instead this function is meant to hand-off from the old numCycleForGrowth function to the new one * where used internally for pro-rating or the like. Where you have applied a grow and want to determine - * how many htreads were needed for THAT SPECIFIC grow case using a multiplier. - * Idealy, this function, and the original function above will be depreciated to use the methodology + * how many threads were needed for THAT SPECIFIC grow case using a multiplier. + * Ideally, this function, and the original function above will be depreciated to use the methodology * and inputs of the new function below this one. Even for internal cases (it's actually easier to do so). * @param server - Server being grown * @param growth - How much the server is being grown by, in DECIMAL form (e.g. 1.5 rather than 50) @@ -98,7 +98,7 @@ export function numCycleForGrowthTransition(server: Server, growth: number, p: I * (ie, how many threads to grow this server from $200 to $600 for example). Used primarily for a formulas (or possibly growthAnalyze) * type of application. It lets you "theorycraft" and easily ask what-if type questions. It's also the one that implements the * main thread calculation algorith, and so is the fuinction all helper functions should call. - * It protects the inputs (so putting in INFINITY for targetMoney will use moneyMax, putting in a nagitive for start will use 0, etc.) + * It protects the inputs (so putting in INFINITY for targetMoney will use moneyMax, putting in a negative for start will use 0, etc.) * @param server - Server being grown * @param targetMoney - How much you want the server grown TO (not by), for instance, to grow from 200 to 600, input 600 * @param startMoney - How much you are growing the server from, for instance, to grow from 200 to 600, input 200 From 28a32ed3a0e75687cd9d6507cb24f4574b1024b8 Mon Sep 17 00:00:00 2001 From: zeddrak <57454318+zeddrak@users.noreply.github.com> Date: Mon, 31 Jan 2022 19:56:02 -0800 Subject: [PATCH 2/7] Ytpo fix Missed one --- src/Server/ServerHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index b96d27351..e6aa97ab9 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -73,7 +73,7 @@ export function numCycleForGrowth(server: Server, growth: number, p: IPlayer, co * and so wouldn't be appropriate to use for formulas.exe or ns.growthAnalyze (as those are meant to * provide theoretical scenarios, or inverse hack respectively). Players COULD use this function with a * custom server object with the correct moneyAvailable and moneyMax amounts, combined with a multiplier - * correctly calculated to bring the server to a new moneyAvailable (ie, pasing in moneyAvailable 300 and x2 + * correctly calculated to bring the server to a new moneyAvailable (ie, passing in moneyAvailable 300 and x2 * when you want the number of threads required to grow that particular server from 300 to 600), and this * function would pass back the correct number of threads. But the key thing is that it doesn't just * inverse/undo a hack (since the amount hacked from/to matters, not just the multiplier). From 94bcd0484aeef336ef1d2d8129936328e6a08a97 Mon Sep 17 00:00:00 2001 From: zeddrak <57454318+zeddrak@users.noreply.github.com> Date: Mon, 31 Jan 2022 20:04:39 -0800 Subject: [PATCH 3/7] Small comment change had an "a the" and the point was redundant, so removed it --- src/Server/ServerHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index e6aa97ab9..f8635fa69 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -94,7 +94,7 @@ export function numCycleForGrowthTransition(server: Server, growth: number, p: I } /** - * This function calculates the number of threads needed to grow a server from one $amount to a the same or higher $amount + * This function calculates the number of threads needed to grow a server from one $amount to a higher $amount * (ie, how many threads to grow this server from $200 to $600 for example). Used primarily for a formulas (or possibly growthAnalyze) * type of application. It lets you "theorycraft" and easily ask what-if type questions. It's also the one that implements the * main thread calculation algorith, and so is the fuinction all helper functions should call. From 63e833317bab9ec287a862b9456c3656626882e7 Mon Sep 17 00:00:00 2001 From: zeddrak <57454318+zeddrak@users.noreply.github.com> Date: Mon, 31 Jan 2022 20:06:13 -0800 Subject: [PATCH 4/7] more otpys fuinction => function --- src/Server/ServerHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index f8635fa69..a16b6d1c8 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -97,7 +97,7 @@ export function numCycleForGrowthTransition(server: Server, growth: number, p: I * This function calculates the number of threads needed to grow a server from one $amount to a higher $amount * (ie, how many threads to grow this server from $200 to $600 for example). Used primarily for a formulas (or possibly growthAnalyze) * type of application. It lets you "theorycraft" and easily ask what-if type questions. It's also the one that implements the - * main thread calculation algorith, and so is the fuinction all helper functions should call. + * main thread calculation algorith, and so is the function all helper functions should call. * It protects the inputs (so putting in INFINITY for targetMoney will use moneyMax, putting in a negative for start will use 0, etc.) * @param server - Server being grown * @param targetMoney - How much you want the server grown TO (not by), for instance, to grow from 200 to 600, input 600 From 76cc1532a726d472e0584652c81e5f2fe785511b Mon Sep 17 00:00:00 2001 From: zeddrak <57454318+zeddrak@users.noreply.github.com> Date: Mon, 31 Jan 2022 20:15:55 -0800 Subject: [PATCH 5/7] Added note to numCycleForGrowthByHackAmt * NOTE: the prehackMoney parameter can be removed and server.moneyMax used in its place. The return value would then give a thread count * that would slowly grow the server more than it is hacked until reaching moneyMax where it would return the correct number of threads. --- src/Server/ServerHelpers.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index a16b6d1c8..2120bc23b 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -140,6 +140,8 @@ export function numCycleForGrowthCorrected(server: Server, targetMoney: number, * This function calculates the number of threads needed to grow a server based on a pre-hack money and hackAmt * (ie, if you're hacking a server with $1e6 moneyAvail for 60%, this function will tell you how many threads to regrow it * PROBABLY the best replacement for the current ns.growthAnalyze + * NOTE: prehackMoney can be removed as a parameter and server.moneyMax used in its place. The return value would then give a thread count + * that would slowly grow the server more than it is hacked until reaching moneyMax where it would return the correct number of threads. * @param server - Server being grown * @param hackAmt - the amount hacked (total, not per thread) - as a decimal (like 0.60 for hacking 60% of available money) * @param prehackMoney - how much money the server had before being hacked (like 200000 for hacking a server that had $200000 on it at time of hacking) From 5cc7a6a0a2bee08e2ecce3215b7599e783441b18 Mon Sep 17 00:00:00 2001 From: zeddrak <57454318+zeddrak@users.noreply.github.com> Date: Mon, 31 Jan 2022 20:41:42 -0800 Subject: [PATCH 6/7] added numCycleForGrowthByMultiplier (ie old growthAnalyze parameters) implemented numCycleForGrowthByMultiplier (fully compatible with old growthAnalyze - though still slightly wrong, it does so in a way that could be seen as beneficial and is compatible with existing scripts) Also some fixes to numCycleForGrowthByHackAmt (wrong parameter order) --- src/Server/ServerHelpers.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index 2120bc23b..2c05d2b9b 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -139,9 +139,7 @@ export function numCycleForGrowthCorrected(server: Server, targetMoney: number, /** * This function calculates the number of threads needed to grow a server based on a pre-hack money and hackAmt * (ie, if you're hacking a server with $1e6 moneyAvail for 60%, this function will tell you how many threads to regrow it - * PROBABLY the best replacement for the current ns.growthAnalyze - * NOTE: prehackMoney can be removed as a parameter and server.moneyMax used in its place. The return value would then give a thread count - * that would slowly grow the server more than it is hacked until reaching moneyMax where it would return the correct number of threads. + * A good replacement for the current ns.growthAnalyze if you want players to have more control/responsibility * @param server - Server being grown * @param hackAmt - the amount hacked (total, not per thread) - as a decimal (like 0.60 for hacking 60% of available money) * @param prehackMoney - how much money the server had before being hacked (like 200000 for hacking a server that had $200000 on it at time of hacking) @@ -149,11 +147,28 @@ export function numCycleForGrowthCorrected(server: Server, targetMoney: number, * @returns Number of "growth cycles" needed to reverse the described hack */ export function numCycleForGrowthByHackAmt(server: Server, hackAmt: number, prehackMoney: number, p: IPlayer, cores = 1): number{ - if (prehackMoney > server.moneyMax) { prehackMoney = server.moneyMax; } - const posthackAmt = Math.floor(prehackMoney * Math.min(1, Math.max(0, (1 - hackAmt)))); - return numCycleForGrowthCorrected(server, prehackMoney, posthackAmt, p, cores); + if (prehackMoney > server.moneyMax) prehackMoney = server.moneyMax; + const posthacMoney = Math.floor(prehackMoney * Math.min(1, Math.max(0, (1 - hackAmt)))); + return numCycleForGrowthCorrected(server, posthacMoney, prehackMoney, p, cores); } +/** + * This function calculates the number of threads needed to grow a server based on a multiplier (and assumes the hack was against a moneyMax'ed server) + * (ie, if you're hacking a server with for 60%, this function will tell you how many threads to regrow it if it were maxed when you hacked it) + * PROBABLY the best replacement for the current ns.growthAnalyze to maintain existing scripts + * @param server - Server being grown + * @param growth - How much the server is being grown by, as a multiple in DECIMAL form (e.g. 1.5 rather than 50). Infinity is acceptable. + * @param p - Reference to Player object + * @returns Number of "growth cycles" needed + */ +export function numCycleForGrowthByMultiplier(server: Server, growth: number, p: IPlayer, cores = 1): number{ + if (!(growth > 1.0)) growth = 1.0; + const posthacMoney = server.moneyMax; + const prehackMoney = server.moneyMax / growth; + return numCycleForGrowthCorrected(server, posthacMoney, prehackMoney, p, cores); +} + + //Applied server growth for a single server. Returns the percentage growth export function processSingleServerGrowth(server: Server, threads: number, p: IPlayer, cores = 1): number { let serverGrowth = calculateServerGrowth(server, threads, p, cores); From bfaecc644d91047db848e97b3ab2974e4348de2b Mon Sep 17 00:00:00 2001 From: zeddrak <57454318+zeddrak@users.noreply.github.com> Date: Tue, 1 Feb 2022 14:34:27 -0800 Subject: [PATCH 7/7] startMoney check should be >= moneyMax, not == Just realized that I checked for exactly equal (as would be likely when operating internally), but really, it should treat anything greater than or equal to as a zero growth scenario (just better protection from a wider range of potential issues) --- src/Server/ServerHelpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index 2c05d2b9b..610900415 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -106,7 +106,7 @@ export function numCycleForGrowthTransition(server: Server, growth: number, p: I * @returns Number of "growth cycles" needed */ export function numCycleForGrowthCorrected(server: Server, targetMoney: number, startMoney: number, p: IPlayer, cores = 1): number { - if (startMoney == server.moneyMax) { return 0; } //no growth possible, no threads needed + if (startMoney >= server.moneyMax) { return 0; } //no growth possible, no threads needed if (startMoney < 0) { startMoney = 0; } // servers "can't" have less than 0 dollars on them if (targetMoney > server.moneyMax) { targetMoney = server.moneyMax; } // can't grow a server to more than its moneyMax