-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbe_gay.js
47 lines (42 loc) · 1.51 KB
/
be_gay.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
const crimes = [
"heist",
"assassination",
"kidnap",
"grand theft auto",
"homicide",
"larceny",
"mug someone",
"rob store",
"shoplift",
];
/** @param {import(".").NS } ns */export async function main(ns) {
// Disable the log
ns.disableLog("ALL");
ns.tail(); // Open a window to view the status of the script
let timeout = 250; // In ms - too low of a time will result in a lockout/hang
while (true) {
await ns.sleep(timeout); // Wait it out first
if (ns.isBusy()) continue;
/** Calculate the risk value of all crimes */ let choices = crimes.map((crime) => {
let crimeStats = ns.getCrimeStats(crime); // Let us look at the important bits
let crimeChance = ns.getCrimeChance(crime); // We need to calculate if its worth it
/** Using probabilty(odds) to calculate the "risk" to get the best reward
* Risk Value = Money Earned * Odds of Success(P(A) / ~P(A)) / Time taken
*
* Larger risk values indicate a better choice
*/ let crimeRiskValue =
(crimeStats.money * Math.log10(crimeChance / (1 - crimeChance + Number.EPSILON))) /
crimeStats.time;
return [crime, crimeRiskValue];
});
let bestCrime = choices.reduce((prev, current) => {
return prev[1] > current[1] ? prev : current;
});
ns.commitCrime(bestCrime[0]);
ns.print(
`Crime: ${bestCrime[0]} Risk Value: ${bestCrime[1].toPrecision(3)} Cash to Earn: \$${ns
.getCrimeStats(bestCrime[0])
.money.toPrecision(4)}`
);
}
}