6MBUKAG6VK6XXGRSER273IP2R35P3C5K3KOY4QVSZXEOYD3H4WRAC // // debugging function that produces an output by running the function it is debugging. as such, should not be used on impure functions. NOT WORKING PROPERLY, CAUSES INFINITE LOOPS DUE TO RECURSION.// const void_debug_pure = function() {// const boolean_on = true;// const array_arguments = Array.from(arguments);// if (boolean_on) {// const ns = array_arguments[1][0];// for (let integer_indices_0 = 0; integer_indices_0 < array_arguments[1].length; ++integer_indices_0) {// const string_argument_type = typeof(array_arguments[1][integer_indices_0]);// if (integer_indices_0 === 0) {// ns.tprint(`${new Date(Date.now()).toISOString()}: ${array_arguments[integer_indices_0].name}(`);// }// else {// if (integer_indices_0 < array_arguments[1].length - 1) {// ns.tprint(`${string_argument_type}: ${JSON.stringify(array_arguments[1][integer_indices_0])}, `);// }// if (integer_indices_0 === array_arguments[1].length - 1) {// ns.tprint(`${string_argument_type}: ${JSON.stringify(array_arguments[1][integer_indices_0])})`);// }// }// }// ns.tprint(`output: ${JSON.stringify(eval(array_arguments[0].name)(...array_arguments[1]))}`);// }// };
// // opens ports of a server using available object_exploits// const void_open_ports = function(ns, string_server_target) {// void_debug_impure(void_open_ports, Array.from(arguments));// const object_constants = object_get_constants(ns);// const object_exploits = object_constants.object_exploits;// for (const exploit in object_exploits) {// if (ns.fileExists(object_exploits[exploit].file, object_constants.string_host)) {// eval("ns." + object_exploits[exploit].function + "(\"" + string_server_target + "\")");// }// }// };
// // returns the amount of exploits present in the string_host// const integer_get_exploits_amount = function(ns) {// void_debug_pure(integer_get_exploits_amount, Array.from(arguments));// const object_constants = object_get_constants(ns);// const object_exploits = object_constants.object_exploits;// let integer_exploits_amount = 0;// for (const exploit in object_exploits) {// if (ns.fileExists(object_exploits[exploit].file, object_constants.string_host)) {// ++integer_exploits_amount;// }// }// return integer_exploits_amount;// };// // opens ports and nukes any unrooted servers if the player's hacking level is high enough to do so and the appropriate number of object_exploits are present// const void_open_ports_nuke = function(ns) {// void_debug_impure(void_open_ports_nuke, Array.from(arguments));// const array_servers_unrooted = array_get_servers_unrooted(ns);// for (let integer_indices_0 = 0; integer_indices_0 < array_servers_unrooted.length; ++integer_indices_0) {// const string_server_unrooted = array_servers_unrooted[integer_indices_0];// if (// (ns.getServerRequiredHackingLevel(string_server_unrooted) <= object_get_constants(ns).object_stats.hacking) &&// (ns.getServerNumPortsRequired(string_server_unrooted) <= integer_get_exploits_amount(ns))// ) {// void_open_ports(ns, string_server_unrooted);// ns.nuke(string_server_unrooted);// }// }// };
// // returns the sum of all free ram from all the servers you have root access to// const float_get_ram_free_total = function(ns) {// void_debug_pure(float_get_ram_free_total, Array.from(arguments));// const array_servers_rooted = array_get_servers_rooted(ns);// let float_free_ram_from_servers_rooted = 0.0;// for (let integer_indices_0 = 0; integer_indices_0 < array_servers_rooted.length; ++integer_indices_0) {// float_free_ram_from_servers_rooted += float_get_server_ram_free(ns, array_servers_rooted[integer_indices_0]);// }// return float_free_ram_from_servers_rooted;// };// // returns what percentage of ram_free_total the ram of a server is// const float_get_percentage_of_server_ram_free_from_ram_free_total = function(ns, string_server) {// void_debug_pure(float_get_percentage_of_server_ram_free_from_ram_free_total, Array.from(arguments));// return float_get_server_ram_free(ns, string_server) / float_get_ram_free_total(ns);// };
const integer_get_cycles_for_bisection_float_precision = function(ns, float_precision) {void_debug(integer_get_cycles_for_bisection_float_precision, Array.from(arguments));
const integer_get_cycles_for_bisection_precision = function(ns, float_precision) {void_debug(integer_get_cycles_for_bisection_precision, Array.from(arguments));
// returns optimum percentage to steal such that cash stolen is as high as float_cap and string_server_target's cash still able to be grown to 100% after one grow with the ram it has available by using a binary search algorithm
// this should return optimum percentage to steal such that cash stolen is as high as float_cap and string_server_target's cash still able to be grown to 100% after one grow with the ram it has remaining by using a binary search algorithm
for (let integer_indices_0 = 0; integer_indices_0 < integer_get_cycles_for_bisection_float_precision(ns, float_precision); ++integer_indices_0) {if (bool_is_ram_enough_for_growth_percentage(ns, float_server_used_ram_free, string_server_target, float_percentage_to_steal, float_server_target_security)) {
for (let integer_indices_0 = 0; integer_indices_0 < integer_get_cycles_for_bisection_precision(ns, float_precision); ++integer_indices_0) {if (bool_is_ram_enough_for_growth_percentage(ns, float_server_used_ram_free_halved, string_server_target, float_percentage_to_steal, float_server_target_security)) {
// if (!ns.fileExists(array_files[integer_indices_1], array_servers_rooted[integer_indices_0])) {ns.scp(array_files[integer_indices_1], string_source, array_servers_rooted[integer_indices_0]);// }
ns.scp(array_files[integer_indices_1], string_source, array_servers_rooted[integer_indices_0]);
const string_get_server_rooted_with_ram_biggest = function(ns) {void_debug(string_get_server_rooted_with_ram_biggest, Array.from(arguments));const array_servers_rooted_sorted_by_ram = array_get_servers_rooted_sorted_by_ram(ns);return array_servers_rooted_sorted_by_ram[array_servers_rooted_sorted_by_ram.length - 1];};const string_get_server_rooted_with_score_biggest = function(ns) {void_debug(string_get_server_rooted_with_score_biggest, Array.from(arguments));const array_servers_rooted_sorted_by_score = array_get_servers_rooted_sorted_by_score(ns);return array_servers_rooted_sorted_by_score[array_servers_rooted_sorted_by_score.length - 1];};
schedule_item.float_ram_cost = integer_threads_weaken * object_scripts.weaken.ram;schedule_item.float_server_used_ram_free_after = float_server_used_ram_free_current;schedule_item.float_server_target_security_after = float_server_target_security_current;schedule_item.float_server_target_security_delta = float_server_target_security_current - schedule_item.float_server_target_security_before;
schedule_item.float_ram_cost = integer_threads_grow * object_scripts.grow.ram;schedule_item.float_server_used_ram_free_after = float_server_used_ram_free_current;schedule_item.float_server_target_security_after = float_server_target_security_current;schedule_item.float_server_target_security_delta = float_server_target_security_current - schedule_item.float_server_target_security_before;schedule_item.float_server_target_cash_after = float_server_target_cash_current;schedule_item.float_server_target_cash_delta = float_server_target_cash_current - schedule_item.float_server_target_cash_before;
schedule_item.float_ram_cost = integer_threads_hack * object_scripts.hack.ram;schedule_item.float_server_used_ram_free_after = float_server_used_ram_free_current;schedule_item.float_server_target_security_after = float_server_target_security_current;schedule_item.float_server_target_security_delta = float_server_target_security_current - schedule_item.float_server_target_security_before;schedule_item.float_server_target_cash_after = float_server_target_cash_current;schedule_item.float_server_target_cash_delta = float_server_target_cash_current - schedule_item.float_server_target_cash_before;
Scripts for the game [Bitburner](https://github.com/danielyxie/bitburner).
### `main.js` (15.70 GB)* Buy and replace old servers whenever appropriate.* Try to exploit and root servers if possible.* Copy `weaken.js`, `grow.js` and `hack.js` scripts to other servers.* Make a schedule containing information about when, where and how many threads (among other information) each of the scripts should be executed with.* Execute the actions in the schedule.* Repeat.### `killall.js` (3.05 GB)* Kill all running scripts.### `lshw.js <"SERVER1" ...>` (2.45 GB)* Display information about one or more servers.
To try them out, simply save all the .js files to the "home" server (which needs to have at least 15.7 GB of free RAM), then enter `run main.js` in the terminal. If you don't have enough RAM on "home", you can also edit the `object_get_constants` function in `lib.js` such that the `string_host` property points to another server that you have rooted and which has >= 15.7 GB.
## InstallationSave all the `.js` files in this repository to the "home" server using the same filenames.## Usage```run main.js```or```run lshw.js "home" "foodnstuff"```