Simple Bot that uses math to choose the most profitable upgrade.
How It Works
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, w przeciwnym razie, it waits to collect money
- Checks if you can buy a new node in less than 30 towary drugiej jakości (you can customize this time), w takim razie, it buys it
- Powtarzać…
Profitable ratio = Production growth / upgrade cost
Production growth = Production after upgrade / current production
This guide is based on my previous “Automation for Hacknet Nodes”.
Jak używać
Take the following steps.
- Run the terminal
- Type ‘nano hacknet-bot.js’
- Copy and paste the code below into this file
- Save the file (ctrl + S)
- Back to the terminal
- Type ‘run hacknet-bot.js’
/** @param {Ns} ns **/ Eksportuj funkcja asynchroniczna główna(ns) { // helpers const getMoney = () => ns.getPlayer().pieniądze; const getProd = (poziom, ram, cores) => (poziom * 1.5) * Math.pow(1.035, ram - 1) * ((cores + 5) / 6); // your production multiplier const PROD_MULTIPLIER = ns.getHacknetMultipliers().produkcja; // maximum waiting time for collecting money for new node (default 30s) const WAITING_TIME = ns.args[0] || 30; chwila (PRAWDA) { const ratios = []; let hacknetProduction = 0; // loop through all nodes for (let index = 0; index < ns.hacknet.numNodes(); index++) { // get current node stats const { poziom, ram, cores, produkcja } = 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. wzrost / cost ratios const levelUpgradeRatio = ((getProd(poziom + 1, ram, cores) * PROD_MULTIPLIER) - produkcja) / levelUpgradeCost; const ramUpgradeRatio = ((getProd(poziom, ram * 2, cores) * PROD_MULTIPLIER) - produkcja) / ramUpgradeCost; const coreUpgradeRatio = ((getProd(poziom, ram, cores + 1) * PROD_MULTIPLIER) - produkcja) / coreUpgradeCost; // possible upgrades of current node const currentNodeUpgrades = [ {stosunek: levelUpgradeRatio, koszt: levelUpgradeCost, nodeIndex: index, aktualizacja: "poziom"}, {stosunek: ramUpgradeRatio, koszt: ramUpgradeCost, nodeIndex: index, aktualizacja: "ram"}, {stosunek: coreUpgradeRatio, koszt: coreUpgradeCost, nodeIndex: index, aktualizacja: "rdzeń"} ]; // push current node upgrades to all upgrades ratios.push(...currentNodeUpgrades); } // get the most profitable upgrade const { koszt, nodeIndex, aktualizacja } = ratios.sort((A, B) => b.ratio - a.ratio)[0]; // wait until you have the money for upgrade while (getMoney() < koszt) { await ns.sleep(1); } // execute upgrade switch (aktualizacja) { sprawa "poziom": await ns.hacknet.upgradeLevel(nodeIndex); przerwa; sprawa "ram": await ns.hacknet.upgradeRam(nodeIndex); przerwa; sprawa "rdzeń": await ns.hacknet.upgradeCore(nodeIndex); przerwa; domyślny: Kontynuować; } // check if you can purchase new node const purchaseNodeCost = ns.hacknet.getPurchaseNodeCost(); const missingMoneyForNewNode = purchaseNodeCost - getMoney(); Jeśli (missingMoneyForNewNode > 0 && missingMoneyForNewNode < hacknetProduction * WAITING_TIME) { // if you need to wait for purchase node less than WAITING_TIME (w kilka sekund) program waits to collect money while (getMoney() < purchaseNodeCost) { await 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. Na przykład:
run hacknet-bot.js 120
To wszystko, co dzisiaj udostępniamy w tym celu Bitburnera przewodnik. Ten przewodnik został pierwotnie stworzony i napisany przez syw1. Na wypadek, gdybyśmy nie zaktualizowali tego przewodnika, możesz znaleźć najnowszą aktualizację, postępując zgodnie z tym połączyć.