Simple Bot that uses math to choose the most profitable upgrade.
작동 방식
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, if not, it waits to collect money
- Checks if you can buy a new node in less than 30 초 (you can customize this time), 그렇다면, it buys it
- 반복하다…
Profitable ratio = Production growth / upgrade cost
Production growth = Production after upgrade / current production
This guide is based on my previous “Automation for Hacknet Nodes”.
사용방법
Take the following steps.
- Run the terminal
- Type ‘nano hacknet-bot.js’
- Copy and paste the code below into this file
- 파일을 저장하십시오 (ctrl + 에스)
- Back to the terminal
- Type ‘run hacknet-bot.js’
/** @param {NS} ns **/ 비동기 함수 메인 내보내기(ns) { // helpers const getMoney = () => ns.getPlayer().돈; const getProd = (수준, ram, 코어) => (수준 * 1.5) * Math.pow(1.035, ram - 1) * ((코어 + 5) / 6); // your production multiplier const PROD_MULTIPLIER = ns.getHacknetMultipliers().생산; // maximum waiting time for collecting money for new node (default 30s) const WAITING_TIME = ns.args[0] || 30; ~하는 동안 (진실) { const ratios = []; let hacknetProduction = 0; // loop through all nodes for (let index = 0; index < ns.hacknet.numNodes(); index++) { // get current node stats const { 수준, ram, 코어, 생산 } = 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. 성장 / cost ratios const levelUpgradeRatio = ((getProd(수준 + 1, ram, 코어) * PROD_MULTIPLIER) - 생산) / levelUpgradeCost; const ramUpgradeRatio = ((getProd(수준, ram * 2, 코어) * PROD_MULTIPLIER) - 생산) / ramUpgradeCost; const coreUpgradeRatio = ((getProd(수준, ram, 코어 + 1) * PROD_MULTIPLIER) - 생산) / coreUpgradeCost; // possible upgrades of current node const currentNodeUpgrades = [ {비율: levelUpgradeRatio, cost: levelUpgradeCost, nodeIndex: index, 치받이: "수준"}, {비율: ramUpgradeRatio, cost: ramUpgradeCost, nodeIndex: index, 치받이: "ram"}, {비율: coreUpgradeRatio, cost: coreUpgradeCost, nodeIndex: index, 치받이: "core"} ]; // push current node upgrades to all upgrades ratios.push(...currentNodeUpgrades); } // get the most profitable upgrade const { cost, nodeIndex, 치받이 } = ratios.sort((에이, 비) => b.ratio - a.ratio)[0]; // wait until you have the money for upgrade while (getMoney() < cost) { ns.sleep을 기다리세요(1); } // execute upgrade switch (치받이) { 사례 "수준": await ns.hacknet.upgradeLevel(nodeIndex); 부서지다; 사례 "ram": await ns.hacknet.upgradeRam(nodeIndex); 부서지다; 사례 "core": await ns.hacknet.upgradeCore(nodeIndex); 부서지다; 기본: 계속하다; } // check if you can purchase new node const purchaseNodeCost = ns.hacknet.getPurchaseNodeCost(); const missingMoneyForNewNode = purchaseNodeCost - getMoney(); 만약에 (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) { 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. 예를 들어:
run hacknet-bot.js 120