Simple Bot that uses math to choose the most profitable upgrade.
Wie es funktioniert
The bot takes the following steps.
- Checks cost and production growth of all the possible upgrades
- Calculates profitable ratio of each upgrade
- Sorts elements by ratio descending
- Chooses the first element
- Checks if you can purchase upgrade now, wenn nicht, it waits to collect money
- Checks if you can buy a new node in less than 30 Sekunden (you can customize this time), Wenn ja, it buys it
- Wiederholen…
Profitable ratio = Production growth / upgrade cost
Production growth = Production after upgrade / current production
This guide is based on my previous „Automation for Hacknet Nodes“.
Verwendung
Take the following steps.
- Run the terminal
- Typ ‚nano hacknet-bot.js‘
- Copy and paste the code below into this file
- Speichern Sie die Datei (Strg + S)
- Back to the terminal
- Typ ‚run hacknet-bot.js‘
/** @param {NS} ns **/ Asynchrone Funktion main exportieren(ns) { // helpers const getMoney = () => ns.getPlayer().Geld; const getProd = (Ebene, RAM, cores) => (Ebene * 1.5) * Math.pow(1.035, RAM - 1) * ((cores + 5) / 6); // your production multiplier const PROD_MULTIPLIER = ns.getHacknetMultipliers().Produktion; // maximum waiting time for collecting money for new node (default 30s) const WAITING_TIME = ns.args[0] || 30; während (WAHR) { const ratios = []; let hacknetProduction = 0; // loop through all nodes for (lass index = 0; Index < ns.hacknet.numNodes(); Index ++) { // get current node stats const { Ebene, RAM, cores, Produktion } = ns.hacknet.getNodeStats(Index); hacknetProduction += production; // get upgrades cost const levelUpgradeCost = ns.hacknet.getLevelUpgradeCost(Index); const ramUpgradeCost = ns.hacknet.getRamUpgradeCost(Index); const coreUpgradeCost = ns.hacknet.getCoreUpgradeCost(Index); // get prod. Wachstum / cost ratios const levelUpgradeRatio = ((getProd(Ebene + 1, RAM, cores) * PROD_MULTIPLIER) - Produktion) / levelUpgradeCost; const ramUpgradeRatio = ((getProd(Ebene, RAM * 2, cores) * PROD_MULTIPLIER) - Produktion) / ramUpgradeCost; const coreUpgradeRatio = ((getProd(Ebene, RAM, cores + 1) * PROD_MULTIPLIER) - Produktion) / coreUpgradeCost; // possible upgrades of current node const currentNodeUpgrades = [ {Verhältnis: levelUpgradeRatio, cost: levelUpgradeCost, nodeIndex: Index, Aktualisierung: "Ebene"}, {Verhältnis: ramUpgradeRatio, cost: ramUpgradeCost, nodeIndex: Index, Aktualisierung: "RAM"}, {Verhältnis: coreUpgradeRatio, cost: coreUpgradeCost, nodeIndex: Index, Aktualisierung: "Kern"} ]; // push current node upgrades to all upgrades ratios.push(...currentNodeUpgrades); } // get the most profitable upgrade const { cost, nodeIndex, Aktualisierung } = ratios.sort((A, B) => b.ratio - a.ratio)[0]; // wait until you have the money for upgrade while (getMoney() < cost) { warte auf ns.sleep(1); } // execute upgrade switch (Aktualisierung) { Fall "Ebene": await ns.hacknet.upgradeLevel(nodeIndex); brechen; Fall "RAM": await ns.hacknet.upgradeRam(nodeIndex); brechen; Fall "Kern": await ns.hacknet.upgradeCore(nodeIndex); brechen; Standard: weitermachen; } // check if you can purchase new node const purchaseNodeCost = ns.hacknet.getPurchaseNodeCost(); const missingMoneyForNewNode = purchaseNodeCost - getMoney(); Wenn (missingMoneyForNewNode > 0 && missingMoneyForNewNode < hacknetProduction * WAITING_TIME) { // if you need to wait for purchase node less than WAITING_TIME (in Sekunden) program waits to collect money while (getMoney() < purchaseNodeCost) { warte auf ns.sleep(1); } ns.hacknet.purchaseNode(); } // sleep 1ms to prevent crash because of infinite loop await ns.sleep(1); } }
You can customize the time of waiting for purchase node (by default 30s) by passing an additional script argument. Zum Beispiel:
run hacknet-bot.js 120
Das ist alles, was wir heute dafür teilen Bitburner Führung. Dieser Leitfaden wurde ursprünglich erstellt und geschrieben von syw1. Für den Fall, dass wir diesen Leitfaden nicht aktualisieren können, Sie können das neueste Update finden, indem Sie diesem folgen Verknüpfung.