-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhnet-full.js
92 lines (86 loc) · 2.84 KB
/
hnet-full.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import BasePlayer from "if.player";
/** @param {NS} ns */
export async function main(ns) {
let player = new BasePlayer(ns, "player");
let runtime = ns.args[0];
if (runtime) {
runtime *= 1000;
} else { runtime = 100000000000; }
const getProd = (level, ram, cores) => (level * 1.5) * Math.pow(1.035, ram - 1) * ((cores + 5) / 6);
let start_time = new Date().valueOf();
let time = new Date().valueOf();
ns.print(time)
while (time < start_time + runtime) {
time = new Date().valueOf();
if (!ns.hacknet.numNodes()) {
while (ns.getmoney < ns.hacknet.getPurchaseNodeCost()) {
ns.print("player.money < ns.hacknet.getPurchaseNodeCost()");
await ns.sleep(1);
}
ns.hacknet.purchaseNode();
}
let currentNodeStats = [];
const mults = ns.getHacknetMultipliers();
let nodeValue = getProd(10, 1, 1) * mults.production;
let nodeCost = ns.hacknet.getPurchaseNodeCost()
currentNodeStats.push({
value: nodeValue,
cost: nodeCost,
ratio: nodeValue/nodeCost,
type: "node"
});
for (let idx = 0; idx < ns.hacknet.numNodes(); idx++) {
let {level, ram, cores, production} = ns.hacknet.getNodeStats(idx);
let levelCost = ns.hacknet.getLevelUpgradeCost(idx, 1);
let ramCost = ns.hacknet.getRamUpgradeCost(idx, 1);
let coreCost = ns.hacknet.getCoreUpgradeCost(idx, 1);
let levelValue = getProd(level + 1, ram, cores) * ns.getHacknetMultipliers().production - production;
let ramValue = getProd(level, ram + 1, cores) * ns.getHacknetMultipliers().production - production;
let coreValue = getProd(level, ram, cores + 1) * ns.getHacknetMultipliers().production - production;
currentNodeStats.push({
value: levelValue,
cost: levelCost,
ratio: levelValue/levelCost,
index: idx,
type: "level"
},{
value: ramValue,
cost: ramCost,
ratio: ramValue/ramCost,
index: idx,
type: "ram"
},{
value: coreValue,
cost: coreCost,
ratio: coreValue/coreCost,
index: idx,
type: "core"
});
}
currentNodeStats.sort((a,b) => b.ratio - a.ratio);
let bestUpgrade = currentNodeStats[0];
while (player.money < bestUpgrade.cost) {
ns.print("INFO player.money < bestUpgrade.cost");
ns.print("INFO "+player.money+" < "+bestUpgrade.cost);
ns.print(bestUpgrade);
await ns.sleep(1);
}
switch(bestUpgrade.type) {
case "level":
ns.hacknet.upgradeLevel(bestUpgrade.index, 1);
break;
case "ram":
ns.hacknet.upgradeRam(bestUpgrade.index, 1);
break;
case "core":
ns.hacknet.upgradeCore(bestUpgrade.index, 1);
break;
case "node":
ns.hacknet.purchaseNode();
break;
}
ns.print("time < start_time + runtime");
ns.print(time+"<"+ start_time + runtime);
await ns.sleep(1);
}
}