Simple Bot that uses math to choose the most profitable upgrade.
Cómo funciona
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, si no, it waits to collect money
- Checks if you can buy a new node in less than 30 artículos de segunda clase (you can customize this time), en ese caso, it buys it
- Repetir…
Profitable ratio = Production growth / upgrade cost
Production growth = Production after upgrade / current production
This guide is based on my previous «Automation for Hacknet Nodes».
Cómo utilizar
Take the following steps.
- Run the terminal
- Type ‘nano hacknet-bot.js’
- Copy and paste the code below into this file
- guardar el archivo (ctrl + s)
- Back to the terminal
- Type ‘run hacknet-bot.js’
/** @param {Ns} ns **/ export async function main(ns) { // helpers const getMoney = () => ns.getPlayer().dinero; const getProd = (nivel, ram, cores) => (nivel * 1.5) * Math.pow(1.035, ram - 1) * ((cores + 5) / 6); // your production multiplier const PROD_MULTIPLIER = ns.getHacknetMultipliers().producción; // maximum waiting time for collecting money for new node (default 30s) const WAITING_TIME = ns.args[0] || 30; mientras (verdadero) { const ratios = []; let hacknetProduction = 0; // loop through all nodes for (let index = 0; índice < ns.hacknet.numNodes(); index++) { // get current node stats const { nivel, ram, cores, producción } = ns.hacknet.getNodeStats(índice); hacknetProduction += production; // get upgrades cost const levelUpgradeCost = ns.hacknet.getLevelUpgradeCost(índice); const ramUpgradeCost = ns.hacknet.getRamUpgradeCost(índice); const coreUpgradeCost = ns.hacknet.getCoreUpgradeCost(índice); // get prod. crecimiento / cost ratios const levelUpgradeRatio = ((getProd(nivel + 1, ram, cores) * PROD_MULTIPLIER) - producción) / levelUpgradeCost; const ramUpgradeRatio = ((getProd(nivel, ram * 2, cores) * PROD_MULTIPLIER) - producción) / ramUpgradeCost; const coreUpgradeRatio = ((getProd(nivel, ram, cores + 1) * PROD_MULTIPLIER) - producción) / coreUpgradeCost; // possible upgrades of current node const currentNodeUpgrades = [ {relación: levelUpgradeRatio, costo: levelUpgradeCost, nodeIndex: índice, mejora: "nivel"}, {relación: ramUpgradeRatio, costo: ramUpgradeCost, nodeIndex: índice, mejora: "ram"}, {relación: coreUpgradeRatio, costo: coreUpgradeCost, nodeIndex: índice, mejora: "centro"} ]; // push current node upgrades to all upgrades ratios.push(...currentNodeUpgrades); } // get the most profitable upgrade const { costo, nodeIndex, mejora } = ratios.sort((a, b) => b.ratio - a.ratio)[0]; // wait until you have the money for upgrade while (getMoney() < costo) { await ns.sleep(1); } // execute upgrade switch (mejora) { caso "nivel": await ns.hacknet.upgradeLevel(nodeIndex); romper; caso "ram": await ns.hacknet.upgradeRam(nodeIndex); romper; caso "centro": await ns.hacknet.upgradeCore(nodeIndex); romper; por defecto: continuar; } // check if you can purchase new node const purchaseNodeCost = ns.hacknet.getPurchaseNodeCost(); const missingMoneyForNewNode = purchaseNodeCost - getMoney(); si (missingMoneyForNewNode > 0 && missingMoneyForNewNode < hacknetProduction * WAITING_TIME) { // if you need to wait for purchase node less than WAITING_TIME (in seconds) 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. Por ejemplo:
run hacknet-bot.js 120
Eso es todo lo que estamos compartiendo hoy para este Quemador de bits guía. Esta guía fue originalmente creada y escrita por syw1. En caso de que no actualicemos esta guía, puede encontrar la última actualización siguiendo este enlace.