-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunBatcher.ts
More file actions
45 lines (35 loc) · 1.18 KB
/
runBatcher.ts
File metadata and controls
45 lines (35 loc) · 1.18 KB
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
import type { NS } from '../NetscriptDefinitions';
import Manager from './manager';
import BatchingAlgorithm from './algorithms/BatchingAlgorithm';
import recursiveScan from '../helpers/recursiveScan';
import rootComputer from '../helpers/rootComputer';
// -=- Main Program -=-
export async function main(ns: NS) {
const targets = recursiveScan(ns, 10).filter((uuid) => {
return rootComputer(ns, uuid, false);
});
const manager = new Manager(targets, ns);
const algorithm = new BatchingAlgorithm(ns, manager, targets);
// ~ Disable logging for ns.sleep
ns.disableLog('ALL');
ns.enableLog('print');
// -=- Clean Up -=-
ns.atExit(() => {
manager.kill();
});
// -=- Main Code -=-
while (true) {
const newTargets = recursiveScan(ns, 10).filter((uuid) => {
return rootComputer(ns, uuid, false);
}).filter((uuid) => !targets.includes(uuid));
newTargets.forEach((uuid) => {
targets.push(uuid);
algorithm.addTarget(uuid);
ns.print(`New target: ${uuid}`);
});
if (!algorithm.isBatchInProgress()) {
await algorithm.runAction();
}
await (async () => { return new Promise((resolve) => setTimeout(resolve, 1000)) })()
}
}