Bitburner: أتمتة عقد Hacknet

أتمتة كاملة لعقد Hacknet التي تبحث عن الترقية الأكثر ربحية واختيارها.

كيف يعمل

الخوارزمية تبحث عن النسبة الأكثر ربحية.

نسبة نمو الإنتاج مقسوما على تكلفة الترقية
نمو الإنتاج = الإنتاج بعد الترقية مقسوما على الانتاج الحالي

أنا أوصيك لتمرير وقت أكبر لتكرار الحلقة (على سبيل المثال 100) أو ترك الإعداد الافتراضي للسماح لعقد الاختراق بجمع المزيد من الأموال حتى تتمكن من مقارنة المزيد من الترقيات بدلاً من ترقية أرخصها باستمرار.

الأستعمال

خطوة بخطوة

  1. افتح المحطة
  2. اكتب "nano hacknet-bot.ns" لإنشاء ملف
  3. امسح الملف والصق الرمز أدناه هناك
  4. حفظ الملف
  5. ارجع إلى المحطة
  6. اكتب “run hacknet-bot.ns” لتشغيل البرنامج النصي

يمكنك تحديد وقت تكرار الحلقة بتمرير وسيطة نصية إضافية
على سبيل المثال ، "قم بتشغيل hacknet-bot.ns 10000"

التكرار الافتراضي للحلقة. هو 60 مللي ثانية = 000 دقيقة.

يمكنك أيضًا نسخ الرمز من https://www.paste.org/121034.

رمز

/** @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

المزيد من الأدلة:

1 فكرت في "Bitburner: أتمتة عقد Hacknet"

اترك تعليق

ArabicEnglishFrenchGermanItalianJapaneseKoreanPortugueseSpanish