Bitburner : automatisation pour les nœuds Hacknet

Automatisation complète pour les nœuds Hacknet qui recherchent la mise à niveau la plus rentable et la choisissent.

Comment ça marche

L'algorithme recherche le ratio le plus rentable.

Ratio Croissance de la production divisé par Coût de mise à niveau
Croissance de la production = Production après mise à niveau divisé par La production actuelle

je te recommande pour passer un plus grand temps d'itération de boucle (par exemple 100 000) ou laisser la valeur par défaut pour laisser les nœuds hacknet collecter plus d'argent afin qu'ils puissent comparer plus de mises à niveau au lieu de mettre constamment à jour la moins chère.

Utilisation

Pas à pas

  1. Ouvrir le terminal
  2. Tapez "nano hacknet-bot.ns" pour créer un fichier
  3. Effacez le fichier et collez le code ci-dessous
  4. Enregistrer le fichier
  5. Retournez au terminal
  6. Tapez "run hacknet-bot.ns" pour exécuter un script

Vous pouvez définir un temps de fréquence de boucle en passant un argument de script supplémentaire
par exemple "exécuter hacknet-bot.ns 10000"

Fréquence de boucle par défaut. est de 60 000 ms = 1 min.

Vous pouvez également copier le code de https://www.paste.org/121034.

Code

/** @param {NS} ns **/
export const main = async ns => {
	// helpers
	const getMoney = () => ns.getPlayer().money;
	const getProduction = (level, ram, cores) => (level * 1.5) * Math.pow(1.035, ram - 1) * ((cores + 5) / 6);
 
	// loop interval passed as a script parameter, default interval is 60 000ms
	const interval = ns.args[0] || 60000;
 
	// main loop
	while (true) {
		// loop through all hacknet nodes
		for (var index = 0; index < await ns.hacknet.numNodes(); index++) { // your current money const money = getMoney(); // your production multiplier from installed augmentations const prodMultiplier = await ns.getHacknetMultipliers().production; // get current node stats const nodeStats = await ns.hacknet.getNodeStats(index); const curRam = nodeStats.ram; const curLevel = nodeStats.level; const curCores = nodeStats.cores; const curProd = nodeStats.production; // get costs of upgrades const ramUpgradeCost = await ns.hacknet.getRamUpgradeCost(index); const levelUpgradeCost = await ns.hacknet.getLevelUpgradeCost(index); const coreUpgradeCost = await ns.hacknet.getCoreUpgradeCost(index); // check upgrades profitability and if you have enough money // UPGRADE RATIO = production growth after upgrade / current production const prodGrowthAfterLevelUpgrade = (getProduction(curLevel + 1, curRam, curCores) * prodMultiplier) - curProd; const levelUpgradeRatio = money >= await levelUpgradeCost 
				? prodGrowthAfterLevelUpgrade / await levelUpgradeCost
				: 0;
 
			const prodGrowthAfterRamUpgrade = (getProduction(curLevel, curRam * 2, curCores) * prodMultiplier) - curProd;
			const ramUpgradeRatio = money >= await ramUpgradeCost
				? prodGrowthAfterRamUpgrade / await ramUpgradeCost
				: 0;
 
			const prodGrowthAfterCoresUpgrade = (getProduction(curLevel, curRam, curCores + 1) * prodMultiplier) - curProd;
			const coresUpgradeRatio = money >= await coreUpgradeCost 
				? prodGrowthAfterCoresUpgrade / await coreUpgradeCost
				: 0;
 
			// check if you have enough money for any upgrade
			const ratios = [levelUpgradeRatio, ramUpgradeRatio, coresUpgradeRatio];
			if (ratios.every(ratio => ratio === 0)) {
				continue;
			}
 
			// find the most profitability upgrade
			const mostProfitUpgrade = Math.max(...ratios);
			const mostProfitUpgradeIndex = ratios.findIndex(ratio => ratio === mostProfitUpgrade);
 
			// execute the most profitability upgrade
			switch (mostProfitUpgradeIndex) {
				case 0:
					await ns.hacknet.upgradeLevel(index, 1);
					break;	
				case 1:
					await ns.hacknet.upgradeRam(index, 1);
					break;	
				case 2:
					await ns.hacknet.upgradeCore(index, 1);
					break;
				default:
					continue;
			}
		}
 
		// check if you can buy new node machine
		if (getMoney() > await ns.hacknet.getPurchaseNodeCost()) {
			await ns.hacknet.purchaseNode();
		}
		
		// sleep to prevent crash because of infinite loop
		await ns.sleep(interval);
	}
}

By syw1

Plus de guides :

1 réflexion sur « Bitburner : automatisation pour les nœuds Hacknet »

Laisser un commentaire

ArabicEnglishFrenchGermanItalianJapaneseKoreanPortugueseSpanish