more work on the lowram scripts
This commit is contained in:
61
Mizzajl/home/lowram/Lowgrow.js
Normal file
61
Mizzajl/home/lowram/Lowgrow.js
Normal 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);
|
||||
|
||||
|
||||
}
|
||||
@@ -9,12 +9,6 @@ export async function main(ns) {
|
||||
const sWeakenScript = "RMweaken.js";
|
||||
const sServerListFile = "serverList.txt";
|
||||
|
||||
// Lowram settings
|
||||
const sBatchScript = "lowram/Lowhgw.js";
|
||||
const sPrepScript = "lowram/Lowprep.js";
|
||||
const sRunScript = "lowram/Lowrun.js";
|
||||
|
||||
|
||||
const nHackScriptRAM = 1.75;
|
||||
const nGrowScriptRAM = 1.7;
|
||||
const nWeakenScriptRAM = 1.75;
|
||||
@@ -78,7 +72,7 @@ export async function main(ns) {
|
||||
|
||||
nCheckRAM = nThisScriptRAM + (nTempHackThreads * nHackScriptRAM) + (nTempGrowThreadsINT * nGrowScriptRAM) + (nTempWeakenThreadsINT * nWeakenScriptRAM);
|
||||
ns.print("nCheckRAM = " + nCheckRAM);
|
||||
|
||||
|
||||
if (nCheckRAM < nMaxRAM) {
|
||||
nUsedRAM = nCheckRAM;
|
||||
nHackThreads = nTempHackThreads;
|
||||
|
||||
@@ -11,6 +11,7 @@ export async function main(ns) {
|
||||
const sBatchScript = "lowram/Lowhgw.js";
|
||||
const sPrepScript = "lowram/Lowprep.js";
|
||||
const sRunScript = "lowram/Lowrun.js";
|
||||
const sGrowScript = "lowram/Lowgrow.js";
|
||||
|
||||
//declare variables
|
||||
const sWeakenScript = "RMweaken.js";
|
||||
|
||||
@@ -7,6 +7,7 @@ export async function main(ns) {
|
||||
const sBatchScript = "lowram/Lowhgw.js";
|
||||
const sPrepScript = "lowram/Lowprep.js";
|
||||
const sRunScript = "lowram/Lowrun.js";
|
||||
const sGrowScript = "lowram/Lowgrow.js";
|
||||
|
||||
const nTargetMoney = ns.getServerMoneyAvailable(sTarget);
|
||||
const nTargetMaxMoney = ns.getServerMaxMoney(sTarget);
|
||||
@@ -16,17 +17,14 @@ export async function main(ns) {
|
||||
ns.print(sTarget + " Money = " + nTargetMoney.toLocaleString() + " / " + nTargetMaxMoney.toLocaleString());
|
||||
ns.print(sTarget + " Security = " + nTargetSecurity.toLocaleString() + " / " + nTargetMinSecurity.toLocaleString());
|
||||
|
||||
if ( nTargetSecurity > nTargetMinSecurity) {
|
||||
ns.killall();
|
||||
if (nTargetSecurity > nTargetMinSecurity + 1) {
|
||||
ns.spawn(sPrepScript, { threads: 1, spawnDelay: 0 }, sTarget);
|
||||
}
|
||||
else if (nTargetMoney < nTargetMaxMoney){
|
||||
ns.print("need to prep MONEY, running "+sRunScript);
|
||||
ns.killall();
|
||||
ns.spawn(sBatchScript, { threads: 1, spawnDelay: 0 }, sTarget);
|
||||
else if (nTargetMoney < nTargetMaxMoney) {
|
||||
ns.print("need to prep MONEY, running " + sGrowScript);
|
||||
ns.spawn(sGrowScript, { threads: 1, spawnDelay: 0 }, sTarget);
|
||||
}
|
||||
else {
|
||||
ns.killall();
|
||||
ns.spawn(sBatchScript, { threads: 1, spawnDelay: 0 }, sTarget);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user