Vollständige Automatisierung für Hacknet-Knoten, die nach dem rentabelsten Upgrade suchen und es auswählen.
So funktioniert's
Der Algorithmus sucht nach dem profitabelsten Verhältnis.
Ratio = Produktionswachstum geteilt durch Upgrade-Kosten
Produktionswachstum = Produktion nach Upgrade geteilt durch Aktuelle Produktion
Ich empfehle dir um eine größere Loop-Iterationszeit zu passieren (z. B. 100 000) oder die Standardeinstellung zu belassen, damit Hacknet-Knoten mehr Geld sammeln können, damit sie mehr Upgrades vergleichen können, anstatt ständig das billigste zu aktualisieren.
Anwendungsbereich
Schritt für Schritt
- Öffnen Sie das Terminal
- Geben Sie „nano hacknet-bot.ns“ ein, um eine Datei zu erstellen
- Löschen Sie die Datei und fügen Sie den Code unten dort ein
- Speicher die Datei
- Gehen Sie zurück zum Terminal
- Geben Sie „run hacknet-bot.ns“ ein, um ein Skript auszuführen
Sie können eine Schleifenfrequenzzeit definieren, indem Sie ein zusätzliches Skriptargument übergeben
zB „hacknet-bot.ns 10000 ausführen“
Standardschleifenfrequenz. ist 60 000 ms = 1 min.
Sie können den Code auch von kopieren https://www.paste.org/121034.
Code
/** @param {NS} ns **/ export const main = async ns => { // helpers const getMoney = () => ns.getPlayer().money; const getProduction = (level, ram, cores) => (level * 1.5) * Math.pow(1.035, ram - 1) * ((cores + 5) / 6); // loop interval passed as a script parameter, default interval is 60 000ms const interval = ns.args[0] || 60000; // main loop while (true) { // loop through all hacknet nodes for (var index = 0; index < await ns.hacknet.numNodes(); index++) { // your current money const money = getMoney(); // your production multiplier from installed augmentations const prodMultiplier = await ns.getHacknetMultipliers().production; // get current node stats const nodeStats = await ns.hacknet.getNodeStats(index); const curRam = nodeStats.ram; const curLevel = nodeStats.level; const curCores = nodeStats.cores; const curProd = nodeStats.production; // get costs of upgrades const ramUpgradeCost = await ns.hacknet.getRamUpgradeCost(index); const levelUpgradeCost = await ns.hacknet.getLevelUpgradeCost(index); const coreUpgradeCost = await ns.hacknet.getCoreUpgradeCost(index); // check upgrades profitability and if you have enough money // UPGRADE RATIO = production growth after upgrade / current production const prodGrowthAfterLevelUpgrade = (getProduction(curLevel + 1, curRam, curCores) * prodMultiplier) - curProd; const levelUpgradeRatio = money >= await levelUpgradeCost ? prodGrowthAfterLevelUpgrade / await levelUpgradeCost : 0; const prodGrowthAfterRamUpgrade = (getProduction(curLevel, curRam * 2, curCores) * prodMultiplier) - curProd; const ramUpgradeRatio = money >= await ramUpgradeCost ? prodGrowthAfterRamUpgrade / await ramUpgradeCost : 0; const prodGrowthAfterCoresUpgrade = (getProduction(curLevel, curRam, curCores + 1) * prodMultiplier) - curProd; const coresUpgradeRatio = money >= await coreUpgradeCost ? prodGrowthAfterCoresUpgrade / await coreUpgradeCost : 0; // check if you have enough money for any upgrade const ratios = [levelUpgradeRatio, ramUpgradeRatio, coresUpgradeRatio]; if (ratios.every(ratio => ratio === 0)) { continue; } // find the most profitability upgrade const mostProfitUpgrade = Math.max(...ratios); const mostProfitUpgradeIndex = ratios.findIndex(ratio => ratio === mostProfitUpgrade); // execute the most profitability upgrade switch (mostProfitUpgradeIndex) { case 0: await ns.hacknet.upgradeLevel(index, 1); break; case 1: await ns.hacknet.upgradeRam(index, 1); break; case 2: await ns.hacknet.upgradeCore(index, 1); break; default: continue; } } // check if you can buy new node machine if (getMoney() > await ns.hacknet.getPurchaseNodeCost()) { await ns.hacknet.purchaseNode(); } // sleep to prevent crash because of infinite loop await ns.sleep(interval); } }
By SYW1
Weitere Anleitungen:
- Bitburner: Frühes Hacknet Auto Management Script
- Bitburner: Combat-Gang-Management-Skript (vollautomatisch)
- Bitburner: So fügen Sie dem HUD (Heads-up-Display) benutzerdefinierte Statistiken hinzu
- Bitburner: Early Game Guide (Spoilerfrei)
- Bitburner: DevMenu-Leistungsleitfaden
Jesus .. Wenn du schon klauen und Codes posten willst – mach es wenigstens lesbar….
Das ist Mist.