Simple Bot that uses math to choose the most profitable upgrade.
Comment ça marche
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, sinon, it waits to collect money
- Checks if you can buy a new node in less than 30 secondes (you can customize this time), le cas échéant, it buys it
- Répéter…
Profitable ratio = Production growth / upgrade cost
Production growth = Production after upgrade / current production
This guide is based on my previous « Automation for Hacknet Nodes ».
Comment utiliser
Take the following steps.
- Run the terminal
- Taper ‘nano hacknet-bot.js’
- Copy and paste the code below into this file
- Enregistrez le fichier (ctrl + s)
- Back to the terminal
- Taper ‘run hacknet-bot.js’
/** @param {Ns} ns **/ export async function main(ns) { // helpers const getMoney = () => ns.getPlayer().argent; const getProd = (niveau, bélier, cores) => (niveau * 1.5) * Math.pow(1.035, bélier - 1) * ((cores + 5) / 6); // your production multiplier const PROD_MULTIPLIER = ns.getHacknetMultipliers().production; // maximum waiting time for collecting money for new node (default 30s) const WAITING_TIME = ns.args[0] || 30; alors que (vrai) { const ratios = []; let hacknetProduction = 0; // loop through all nodes for (let index = 0; indice < ns.hacknet.numNodes(); index++) { // get current node stats const { niveau, bélier, cores, production } = ns.hacknet.getNodeStats(indice); hacknetProduction += production; // get upgrades cost const levelUpgradeCost = ns.hacknet.getLevelUpgradeCost(indice); const ramUpgradeCost = ns.hacknet.getRamUpgradeCost(indice); const coreUpgradeCost = ns.hacknet.getCoreUpgradeCost(indice); // get prod. croissance / cost ratios const levelUpgradeRatio = ((getProd(niveau + 1, bélier, cores) * PROD_MULTIPLIER) - production) / levelUpgradeCost; const ramUpgradeRatio = ((getProd(niveau, bélier * 2, cores) * PROD_MULTIPLIER) - production) / ramUpgradeCost; const coreUpgradeRatio = ((getProd(niveau, bélier, cores + 1) * PROD_MULTIPLIER) - production) / coreUpgradeCost; // possible upgrades of current node const currentNodeUpgrades = [ {rapport: levelUpgradeRatio, coût: levelUpgradeCost, nodeIndex: indice, mise à niveau: "niveau"}, {rapport: ramUpgradeRatio, coût: ramUpgradeCost, nodeIndex: indice, mise à niveau: "bélier"}, {rapport: coreUpgradeRatio, coût: coreUpgradeCost, nodeIndex: indice, mise à niveau: "cœur"} ]; // push current node upgrades to all upgrades ratios.push(...currentNodeUpgrades); } // get the most profitable upgrade const { coût, nodeIndex, mise à niveau } = ratios.sort((un, b) => b.ratio - a.ratio)[0]; // wait until you have the money for upgrade while (getMoney() < coût) { attendre le ns(1); } // execute upgrade switch (mise à niveau) { cas "niveau": await ns.hacknet.upgradeLevel(nodeIndex); casser; cas "bélier": await ns.hacknet.upgradeRam(nodeIndex); casser; cas "cœur": await ns.hacknet.upgradeCore(nodeIndex); casser; défaut: continuer; } // 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) { attendre le ns(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. Par exemple:
run hacknet-bot.js 120
C'est tout ce que nous partageons aujourd'hui pour cela Brûleur de bits guide. Ce guide a été initialement créé et rédigé par syw1. Si nous ne parvenons pas à mettre à jour ce guide, vous pouvez trouver la dernière mise à jour en suivant ceci lien.