minor refactoring.

[?]
Apr 25, 2020, 3:21 PM
7SRULDRFXA6ZZUEXRPCDO7NIUJDREKYI3ESUYTOXMSPVMORDJXIQC

Dependencies

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

Change contents

  • replacement in bin/main.js at line 1
    [3.3793719][2.2046:2533]()
    // 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?
    [3.3793719]
    [3.10320]
    /* main.js - 8.85GB - TODO:
    * add --help flag
    * 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.
    * add a job cap thing that prevents running more jobs if the first worker in a cycle finishes. add a thing to worker script that writes to a file (or to `window`) its identifier, when it started and when it finishes. add a padding optimiser that detects when tail collision occurs and increases padding each cycle if it does occur, and decreases it by half of how much it increases everytime no tail collision occurs
    * do we need to Add delay between each script execution?
    */
  • replacement in bin/main.js at line 32
    [3.3870][3.1663:1694]()
    let integer_job_cap = 2000;
    [3.3870]
    [3.3903]
    let integer_job_cap = 1000;
  • replacement in bin/main.js at line 34
    [3.3934][3.1695:1730]()
    let float_padding_seconds = 0.4;
    [3.3934]
    [3.11493]
    let float_padding_seconds = 1;
  • replacement in bin/main.js at line 38
    [3.11619][3.1763:1793]()
    let float_steal_cap = 0.96;
    [3.11619]
    [3.11651]
    let float_steal_cap = 0.9;
  • edit in bin/main.js at line 45
    [3.10628]
    [2.2534]
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • edit in bin/main.js at line 48
    [2.2597][2.2597:2738]()
    const integer_helper_threads_ram = 1;
    const array_helper_arguments_ram = [float_period_check_seconds, float_ram_utilisation_threshold];
  • replacement in bin/main.js at line 49
    [2.2789][2.2789:2965]()
    const integer_helper_threads_servers = 1;
    const array_helper_arguments_servers = [float_period_check_seconds, string_servers_bought_name, float_ram_utilisation_threshold];
    [2.2789]
    [3.2359]
    ================================
  • edit in bin/main.js at line 51
    [3.2360][2.2966:3576]()
    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]
    }
    ];
  • replacement in bin/main.js at line 74
    [2.4079][2.4079:4286]()
    // 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;
    [2.4079]
    [2.4286]
    // 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;
  • replacement in bin/main.js at line 150
    [3.4152][3.3794389:3794482](),[2.4798][3.3794389:3794482](),[3.11722][3.3794389:3794482](),[3.3794389][3.3794389:3794482]()
    let integer_time_current = Date.now();
    let integer_time_finishes = integer_time_current;
    [2.4798]
    [3.3794482]
    let integer_time_finishes = Date.now();
  • replacement in bin/main.js at line 152
    [3.3794499][3.3794499:3794595]()
    integer_time_current = Date.now();
    if (integer_time_current >= integer_time_finishes) {
    [3.3794499]
    [3.4153]
    if (integer_time_finishes <= Date.now()) {
  • edit in bin/main.js at line 530
    [3.3795167][2.5519:5552]()
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  • replacement in bin/main.js at line 715
    [3.30039][3.30039:30134]()
    // assumes weaken takes longest
    let integer_time_job_finishes_seconds = float_time_weaken;
    [3.30039]
    [3.30134]
    let integer_time_job_finishes_seconds = Math.max(float_time_weaken, float_time_grow, float_time_hack);
  • replacement in bin/main.js at line 915
    [3.8123][2.7098:7131]()
    ================================
    [3.8123]
    [2.7131]
    let integer_time_start = Date.now();
    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_get_constants(ns).array_workers], 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) - integer_time_start + Date.now());
    }
    }
    // 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) - integer_time_start + Date.now();
  • replacement in bin/lshw.js at line 44
    [3.13825][3.13825:13896]()
    float_sleep_duration = array_arguments[integer_indices_0 + 1];
    [3.13825]
    [3.13896]
    float_sleep_duration = array_arguments[integer_indices_0 + 1] * 1000;
  • replacement in README.md at line 106
    [3.5774][3.5774:5805]()
    `-d, --delay <MILLISECONDS>`
    [3.5774]
    [3.5805]
    `-d, --delay <SECONDS>`
  • replacement in README.md at line 108
    [3.5806][3.5806:6022]()
    * MILLISECONDS = The duration of delay between update, in milliseconds. Should be a floating-point number >= 1. By default, the script will only display server information once, unless this option is manually set.
    [3.5806]
    [3.6022]
    * SECONDS = The duration of delay between update, in seconds. Should be a floating-point number >= 0.001. By default, the script will only display server information once, unless this option is manually set.
  • replacement in README.md at line 111
    [3.6037][3.6037:6077]()
    `run lshw.js -s 1000 home foodnstuff`
    [3.6037]
    [3.6077]
    `run lshw.js -d 1 home foodnstuff`