fixed the ram utilisation logic. added flags to `main.js` that can prevent the execution of helpers.
[?]
Apr 21, 2020, 2:54 PM
3NFCZ6IPQPUCWANJN5WMUHUCHEQN7U5HZXMHDKVC6V6HXA3FG5YQCDependencies
- [2]
SLSWBNYTadded ram utilisation logic to `ram.js` and `servers.js`. split and refactored redundant code into separate library files. - [3]
RWMZ7DVLsplit and refactor various logics. update "README.md". - [4]
YXH7ERRNfixed bug that prevented helper scripts running if the "home" server does not have RAM bigger than the rest of the rooted servers. - [5]
2BKHJI2Sinit - [6]
2LU5Y77Ofixed optimum percentage to steal calculator. - [7]
BZ6FC2BTadd `cp.js`. - [8]
NQ22FUSWadd more options to `main.js`. update `README.md`. - [9]
4ACCU75Nimprove and refactor scheduling logic. - [10]
6MBUKAG6remove unneeded functions and comments. update readme. - [11]
NC66CZ5Jrename certain variables that had the same names as ns functions to prevent the RAM checker from triggering. - [12]
VMXI7PS4added action cap. improved scoring system. fixed parts of security and cash predictors. made lshw loopable. - [*]
CJBGAILAadd optional `--target` parameter for `main.js`. update `README.md`.
Change contents
- edit in sbin/ram.js at line 15
await ns.sleep(float_period_check); - edit in sbin/ram.js at line 20
await ns.sleep(float_period_check); - replacement in lib/lib_ram.js at line 32
// returns the total free RAM from all the servers you have root access toconst float_get_network_ram_free = function (ns) {// returns the total RAM used from all the servers you have root access toconst float_get_network_ram_used = function (ns) { - replacement in lib/lib_ram.js at line 35
let float_network_ram_free = 0;let float_network_ram_used = 0; - replacement in lib/lib_ram.js at line 37
float_network_ram_free += float_get_server_ram_free(ns, array_servers_rooted[integer_indices_0]);float_network_ram_used += float_get_server_ram_used(ns, array_servers_rooted[integer_indices_0]); - replacement in lib/lib_ram.js at line 39
return float_network_ram_free;return float_network_ram_used; - replacement in lib/lib_ram.js at line 44
return float_get_network_ram_free(ns) / float_get_network_ram_total(ns);return float_get_network_ram_used(ns) / float_get_network_ram_total(ns); - replacement in bin/main.js at line 1
// main.js - 8.75GB - TODO: Separate logic that requires source files so that they are only ran when you have the required source file - need a cheap way to check if you have source file? Maybe make a cache script that saves runtime constants like max money of servers to a cache file to potentially reduce RAM usage further. Maybe add functionality that allows on-the-fly hot loading of settings from a file.// main.js - 8.85GB - TODO: Separate logic that requires source files so that they are only ran when you have the required source file - need a cheap way to check if you have source file? Maybe make a cache script that saves runtime constants like max money of servers to a cache file to potentially reduce RAM usage further. Maybe add functionality that allows on-the-fly hot loading of settings from a file. Possibly split the helper script execution management to a different script? - edit in bin/main.js at line 38[2.10628][14.2359]
// helper scriptsconst string_helper_file_ram = "ram.js";const integer_helper_threads_ram = 1;const array_helper_arguments_ram = [float_period_check_seconds, float_ram_utilisation_threshold];const string_helper_file_servers = "servers.js";const integer_helper_threads_servers = 1;const array_helper_arguments_servers = [float_period_check_seconds, string_servers_bought_name, float_ram_utilisation_threshold]; - edit in bin/main.js at line 47[14.2360][14.2360]
const string_helper_file_botnet = "botnet.js";const integer_helper_threads_botnet = 1;const array_helper_arguments_botnet = [float_period_check_seconds];let array_helpers = [{file: string_helper_file_ram,threads: integer_helper_threads_ram,args: array_helper_arguments_ram},{file: string_helper_file_servers,threads: integer_helper_threads_servers,args: array_helper_arguments_servers},{file: string_helper_file_botnet,threads: integer_helper_threads_botnet,args: [array_helper_arguments_botnet]}]; - edit in bin/main.js at line 70[14.2382][3.1989]
// returns the index of the scripts array which matches the filename inputconst integer_get_index_of_file = function(array_scripts, string_file) {for (let integer_indices_0 = 0; integer_indices_0 < array_scripts.length; ++integer_indices_0) {const object_script = array_scripts[integer_indices_0];const string_script_file = object_script.file;if (string_script_file === string_file) {return integer_indices_0;}}}; - edit in bin/main.js at line 90
// flagscase "-a":// fall-throughcase "--no-ram":array_arguments.splice(0, 1);array_helpers.splice(integer_get_index_of_file(array_helpers, string_helper_file_ram), 1);break;case "-e":// fall-throughcase "--no-servers":array_arguments.splice(0, 1);array_helpers.splice(integer_get_index_of_file(array_helpers, string_helper_file_servers), 1);break;case "-b":// fall-throughcase "--no-botnet":array_arguments.splice(0, 1);array_helpers.splice(integer_get_index_of_file(array_helpers, string_helper_file_botnet), 1);break;// options - replacement in bin/main.js at line 167[3.11722]→[3.3627:3733](∅→∅),[3.3733]→[2.10819:10838](∅→∅),[2.10838]→[3.3752:3773](∅→∅),[3.3752]→[3.3752:3773](∅→∅),[3.3773]→[2.10839:10921](∅→∅),[2.10921]→[3.3822:3864](∅→∅),[3.3822]→[3.3822:3864](∅→∅),[3.3864]→[2.10922:10939](∅→∅),[2.10939]→[3.3881:3899](∅→∅),[3.3881]→[3.3881:3899](∅→∅),[3.3899]→[2.10940:11047](∅→∅),[2.11047]→[3.3973:4152](∅→∅),[3.3973]→[3.3973:4152](∅→∅)
const array_scripts = [// // uncomment if you have source-file 4// {// file: "ram.js",// ram: 6.6,// threads: 1,// arguments: [float_period_check_seconds, float_ram_utilisation_threshold]// },{file: "servers.js",ram: 8.85,threads: 1,arguments: [float_period_check_seconds, string_servers_bought_name, float_ram_utilisation_threshold]},{file: "botnet.js",ram: 2.15,threads: 1,arguments: [float_period_check_seconds]}];await void_script_executor(ns, array_scripts);await void_script_executor(ns, array_helpers); - replacement in bin/main.js at line 343[3.7256]→[3.7256:7278](∅→∅),[3.7278]→[3.1988:2018](∅→∅),[3.2018]→[3.7294:7321](∅→∅),[3.7294]→[3.7294:7321](∅→∅),[3.7321]→[3.2019:2037](∅→∅),[3.2037]→[3.7415:7424](∅→∅),[3.7415]→[3.7415:7424](∅→∅),[3.7424]→[3.2038:2066](∅→∅),[3.2066]→[3.7438:7463](∅→∅),[3.7438]→[3.7438:7463](∅→∅),[3.7463]→[3.2067:2085](∅→∅),[3.2085]→[3.7555:7564](∅→∅),[3.7555]→[3.7555:7564](∅→∅),[3.7564]→[3.2086:2114](∅→∅),[3.2114]→[3.7578:7603](∅→∅),[3.7578]→[3.7578:7603](∅→∅),[3.7603]→[3.2115:2132](∅→∅),[3.2132]→[3.7694:7702](∅→∅),[3.7694]→[3.7694:7702](∅→∅),[3.7702]→[3.4316:4322](∅→∅)
object_scripts: {object_weaken_script: {file: "weaken.js",ram: 1.75},object_grow_script: {file: "grow.js",ram: 1.75},object_hack_script: {file: "hack.js",ram: 1.7}}array_workers: ["weaken.js", "grow.js", "hack.js"] - replacement in bin/main.js at line 383
const float_ram = object_script.ram;const float_ram = ns.getScriptRam(string_file); - replacement in bin/main.js at line 385
const array_arguments = object_script.arguments;const array_arguments = object_script.args; - replacement in bin/main.js at line 396
} catch (error) {}catch (error) { - replacement in bin/main.js at line 453
const integer_threads_available = Math.trunc(float_server_used_ram_free / object_get_constants(ns).object_scripts.object_weaken_script.ram);const string_weaken = object_get_constants(ns).array_workers[0];const integer_threads_available = Math.trunc(float_server_used_ram_free / ns.getScriptRam(string_weaken)); - replacement in bin/main.js at line 503
const integer_threads_available = Math.trunc(float_server_used_ram_free / object_get_constants(ns).object_scripts.object_grow_script.ram);const string_grow = object_get_constants(ns).array_workers[1];const integer_threads_available = Math.trunc(float_server_used_ram_free / ns.getScriptRam(string_grow)); - replacement in bin/main.js at line 537
const integer_threads_available = Math.trunc(float_server_used_ram_free / object_get_constants(ns).object_scripts.object_hack_script.ram);const string_hack = object_get_constants(ns).array_workers[2];const integer_threads_available = Math.trunc(float_server_used_ram_free / ns.getScriptRam(string_hack)); - edit in bin/main.js at line 550
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - replacement in bin/main.js at line 564
const object_scripts = object_get_constants(ns).object_scripts;const string_weaken = object_get_constants(ns).array_workers[0];const string_grow = object_get_constants(ns).array_workers[1]; - replacement in bin/main.js at line 578
const float_ram_required = (integer_threads_required_for_weaken_minimum_security_after_hack * object_scripts.object_weaken_script.ram) + (integer_threads_required_for_cash_grow_after_percentage_stolen * object_scripts.object_grow_script.ram) + (integer_threads_required_for_weaken_minimum_security_after_grow * object_scripts.object_weaken_script.ram);const float_ram_required = (integer_threads_required_for_weaken_minimum_security_after_hack * ns.getScriptRam(string_weaken)) + (integer_threads_required_for_cash_grow_after_percentage_stolen * ns.getScriptRam(string_weaken)) + (integer_threads_required_for_weaken_minimum_security_after_grow * ns.getScriptRam(string_grow)); - replacement in bin/main.js at line 716
const object_constants = object_get_constants(ns);const object_scripts = object_constants.object_scripts;const array_workers = object_get_constants(ns).array_workers;const string_weaken = array_workers[0];const string_grow = array_workers[1];const string_hack = array_workers[2]; - replacement in bin/main.js at line 769
if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, object_scripts.object_weaken_script.ram, 1)) {if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, ns.getScriptRam(string_weaken), 1)) { - replacement in bin/main.js at line 777
float_server_used_ram_free_current -= integer_threads_weaken * object_scripts.object_weaken_script.ram;float_server_used_ram_free_current -= integer_threads_weaken * ns.getScriptRam(string_weaken); - replacement in bin/main.js at line 802
if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, object_scripts.object_grow_script.ram, 1)) {if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, ns.getScriptRam(string_grow), 1)) { - replacement in bin/main.js at line 814
float_server_used_ram_free_current -= integer_threads_grow * object_scripts.object_grow_script.ram;float_server_used_ram_free_current -= integer_threads_grow * ns.getScriptRam(string_grow); - replacement in bin/main.js at line 842
if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, object_scripts.object_hack_script.ram, 1)) {if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, ns.getScriptRam(string_hack), 1)) { - replacement in bin/main.js at line 850
float_server_used_ram_free_current -= integer_threads_hack * object_scripts.object_hack_script.ram;float_server_used_ram_free_current -= integer_threads_hack * ns.getScriptRam(string_hack); - edit in bin/main.js at line 908
const array_workers = object_get_constants(ns).array_workers; - replacement in bin/main.js at line 919
string_script = object_get_constants(ns).object_scripts.object_weaken_script.file;string_script = array_workers[0]; - replacement in bin/main.js at line 923
string_script = object_get_constants(ns).object_scripts.object_grow_script.file;string_script = array_workers[1]; - replacement in bin/main.js at line 927
string_script = object_get_constants(ns).object_scripts.object_hack_script.file;string_script = array_workers[2]; - replacement in bin/main.js at line 937[3.8123]→[3.42160:42466](∅→∅),[3.42160]→[3.42160:42466](∅→∅),[3.42466]→[3.8124:8160](∅→∅),[3.8160]→[3.43083:43132](∅→∅),[3.43083]→[3.43083:43132](∅→∅),[3.43132]→[3.4068:4201](∅→∅),[3.4201]→[3.8161:8185](∅→∅),[3.8185]→[3.43259:44337](∅→∅),[3.43259]→[3.43259:44337](∅→∅),[3.44337]→[3.3795167:3795169](∅→∅),[3.3795167]→[3.3795167:3795169](∅→∅)
const object_constants = object_get_constants(ns);const object_scripts = object_constants.object_scripts;let string_server_target = string_server_target_argument;if (string_server_target_argument === "") {string_server_target = string_get_server_rooted_hackable_with_score_biggest(ns);}// copy scripts to rooted serversvoid_copy_files_to_string_servers_rooted(ns, [object_scripts.object_weaken_script.file,object_scripts.object_grow_script.file,object_scripts.object_hack_script.file], ns.getHostname());// prepare the target if necessarywhile (true) {if (ns.getServerSecurityLevel(string_server_target) === ns.getServerMinSecurityLevel(string_server_target) &&ns.getServerMoneyAvailable(string_server_target) === ns.getServerMaxMoney(string_server_target)) {break;}const array_schedule_prepare = array_make_schedule(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target, string_job_decider_prepare);if (array_schedule_prepare.length > 0) {await void_schedule_runner(ns, array_schedule_prepare);await ns.sleep(array_schedule_prepare[array_schedule_prepare.length - 1].integer_time_job_finishes_seconds * 1000);}}// make and run actual hacking scheduleconst array_schedule = array_make_schedule(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target, string_job_decider);await void_schedule_runner(ns, array_schedule);return array_schedule[array_schedule.length - 1].integer_time_job_finishes_seconds * 1000;};[3.8123]================================};<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - replacement in README.md at line 10
### "main.js" (8.75 [+6.6] [+8.85] [+2.2] GB)### "main.js" (8.85 [+6.6] [+8.85] [+2.2] GB) - replacement in README.md at line 21
`run main.js [OPTIONS]``run main.js [OPTIONS] [FLAGS]` - edit in README.md at line 56
#### FLAGS`-a, --no-ram`* Prevents the "ram.js" script from being started which is responsible for upgrading the RAM of the "home" server.`-b, --no-botnet`* Prevents the "botnet.js" script from being started which is responsible for rooting servers in the network.`-e, --no-servers`* Prevents the "servers.js" script from being started which is responsible for the purchasing and replacement of servers. - replacement in README.md at line 74
`run main.js --job-cap 4000 -i "harakiri-sushi" -r 0.7 -s 0.5``run main.js --job-cap 4000 -i "harakiri-sushi" -r 0.7 -s 0.5 -a --no-botnet` - replacement in README.md at line 76
* Runs the script with up to 4000 jobs, targetting "harakiri-sushi", only upgrading/replacing RAM and servers when at least 0.7 of your network's total RAM is being used, and stealing only up to 50% of harakiri-sushi's cash per "hack.js" job that finishes executing, whilst the remaining variables are set to defaults.* Runs the script with up to 4000 jobs, targetting "harakiri-sushi", only upgrading/replacing servers when at least 0.7 of your network's total RAM is being used, and stealing only up to 50% of harakiri-sushi's cash per "hack.js" job that finishes executing, whilst the remaining variables are set to defaults. The "ram.js" and "botnet.js" helper scripts are also prevented from starting.