more work on the lowram scripts

This commit is contained in:
2024-10-10 17:19:40 +02:00
parent 81b1675356
commit a63a9ca66f
15 changed files with 115 additions and 51 deletions

View File

@@ -0,0 +1,61 @@
/** @param {NS} ns */
export async function main(ns) {
ns.tail();
const sTarget = ns.args[0]; // target server
// Lowram settings
const sBatchScript = "lowram/Lowhgw.js";
const sPrepScript = "lowram/Lowprep.js";
const sRunScript = "lowram/Lowrun.js";
const sLowGrowScript = "lowram/Lowgrow.js";
const sGrowScript = "RMgrow.js";
const nThisScriptRAM = ns.getScriptRam(sLowGrowScript, "home");
let nMoney = ns.getServerMoneyAvailable(sTarget);
const nMaxMoney = ns.getServerMaxMoney(sTarget);
const startValue = nMoney; // First argument: starting value
const target = nMaxMoney; // Second argument: target value
let result = startValue; // Initialize result with the starting value
let n = 1;
// For loop that continues until the result exceeds or matches the target
for (; result < target; n++) {
result += 1; // Add 1 before multiplication
result *= n; // Multiply by the current step value
}
let nGrowThreadsNeeded = n * ns.growthAnalyze(sTarget, n, 1);
ns.print("nGrowThreadsNeeded = " + nGrowThreadsNeeded);
//while (nMoney < nMaxMoney) {
let nFreeRam = ns.getServerMaxRam("home") - ns.getServerUsedRam("home");
ns.print("nFreeRam = " + nFreeRam);
ns.print("needed ram = " + Math.ceil(nFreeRam / ns.getScriptRam(sGrowScript, "home")));
ns.print("needed ram? = " + ns.getScriptRam(sGrowScript, "home"));
if (nFreeRam >= (ns.getScriptRam(sGrowScript, "home") * nGrowThreadsNeeded)) {
let nGrowPID = ns.run(sGrowScript, Math.ceil(nGrowThreadsNeeded), sTarget);
await ns.nextPortWrite(nGrowPID);
await ns.sleep(1000);
nMoney = ns.getServerMoneyAvailable(sTarget);
}
else {
ns.print("Too smol");
let nGrowPID = ns.run(sGrowScript, Math.ceil((nFreeRam - nThisScriptRAM) / ns.getScriptRam(sGrowScript, "home")), sTarget);
await ns.nextPortWrite(nGrowPID);
await ns.sleep(1000);
nMoney = ns.getServerMoneyAvailable(sTarget);
}
//back to Lowrun
ns.spawn(sRunScript, { threads: 1, spawnDelay: 0 }, sTarget);
}