main.js, hacker.js, servers.js, ram.js: refactor.

[?]
Apr 28, 2020, 4:18 PM
BKG7YVUVECDMXYJHUCUG2OULA4MSHZURNSDR7PYPPCSFM5ZV326QC

Dependencies

  • [2] P6ZJC2SH hacker.js: normalise factors used in server scoring function.
  • [3] 3TZILRX2 servers.js: fix and refactor.
  • [4] 2BKHJI2S init
  • [5] 3NFCZ6IP fixed the ram utilisation logic. added flags to `main.js` that can prevent the execution of helpers.
  • [6] XQDYEN4M hacker.js: change server scoring function.
  • [7] Y5OWMCQR all: remove unecessary uses of `exec`. refactor. main.js: add RAM reservation logic. lib_ram.js: renamed to lib_ram_server.js. README.js: update.
  • [8] SLSWBNYT added ram utilisation logic to `ram.js` and `servers.js`. split and refactored redundant code into separate library files.
  • [9] HSNSECD5 all: refactor. main.js: fix call to `void_kill_script_named_server_named`.
  • [10] AXGQ7FML split and refactor hacking logic to "hacker.js" and argument parsing and script execution logic to "main.js". update "README.md".
  • [11] MKHG4OQB make worker scripts and worker script executor time-aware.
  • [12] NQ22FUSW add more options to `main.js`. update `README.md`.
  • [13] DJDWBCCQ add missing "nop.js". killall.js: rename to kill.js. add `--script` and `--server` options.
  • [*] V4DMWF25 remove redundant preparation steps in "hacker.js".

Change contents

  • replacement in sbin/servers.js at line 11
    [3.249][3.249:299]()
    for (; !boolean_servers_bought_all_max(ns); ) {
    [3.249]
    [3.299]
    for (;;) {
  • replacement in sbin/servers.js at line 14
    [3.317][3.317:396]()
    float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold;
    [3.317]
    [4.3412]
    !boolean_servers_bought_all_max(ns) &&
    float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold &&
    boolean_conditions_server_delete_purchase(ns);
  • replacement in sbin/servers.js at line 18
    [4.3413][3.397:727](),[3.727][4.847:899](),[4.847][4.847:899]()
    ) {
    for (; boolean_conditions_server_delete_purchase(ns); )
    ns.deleteServer(string_get_server_bought_smallest(ns)),
    ns.purchaseServer(
    string_servers_bought_name,
    integer_get_server_ram_biggest_afforded(ns)
    ),
    await ns.sleep(float_period_check);
    for (
    ;
    boolean_conditions_server_purchase_3(ns) ||
    [4.3413]
    [4.899]
    )
    ns.deleteServer(string_get_server_bought_smallest(ns)),
    ns.purchaseServer(
    string_servers_bought_name,
    integer_get_server_ram_biggest_afforded(ns)
    ),
    await ns.sleep(float_period_check);
    for (
    ;
    !boolean_servers_bought_all_max(ns) &&
    float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold &&
    (boolean_conditions_server_purchase_3(ns) ||
  • replacement in sbin/servers.js at line 31
    [4.951][3.728:778]()
    boolean_conditions_server_purchase_1(ns);
    [4.951]
    [3.778]
    boolean_conditions_server_purchase_1(ns));
  • replacement in sbin/servers.js at line 33
    [3.779][3.779:960](),[3.960][4.4818:4824](),[4.4818][4.4818:4824]()
    )
    ns.purchaseServer(
    string_servers_bought_name,
    integer_get_server_ram_biggest_afforded(ns)
    )
    await ns.sleep(float_period_check);
    }
    [3.779]
    [4.1111]
    )
    ns.purchaseServer(
    string_servers_bought_name,
    integer_get_server_ram_biggest_afforded(ns)
    ),
    await ns.sleep(float_period_check);
  • edit in sbin/servers.js at line 43
    [4.4830]
    [4.1159]
  • edit in sbin/ram.js at line 9
    [4.5436]
    [4.5436]
    ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost() &&
  • replacement in sbin/ram.js at line 12
    [4.7946][4.5516:5522]()
    )
    [4.7946]
    [4.8087]
    ) {
  • replacement in sbin/ram.js at line 14
    [4.8099][4.5523:5703]()
    for (
    ;
    ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost();
    )
    ns.upgradeHomeRam(), await ns.sleep(float_period_check);
    [4.8099]
    [4.5703]
    ns.upgradeHomeRam();
  • replacement in sbin/ram.js at line 16
    [4.5727][4.5727:5804]()
    ns.print(JSON.stringify(error)), await ns.sleep(float_period_check);
    [4.5727]
    [4.8287]
    ns.print(JSON.stringify(error));
  • edit in sbin/ram.js at line 18
    [4.8295]
    [4.10887]
    await ns.sleep(float_period_check);
    }
  • replacement in sbin/hacker.js at line 1
    [4.14850][4.14851:14881]()
    /* hacker.js - 8.05GB - TODO:
    [4.14850]
    [2.11]
    /* hacker.js - 8.25GB - TODO:
  • edit in sbin/hacker.js at line 13
    [4.6562]
    [4.91]
    import { boolean_array_scripts_any_running } from "lib_ps.js";
  • replacement in sbin/hacker.js at line 21
    [4.6660][4.6660:6807]()
    (integer_time_finishes =
    void_runner(ns, ...array_arguments.slice(1)) + Date.now()),
    await ns.sleep(1e3 * array_arguments[0]);
    [4.6660]
    [4.16111]
    !boolean_array_scripts_any_running(
    ns,
    object_get_constants(ns).array_workers
    )
    ? ((integer_time_finishes =
    void_runner(ns, ...array_arguments) + Date.now()),
    await ns.sleep(integer_time_finishes - Date.now()))
    : await ns.sleep(integer_time_finishes - Date.now());
  • replacement in lib/lib_ram_server.js at line 25
    [4.3720556][4.3720556:3720679]()
    // returns the total RAM from all the servers you have root access to
    const float_get_network_ram_total = function (ns) {
    [4.3720556]
    [4.3720679]
    // returns the total RAM trait from all the servers you have root access to
    const float_get_network_ram_trait = function (ns, float_get_ram_trait) {
  • replacement in lib/lib_ram_server.js at line 28
    [4.3720740][4.3720740:3720775]()
    let float_network_ram_total = 0;
    [4.3720740]
    [4.3720775]
    let float_network_ram_trait = 0;
  • replacement in lib/lib_ram_server.js at line 34
    [4.3720895][4.3720895:3720954]()
    float_network_ram_total += float_get_server_ram_total(
    [4.3720895]
    [4.3720954]
    float_network_ram_trait += float_get_ram_trait(
  • replacement in lib/lib_ram_server.js at line 38
    [4.3721017][4.3721017:3721051]()
    return float_network_ram_total;
    [4.3721017]
    [4.3721051]
    return float_network_ram_trait;
  • edit in lib/lib_ram_server.js at line 41
    [4.3721055][4.3721055:3721554]()
    // returns the total RAM used from all the servers you have root access to
    const float_get_network_ram_used = function (ns) {
    const array_servers_rooted = array_get_servers_rooted(ns);
    let float_network_ram_used = 0;
    for (
    let integer_indices_0 = 0;
    integer_indices_0 < array_servers_rooted.length;
    ++integer_indices_0
    )
    float_network_ram_used += float_get_server_ram_used(
    ns,
    array_servers_rooted[integer_indices_0]
    );
    return float_network_ram_used;
    };
  • replacement in lib/lib_ram_server.js at line 43
    [4.3721678][4.3721678:3721753]()
    return float_get_network_ram_used(ns) / float_get_network_ram_total(ns);
    [4.3721678]
    [4.3721753]
    return (
    float_get_network_ram_trait(ns, float_get_server_ram_used) /
    float_get_network_ram_trait(ns, float_get_server_ram_total)
    );
  • edit in bin/main.js at line 17
    [4.9990]
    [4.9990]
    import { boolean_script_running } from "lib_ps.js";
  • edit in bin/main.js at line 159
    [4.12653][4.12653:12685]()
    float_period_check_seconds,
  • edit in bin/main.js at line 228
    [4.13828][4.13828:14613]()
    }
    };
    // returns true if a script is running on any server
    const boolean_script_running = function (ns, string_script) {
    const array_servers = array_get_servers(ns);
    for (
    let integer_indices_0 = 0;
    integer_indices_0 < array_servers.length;
    ++integer_indices_0
    ) {
    const string_server = array_servers[integer_indices_0],
    array_scripts_running = ns.ps(string_server);
    if (array_scripts_running.length > 0)
    for (
    let integer_indices_1 = 0;
    integer_indices_1 < array_scripts_running.length;
    ++integer_indices_1
    ) {
    const object_script = array_scripts_running[integer_indices_1],
    string_script_to_check = object_script.filename;
    if (string_script_to_check == string_script) return !0;
    }
  • edit in bin/main.js at line 229
    [4.14617][4.14617:14630]()
    return !1;
  • replacement in README.md at line 11
    [4.4253][4.4253:4326]()
    * Reserve at least enough RAM to be able to run "hacker.js" (8.05 GB).
    [4.4253]
    [4.2728]
    * Reserve at least enough RAM to be able to run "hacker.js" (8.25 GB).
  • edit in README.md at line 21
    [15.2396]
    [4.3444]
    * Wait until the current schedule finishes.
  • replacement in README.md at line 31
    [4.3400][4.3400:3568]()
    * SECONDS = The duration of delay between each checking done for the completion of the main cycle, in seconds. Should be a floating-point number > 0. Defaults to 10.
    [4.3400]
    [4.3568]
    * SECONDS = The duration of delay between each main loop used in helper scripts, in seconds. Should be a floating-point number > 0. Defaults to 10.