A collection of scripts for the game Bitburner broken into "levels" of understanding.
- Level 1: Very basic attempt which grows a server 20% of the time, always hacks, and always weakens, while
await-ing each weaken/hack/grow - Level 2: Starts to use batching to fire off a worker script for weaken/hack/grow
- Level 3: Uses batching to fire off worker scripts for weaken/hack/grow distributed to many servers simulataneously, and hacks any available unhacked server to distribute even more threads
- Level 4: Improves on level 3 by automating the target server to work on based on potential income per hour, and adds a monitoring script
My initial attempt at automating hacking, growing, and weakening a server.
Very basic attempt which grows a server 20% of the time, always hacks, and always weakens, while await-ing each weaken/hack/grow.
core.js: Commonly used functions for hacking, weakening, and growing servers
Using core.js, you can create a script to grow, hack, and weaken a server back to it's minimum security level easily:
import {hackAndWeaken} from 'core.js';
/** @param {NS} ns */
export async function main(ns) {
/* note: there is a better approach using batching,
* but I haven't learned how to do that yet */
while(true) {
await hackAndWeaken(ns, 'n00dles');
}
}- Each
nstask must be immediatelyawait-ed- Typical
Promiseconcurrency (i.e.:Promise.all(...)) cannot be used to fire off many async tasks at once, it violates the rules of the game
- Typical
My second attempt at automating hacking, growing, and weakening a server.
Starts to use batching to fire off a worker script for weaken/hack/grow.
orchestrator.js: Uses batching to concurrently grow and drain a serverworkGrow.js: Grows a serverworkHack.js: Hacks a serverworkWeak.js: Weakens a server
Using orchestrator.js, you can create a script to grow, hack, and weaken a server simultaneously while respecting RAM limits of the host:
import {orchestrate} from 'orchestrator.js';
/** @param {NS} ns */
export async function main(ns) {
while(true) {
await orchestrate(ns, 'n00dles');
}
}- home RAM gets eaten very quick by the
orchestrator
My third attempt at automating hacking, growing, and weakening a server.
Uses batching to fire off worker scripts for weaken/hack/grow distributed to many servers simulataneously. Also hacks any available unhacked server to distribute even more threads.
target-search.js: Uses batching to nuke any available server, then distributes hack/weaken/grow scripts to grow & drain a server in a distributed fashionworkGrow.js: Grows a server (same as level 2)workHack.js: Hacks a server (same as level 2)workWeak.js: Weakens a server (same as level 2)
Using target-search.js, you can create a script to nuke any available server, then distribute hack/weaken/grow scripts to grow & drain a server in a distributed fashion:
import {targetSearch} from 'target-search.js';
/** @param {NS} ns */
export async function main(ns) {
while(true) {
await targetSearch(ns, 'n00dles');
}
}- This approach works, but it would be better if the need to manually target servers was automated
My fourth attempt at automating hacking, growing, and weakening a server.
Improves on level 3 by automating the target server to work on based on potential income per hour, and adds a monitoring script.
find-servers.js: Finds all servers that can be connected to from the home noderanker.js: Ranks all servers that can be connected to from the home node by income per hourmonitor.js: Opens a new window that is constantly updated to show server stats and income per secondwork.js: Finds the best server by income per hour and distributes work on all servers that can be connected to from the home nodetarget-search.js: Uses batching to nuke any available server, then distributes hack/weaken/grow scripts to grow & drain a server in a distributed fashion (mostly the same as level 3)workGrow.js: Grows a server (same as level 2)workHack.js: Hacks a server (same as level 2)workWeak.js: Weakens a server (same as level 2)
Using work.js, you can work on the best server continually (in terms of income per hour) by running:
[home /]> run work.js
Using monitor.js, you can monitor any server by running:
[home /]> run monitor.js [server]
Using ranker.js, you can get the top 5 profitable server candidates by running:
[home /]> run ranker.js