fixed the ram utilisation logic. added flags to `main.js` that can prevent the execution of helpers.

[?]
Apr 21, 2020, 2:54 PM
3NFCZ6IPQPUCWANJN5WMUHUCHEQN7U5HZXMHDKVC6V6HXA3FG5YQC

Dependencies

  • [2] SLSWBNYT added ram utilisation logic to `ram.js` and `servers.js`. split and refactored redundant code into separate library files.
  • [3] RWMZ7DVL split and refactor various logics. update "README.md".
  • [4] YXH7ERRN fixed bug that prevented helper scripts running if the "home" server does not have RAM bigger than the rest of the rooted servers.
  • [5] 2BKHJI2S init
  • [6] 2LU5Y77O fixed optimum percentage to steal calculator.
  • [7] BZ6FC2BT add `cp.js`.
  • [8] NQ22FUSW add more options to `main.js`. update `README.md`.
  • [9] 4ACCU75N improve and refactor scheduling logic.
  • [10] 6MBUKAG6 remove unneeded functions and comments. update readme.
  • [11] NC66CZ5J rename certain variables that had the same names as ns functions to prevent the RAM checker from triggering.
  • [12] VMXI7PS4 added action cap. improved scoring system. fixed parts of security and cash predictors. made lshw loopable.
  • [*] CJBGAILA add optional `--target` parameter for `main.js`. update `README.md`.

Change contents

  • edit in sbin/ram.js at line 15
    [2.8213]
    [2.8213]
    await ns.sleep(float_period_check);
  • edit in sbin/ram.js at line 20
    [2.8287]
    [2.8287]
    await ns.sleep(float_period_check);
  • replacement in lib/lib_ram.js at line 32
    [3.3723849][3.3723849:3723976]()
    // returns the total free RAM from all the servers you have root access to
    const float_get_network_ram_free = function (ns) {
    [3.3723849]
    [3.3723976]
    // returns the total RAM used from all the servers you have root access to
    const float_get_network_ram_used = function (ns) {
  • replacement in lib/lib_ram.js at line 35
    [3.3724037][3.3724037:3724071]()
    let float_network_ram_free = 0;
    [3.3724037]
    [3.3724071]
    let float_network_ram_used = 0;
  • replacement in lib/lib_ram.js at line 37
    [3.3724177][3.3724177:3724279]()
    float_network_ram_free += float_get_server_ram_free(ns, array_servers_rooted[integer_indices_0]);
    [3.3724177]
    [3.3724279]
    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
    [3.3724283][3.3724283:3724316]()
    return float_network_ram_free;
    [3.3724283]
    [3.3724316]
    return float_network_ram_used;
  • replacement in lib/lib_ram.js at line 44
    [3.3724444][3.3724444:3724519]()
    return float_get_network_ram_free(ns) / float_get_network_ram_total(ns);
    [3.3724444]
    [3.3724519]
    return float_get_network_ram_used(ns) / float_get_network_ram_total(ns);
  • replacement in bin/main.js at line 1
    [3.3793719][3.1578:1988]()
    // 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.
    [3.3793719]
    [2.10320]
    // 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 scripts
    const 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 input
    const 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
    [3.2344]
    [3.2344]
    // flags
    case "-a":
    // fall-through
    case "--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-through
    case "--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-through
    case "--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);
    [3.11722]
    [3.3794389]
    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
    }
    }
    [3.7256]
    [3.7801]
    array_workers: ["weaken.js", "grow.js", "hack.js"]
  • replacement in bin/main.js at line 383
    [3.6543][3.6543:6584]()
    const float_ram = object_script.ram;
    [3.6543]
    [3.6584]
    const float_ram = ns.getScriptRam(string_file);
  • replacement in bin/main.js at line 385
    [3.6635][3.6635:6688]()
    const array_arguments = object_script.arguments;
    [3.6635]
    [3.6688]
    const array_arguments = object_script.args;
  • replacement in bin/main.js at line 396
    [3.7422][3.7422:7450]()
    } catch (error) {
    [3.7422]
    [3.7450]
    }
    catch (error) {
  • replacement in bin/main.js at line 453
    [3.12267][3.2133:2276]()
    const integer_threads_available = Math.trunc(float_server_used_ram_free / object_get_constants(ns).object_scripts.object_weaken_script.ram);
    [3.12267]
    [3.12396]
    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
    [3.15750][3.2277:2418]()
    const integer_threads_available = Math.trunc(float_server_used_ram_free / object_get_constants(ns).object_scripts.object_grow_script.ram);
    [3.15750]
    [3.15877]
    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
    [3.18332][3.2419:2560]()
    const integer_threads_available = Math.trunc(float_server_used_ram_free / object_get_constants(ns).object_scripts.object_hack_script.ram);
    [3.18332]
    [3.18459]
    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
    [3.3795167]
    [3.19391]
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • replacement in bin/main.js at line 564
    [3.20636][3.20636:20703]()
    const object_scripts = object_get_constants(ns).object_scripts;
    [3.20636]
    [3.20703]
    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
    [3.22087][3.2561:2916]()
    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);
    [3.22087]
    [3.22400]
    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
    [3.28927][3.28927:29038]()
    const object_constants = object_get_constants(ns);
    const object_scripts = object_constants.object_scripts;
    [3.28927]
    [3.29038]
    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
    [3.31458][3.3040:3180]()
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, object_scripts.object_weaken_script.ram, 1)) {
    [3.31458]
    [3.31584]
    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
    [3.31880][3.3181:3295]()
    float_server_used_ram_free_current -= integer_threads_weaken * object_scripts.object_weaken_script.ram;
    [3.31880]
    [3.31980]
    float_server_used_ram_free_current -= integer_threads_weaken * ns.getScriptRam(string_weaken);
  • replacement in bin/main.js at line 802
    [3.33080][3.3296:3434]()
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, object_scripts.object_grow_script.ram, 1)) {
    [3.33080]
    [3.33204]
    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
    [3.33736][3.3435:3545]()
    float_server_used_ram_free_current -= integer_threads_grow * object_scripts.object_grow_script.ram;
    [3.33736]
    [3.33832]
    float_server_used_ram_free_current -= integer_threads_grow * ns.getScriptRam(string_grow);
  • replacement in bin/main.js at line 842
    [3.35192][3.3546:3684]()
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, object_scripts.object_hack_script.ram, 1)) {
    [3.35192]
    [3.35316]
    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
    [3.35807][3.3685:3795]()
    float_server_used_ram_free_current -= integer_threads_hack * object_scripts.object_hack_script.ram;
    [3.35807]
    [3.35903]
    float_server_used_ram_free_current -= integer_threads_hack * ns.getScriptRam(string_hack);
  • edit in bin/main.js at line 908
    [3.38777]
    [3.38777]
    const array_workers = object_get_constants(ns).array_workers;
  • replacement in bin/main.js at line 919
    [3.39404][3.3796:3887]()
    string_script = object_get_constants(ns).object_scripts.object_weaken_script.file;
    [3.39404]
    [3.39481]
    string_script = array_workers[0];
  • replacement in bin/main.js at line 923
    [3.39525][3.3888:3977]()
    string_script = object_get_constants(ns).object_scripts.object_grow_script.file;
    [3.39525]
    [3.39600]
    string_script = array_workers[1];
  • replacement in bin/main.js at line 927
    [3.39644][3.3978:4067]()
    string_script = object_get_constants(ns).object_scripts.object_hack_script.file;
    [3.39644]
    [3.39719]
    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 servers
    void_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 necessary
    while (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 schedule
    const 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
    [3.3289][2.11481:11527]()
    ### "main.js" (8.75 [+6.6] [+8.85] [+2.2] GB)
    [3.3289]
    [2.11527]
    ### "main.js" (8.85 [+6.6] [+8.85] [+2.2] GB)
  • replacement in README.md at line 21
    [3.3327][3.3327:3353]()
    `run main.js [OPTIONS]`
    [3.3327]
    [3.3353]
    `run main.js [OPTIONS] [FLAGS]`
  • edit in README.md at line 56
    [3.4856]
    [3.4856]
    #### 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
    [3.4930][2.12019:12084]()
    `run main.js --job-cap 4000 -i "harakiri-sushi" -r 0.7 -s 0.5`
    [3.4930]
    [3.4988]
    `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
    [3.4989][2.12085:12406]()
    * 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.
    [3.4989]
    [3.5163]
    * 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.