New Setup?
This commit is contained in:
29
Mizzajl/home/wip/Minimum_Path_Sum_in_a_Triangle.js
Normal file
29
Mizzajl/home/wip/Minimum_Path_Sum_in_a_Triangle.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
//8,5,1,1,2,6,7,2,5,4
|
||||
//const sContractData = ns.codingcontract.getData(sContract, sTarget);
|
||||
const sContractData = "8,5,1,1,2,6,7,2,5,4";
|
||||
/*
|
||||
8
|
||||
5,1
|
||||
1,2,6
|
||||
7,2,5,4
|
||||
*/
|
||||
//nArray[0[2]]
|
||||
const sArray = sContractData.split(',');
|
||||
ns.tprint(sArray);
|
||||
let nArray = [];
|
||||
//Number
|
||||
for (let i = 0; i < sArray.length; i++) {
|
||||
nArray[i] = Number(sArray[i]);
|
||||
}
|
||||
ns.tprint(nArray);
|
||||
|
||||
let nLayers = [];
|
||||
for (let l = 0; l < nArray.length; l++) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
108
Mizzajl/home/wip/RMbreach.js
Normal file
108
Mizzajl/home/wip/RMbreach.js
Normal file
@@ -0,0 +1,108 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
//args
|
||||
const sTarget = ns.args[0]; // target server
|
||||
|
||||
// declare objects
|
||||
const oHome = ns.getServer("home");
|
||||
//const oTarget = ns.getServer(sTarget);
|
||||
|
||||
//declare variables
|
||||
const sWeakenScript = "RMweaken.js";
|
||||
const sGrowScript = "RMgrow.js";
|
||||
const sBatch = "RMcontroller.js";
|
||||
|
||||
const nCores = oHome.cpuCores;
|
||||
let nSecurity = ns.getServerSecurityLevel(sTarget);
|
||||
const nMinSecurity = ns.getServerMinSecurityLevel(sTarget);
|
||||
let nMoney = ns.getServerMoneyAvailable(sTarget);
|
||||
const nMaxMoney = ns.getServerMaxMoney(sTarget);
|
||||
|
||||
const nWeakenSTR = ns.weakenAnalyze(1, nCores);
|
||||
let nWeakenThreads = Math.ceil((nSecurity - nMinSecurity) / nWeakenSTR);
|
||||
let nFreeRam = ns.getServerMaxRam("home") - ns.getServerUsedRam("home");
|
||||
ns.tail(ns.pid, oHome.hostname, sTarget);
|
||||
//ns.resizeTail(815, 395);
|
||||
//ns.moveTail(1925, 0);
|
||||
|
||||
// crack target
|
||||
//ns.run(sCrack, 1, sTarget);
|
||||
const nDelay = ns.getWeakenTime(sTarget);
|
||||
if (nWeakenThreads > 0 && nSecurity > nMinSecurity) {
|
||||
|
||||
|
||||
ns.tprint("current security is: " + nSecurity);
|
||||
ns.tprint("minimum security is: " + nMinSecurity);
|
||||
ns.tprint("threads needed for weaken: " + nWeakenThreads);
|
||||
ns.tprint(nWeakenThreads + " will reduce Security by " + ns.weakenAnalyze(nWeakenThreads, nCores));
|
||||
let nScriptRAM = ns.getScriptRam(sWeakenScript, "home");
|
||||
let nRequiredRAM = nScriptRAM * nWeakenThreads;
|
||||
ns.tprint(nWeakenThreads + " of " + sWeakenScript + " requires " + nRequiredRAM + " GB of RAM");
|
||||
ns.tprint("weakening will take " + (nDelay / 1000 / 60) + " minutes");
|
||||
|
||||
if (nFreeRam > nRequiredRAM) {
|
||||
ns.run(sWeakenScript, nWeakenThreads, sTarget);
|
||||
|
||||
//await ns.sleep(Math.ceil(nDelay));
|
||||
|
||||
nSecurity = ns.getServerSecurityLevel(sTarget);
|
||||
ns.tprint("Breach complete, security level is now at: " + nSecurity);
|
||||
|
||||
}
|
||||
else {
|
||||
ns.print("not enough RAM to run all threads at once, splitting into smaller chunks...");
|
||||
|
||||
|
||||
while (nSecurity > nMinSecurity) {
|
||||
//nWeakenThreads /= (1+(nRequiredRAM / nFreeRam));
|
||||
nMaxThreads = Math.min( );
|
||||
ns.print(Math.ceil(nRequiredRAM / nFreeRam));
|
||||
ns.print(nWeakenThreads);
|
||||
ns.print(nWeakenThreads * nScriptRAM);
|
||||
ns.run(sWeakenScript, Math.ceil(nWeakenThreads), sTarget);
|
||||
await ns.sleep(Math.ceil(nDelay));
|
||||
nSecurity = ns.getServerSecurityLevel(sTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
let nGrowMulti = 1;
|
||||
ns.print("nGrowMulti = " + nGrowMulti);
|
||||
let nGrowth = ns.growthAnalyze(sTarget, nGrowMulti, nCores);
|
||||
ns.print("nGrowth = " + nGrowth);
|
||||
*/
|
||||
|
||||
//ns.growthAnalyzeSecurity();
|
||||
|
||||
|
||||
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");
|
||||
let nGrowPID = ns.run(sGrowScript, Math.min([Math.ceil(nGrowThreadsNeeded)], [Math.ceil(nFreeRam / ns.getScriptRam(sGrowScript, "home"))]), sTarget);
|
||||
await ns.nextPortWrite(nGrowPID);
|
||||
await ns.sleep(1000);
|
||||
nMoney = ns.getServerMoneyAvailable(sTarget);
|
||||
}
|
||||
|
||||
await ns.sleep(Math.ceil(nDelay));
|
||||
|
||||
//run batch
|
||||
const nBatchPID = ns.run(sBatch, 1, sTarget);
|
||||
ns.tail(nBatchPID, "home", sBatch, 1, sTarget);
|
||||
ns.resizeTail(815, 395, nBatchPID);
|
||||
ns.moveTail(1925, 0, nBatchPID);
|
||||
|
||||
}
|
||||
166
Mizzajl/home/wip/RMcontroller.js
Normal file
166
Mizzajl/home/wip/RMcontroller.js
Normal file
@@ -0,0 +1,166 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
//Arguments
|
||||
const sTarget = ns.args[0]; // target server
|
||||
|
||||
ns.tail("RMcontroller.js", "home", sTarget);
|
||||
|
||||
//Settings
|
||||
const oHome = ns.getServer("home");
|
||||
const nCores = oHome.cpuCores;
|
||||
const sScript = ns.getScriptName();
|
||||
const sWeaken = "RMweaken.js";
|
||||
const sGrow = "RMgrow.js";
|
||||
const sHack = "RMhack.js";
|
||||
const nScriptRAM = ns.getScriptRam(sScript, "home");
|
||||
const nWeakenRAM = ns.getScriptRam(sWeaken, "home");
|
||||
const nGrowRAM = ns.getScriptRam(sGrow, "home");
|
||||
const nHackRAM = ns.getScriptRam(sHack, "home");
|
||||
const nHomeUsedRAM = ns.getServerUsedRam("home");
|
||||
const nHomeMaxRAM = ns.getServerMaxRam("home");
|
||||
let nHomeFreeRAM = nHomeMaxRAM - nHomeUsedRAM;
|
||||
|
||||
const nDelays = [0, 100, 200, 300];
|
||||
|
||||
|
||||
//abort script if sTarget is undefined
|
||||
if (sTarget === undefined) {
|
||||
ns.tprint("1st arg sTarget is undefined");
|
||||
return false;
|
||||
}
|
||||
|
||||
//target server info
|
||||
const nMinSecurity = ns.getServerMinSecurityLevel(sTarget);
|
||||
const nMaxMoney = ns.getServerMaxMoney(sTarget);
|
||||
|
||||
let nWeakenTime1 = ns.getWeakenTime(sTarget);
|
||||
let nWeakenTime2 = nWeakenTime1 + nDelays[3];
|
||||
let nGrowTime = nWeakenTime1 * 0.8;
|
||||
let nHackTime = nWeakenTime1 / 4;
|
||||
|
||||
//let nHackSecurityGain = ns.hackAnalyzeSecurity(1, sTarget);
|
||||
//let nHackSecurityGain = 0.002;
|
||||
//let nHackThreadsEstimate = Math.max(Math.floor(1 / nHackSecurityGain),1);
|
||||
//let nHackThreadsEstimate = 10;
|
||||
//ns.tprint("nHackSecurityGain = " + nHackSecurityGain);
|
||||
//ns.tprint("nHackThreadsEstimate = " + nHackThreadsEstimate);
|
||||
const nHackTotalRAM = nHackRAM * 25;
|
||||
|
||||
//let nGrowSecurityGain = ns.growthAnalyzeSecurity(1, sTarget, nCores);
|
||||
//let nGrowSecurityGain = 0.004;
|
||||
//let nGrowThreadsEstimate = Math.max(Math.floor(1 / nGrowSecurityGain),1);
|
||||
//ns.tprint("nGrowSecurityGain = " + nGrowSecurityGain);
|
||||
//ns.tprint("nGrowThreadsEstimate = " + nGrowThreadsEstimate);
|
||||
const nGrowTotalRAM = nGrowRAM * 12.5;
|
||||
|
||||
//let nWeakenSecurity = ns.weakenAnalyze(1, nCores);
|
||||
//let nWeakenSecurity = 0.05;
|
||||
//let nWeakenThreadsEstimate = Math.max(Math.ceil(1 / nWeakenSecurity),1);
|
||||
//ns.tprint("nWeakenSecurity = " + nWeakenSecurity);
|
||||
//ns.tprint("nWeakenThreadsEstimate = " + nWeakenThreadsEstimate);
|
||||
const nWeakenTotalRAM = nWeakenRAM * 1;
|
||||
|
||||
const nTotalRAM = nHackTotalRAM + nGrowTotalRAM + (nWeakenTotalRAM * 2)
|
||||
const nTotalBatches = Math.floor((nHomeFreeRAM - nScriptRAM) / nTotalRAM);
|
||||
|
||||
let nHackThreadsEstimate = nTotalBatches * 25;
|
||||
let nWeakenThreadsEstimate1 = nTotalBatches * 1;
|
||||
let nGrowThreadsEstimate = nTotalBatches * 12.5;
|
||||
let nWeakenThreadsEstimate2 = nTotalBatches * 1;
|
||||
|
||||
ns.tprint("RAM per Cycle = " + nTotalRAM);
|
||||
ns.tprint("how many batches can i run at the same time? = " + nTotalBatches);
|
||||
|
||||
//await ns.grow(server, { additionalMsec: nMsecDelay });
|
||||
let nGrowDelay = nWeakenTime1 - nGrowTime;
|
||||
let nHackDelay = nWeakenTime1 - nHackTime;
|
||||
|
||||
|
||||
const nCycleDuration = nWeakenTime2 + nDelays[3];
|
||||
ns.tprint("nCycleDuration = " + nCycleDuration);
|
||||
|
||||
const nBatchFrequency = Math.ceil(nCycleDuration / nTotalBatches);
|
||||
ns.tprint("nBatchFrequency = " + nBatchFrequency);
|
||||
|
||||
while (true) {
|
||||
|
||||
//server stats
|
||||
let nCurrentSecurity = ns.getServerSecurityLevel(sTarget);
|
||||
let nCurrentMoney = ns.getServerMoneyAvailable(sTarget);
|
||||
|
||||
//timestamp
|
||||
let currentDate = new Date();
|
||||
let nOffset;
|
||||
|
||||
ns.print("Cash: " + (Math.floor(nCurrentMoney * 1000) / 1000) + " / " + nMaxMoney);
|
||||
ns.print("Security: " + (Math.floor(nCurrentSecurity * 1000) / 1000) + " / " + nMinSecurity);
|
||||
|
||||
//Calculate estimate time of completion
|
||||
nOffset = ns.getWeakenTime(sTarget);
|
||||
let nSafeTime = nOffset + nDelays[3] + 1000;
|
||||
let nWeakTime = new Date(currentDate.getTime() + nSafeTime);
|
||||
let sWeakTime = nWeakTime.toLocaleTimeString('sw-SV'); //swedish time
|
||||
|
||||
//Print estimated time of completion
|
||||
ns.print("Weakening " + sTarget + " Estimated complete at " + sWeakTime);
|
||||
|
||||
//hack
|
||||
const nHackPID = ns.exec(sHack, "home", nHackThreadsEstimate, sTarget, false, nHackDelay + nDelays[0]);
|
||||
//ns.tail(nHackPID, "home", "home", nHackThreadsEstimate, sTarget, 0, nHackDelay + nDelays[0]);
|
||||
|
||||
//weaken 1
|
||||
const nWeakenPID1 = ns.exec(sWeaken, "home", nWeakenThreadsEstimate1, sTarget, false, nDelays[1]);
|
||||
//ns.tail(nWeakenPID, "home", "home", nWeakenThreadsEstimate, sTarget, 0, nDelays[1]);
|
||||
|
||||
//grow
|
||||
const nGrowPID = ns.exec(sGrow, "home", nGrowThreadsEstimate, sTarget, false, nGrowDelay + nDelays[2]);
|
||||
//ns.tail(nGrowPID, "home", "home", nGrowThreadsEstimate, sTarget, 0, nGrowDelay + nDelays[2]);
|
||||
|
||||
//weaken 2
|
||||
const nWeakenPID2 = ns.exec(sWeaken, "home", nWeakenThreadsEstimate2, sTarget, false, nDelays[3]);
|
||||
//ns.tail(nWeakenPID2, "home", "home", nWeakenThreadsEstimate, sTarget, 0, nDelays[3]);
|
||||
|
||||
//await ns.sleep(nSafeTime);
|
||||
|
||||
/*
|
||||
await ns.nextPortWrite(nHackPID);
|
||||
await ns.nextPortWrite(nWeakenPID1);
|
||||
await ns.nextPortWrite(nGrowPID);
|
||||
await ns.nextPortWrite(nWeakenPID2);
|
||||
|
||||
ns.print("nHackPeek = " + nHackPeek);
|
||||
ns.print("nWeaken1Peek = " + nWeaken1Peek);
|
||||
ns.print("nGrowPeek = " + nGrowPeek);
|
||||
ns.print("nWeaken2Peek = " + nWeaken2Peek);
|
||||
*/
|
||||
|
||||
|
||||
let nHackPeek = ns.peek(nHackPID);
|
||||
let nWeaken1Peek = ns.peek(nWeakenPID1);
|
||||
let nGrowPeek = ns.peek(nGrowPID);
|
||||
let nWeaken2Peek = ns.peek(nWeakenPID2);
|
||||
|
||||
|
||||
if (nHackPeek === true || nWeaken1Peek === true || nGrowPeek === true || nWeaken2Peek === true) {
|
||||
ns.print("some of the ports are already written to...");
|
||||
ns.print("nHackPeek = " + nHackPeek);
|
||||
ns.print("nWeaken1Peek = " + nWeaken1Peek);
|
||||
ns.print("nGrowPeek = " + nGrowPeek);
|
||||
ns.print("nWeaken2Peek = " + nWeaken2Peek);
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
ns.nextPortWrite(nHackPID),
|
||||
ns.nextPortWrite(nWeakenPID1),
|
||||
ns.nextPortWrite(nGrowPID),
|
||||
ns.nextPortWrite(nWeakenPID2)
|
||||
])
|
||||
|
||||
|
||||
ns.print("hack: " + nHackPID + " completed at " + ns.readPort(nHackPID));
|
||||
ns.print("weaken1: " + nWeakenPID1 + " completed at " + ns.readPort(nWeakenPID1));
|
||||
ns.print("grow: " + nGrowPID + " completed at " + ns.readPort(nGrowPID));
|
||||
ns.print("weaken2: " + nWeakenPID2 + " completed at " + ns.readPort(nWeakenPID2));
|
||||
await ns.sleep(100);
|
||||
}
|
||||
}
|
||||
52
Mizzajl/home/wip/pserv.js
Normal file
52
Mizzajl/home/wip/pserv.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
|
||||
let aPservers = ns.getPurchasedServers();
|
||||
ns.tprint("aPservers = " + aPservers);
|
||||
let nPservers = aPservers.length;
|
||||
ns.tprint("nPservers = " + nPservers);
|
||||
|
||||
let nCurrentRAM;
|
||||
let nLowestRAM = 2 ** 21;
|
||||
let nHighestRAM = 0;
|
||||
let sLowestPserv;
|
||||
let sHighestPserv;
|
||||
let nTotalPServRAM = 0;
|
||||
|
||||
|
||||
const oPservers = new Object();
|
||||
|
||||
|
||||
/*
|
||||
const oPservers = {
|
||||
pserv-01 : { name: "pserv-01" , ram: nRAM}
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
for (let i = 0; i < nPservers; i++) {
|
||||
nCurrentRAM = ns.getServerMaxRam(aPservers[i]);
|
||||
//ns.tprint("nTotalPServRAM = " + nTotalPServRAM + " + " + "nCurrentRAM = " + nCurrentRAM);
|
||||
nTotalPServRAM += nCurrentRAM;
|
||||
if (nCurrentRAM < nLowestRAM) {
|
||||
nLowestRAM = nCurrentRAM
|
||||
sLowestPserv = aPservers[i];
|
||||
}
|
||||
|
||||
if (nCurrentRAM > nHighestRAM) {
|
||||
nHighestRAM = nCurrentRAM
|
||||
sHighestPserv = aPservers[i];
|
||||
}
|
||||
}
|
||||
ns.tprint("sLowestPserv = " + sLowestPserv);
|
||||
ns.tprint("nLowestRAM = " + nLowestRAM);
|
||||
|
||||
ns.tprint("sHighestPserv = " + sHighestPserv);
|
||||
ns.tprint("nHighestRAM = " + nHighestRAM);
|
||||
|
||||
ns.tprint("nTotalPServRAM = " + nTotalPServRAM);
|
||||
|
||||
}
|
||||
24
Mizzajl/home/wip/scanFactionAugments.js
Normal file
24
Mizzajl/home/wip/scanFactionAugments.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
|
||||
let aFactions = ns.getPlayer().factions;
|
||||
ns.tprint("aFactions = " + aFactions);
|
||||
let aAugmentations;
|
||||
let sStats;
|
||||
|
||||
for (let f = 0; f < aFactions.length; f++) {
|
||||
//ns.tprint("f = " + f);
|
||||
//sFaction = ns.singularity.faction
|
||||
aAugmentations = ns.singularity.getAugmentationsFromFaction(aFactions[f]);
|
||||
ns.tprint("aAugmentations = " + aAugmentations);
|
||||
ns.tprint("----------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
for (let a = 0; a < aFactions.length; a++) {
|
||||
sStats = JSON.stringify(ns.singularity.getAugmentationStats(aAugmentations[a]));
|
||||
ns.tprint(aAugmentations[f] + "sStats = " + sStats);
|
||||
ns.tprint("----------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
16
Mizzajl/home/wip/test.js
Normal file
16
Mizzajl/home/wip/test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
|
||||
let oSettings = JSON.parse(ns.read("settings.txt"));
|
||||
// let variable = someJSON.missingKey || ""
|
||||
//let tempVar = oSettings.settings.missingKey || "";
|
||||
//ns.tprint(tempVar)
|
||||
|
||||
ns.tprint(oSettings);
|
||||
ns.tprint(JSON.stringify(oSettings));
|
||||
ns.tprint(oSettings.setting.autoUpgrades);
|
||||
|
||||
//let tempVar = oSettings.settings.missingKey || "";
|
||||
//ns.tprint(tempVar)
|
||||
|
||||
}
|
||||
41
Mizzajl/home/wip/testhackgrow.js
Normal file
41
Mizzajl/home/wip/testhackgrow.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
ns.tail();
|
||||
const sTarget = ns.args[0]; // run on this target instead of best
|
||||
const nHackThreads = ns.args[1] ? ns.args[1] : 1;
|
||||
|
||||
ns.disableLog("sleep");
|
||||
|
||||
ns.print("nHackThreads = " + nHackThreads);
|
||||
|
||||
//ns.tprint(ns.getHackingMultipliers());
|
||||
|
||||
let nHackAmountPercent = ns.hackAnalyze(sTarget) * nHackThreads;
|
||||
let nTargetMoney = ns.getServerMoneyAvailable(sTarget);
|
||||
let nHackAmount = nTargetMoney * nHackAmountPercent;
|
||||
ns.print("nHackAmountPercent = " + nHackAmountPercent);
|
||||
ns.print("nTargetMoney = " + nTargetMoney);
|
||||
ns.print("nHackAmount = " + nHackAmount);
|
||||
|
||||
let nGrowthThreads = ns.growthAnalyze(sTarget, 1 + nHackAmountPercent, 1);
|
||||
ns.print("nGrowthThreads = " + nGrowthThreads);
|
||||
let nGrowThreadsINT = Math.ceil(nGrowthThreads);
|
||||
ns.print("Hack() : Grow() Ratio = " + nHackThreads + ":" + nGrowThreadsINT);
|
||||
|
||||
|
||||
|
||||
//test hack() and grow()
|
||||
/*
|
||||
let nHackPID = ns.exec("RMhack.js", "home", nHackThreads, sTarget);
|
||||
ns.tail(nHackPID);
|
||||
let nGrowPID = ns.exec("RMgrow.js", "home", nGrowThreadsINT, sTarget);
|
||||
ns.tail(nGrowPID);
|
||||
ns.print("Wait for Hack and Grow...");
|
||||
while (ns.isRunning(nHackPID) || ns.isRunning(nGrowPID)) {
|
||||
await ns.sleep(1000);
|
||||
}
|
||||
ns.print("Wait complete");
|
||||
nTargetMoney = ns.getServerMoneyAvailable(sTarget);
|
||||
ns.print("nTargetMoney = " + nTargetMoney);
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user