main.js, hacker.js, servers.js, ram.js: refactor.
[?]
Apr 28, 2020, 4:18 PM
BKG7YVUVECDMXYJHUCUG2OULA4MSHZURNSDR7PYPPCSFM5ZV326QCDependencies
- [2]
P6ZJC2SHhacker.js: normalise factors used in server scoring function. - [3]
3TZILRX2servers.js: fix and refactor. - [4]
2BKHJI2Sinit - [5]
3NFCZ6IPfixed the ram utilisation logic. added flags to `main.js` that can prevent the execution of helpers. - [6]
XQDYEN4Mhacker.js: change server scoring function. - [7]
Y5OWMCQRall: 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]
SLSWBNYTadded ram utilisation logic to `ram.js` and `servers.js`. split and refactored redundant code into separate library files. - [9]
HSNSECD5all: refactor. main.js: fix call to `void_kill_script_named_server_named`. - [10]
AXGQ7FMLsplit and refactor hacking logic to "hacker.js" and argument parsing and script execution logic to "main.js". update "README.md". - [11]
MKHG4OQBmake worker scripts and worker script executor time-aware. - [12]
NQ22FUSWadd more options to `main.js`. update `README.md`. - [13]
DJDWBCCQadd missing "nop.js". killall.js: rename to kill.js. add `--script` and `--server` options. - [*]
V4DMWF25remove redundant preparation steps in "hacker.js".
Change contents
- replacement in sbin/servers.js at line 11
for (; !boolean_servers_bought_all_max(ns); ) {for (;;) { - replacement in sbin/servers.js at line 14
float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold;!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
) {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) ||)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
boolean_conditions_server_purchase_1(ns);boolean_conditions_server_purchase_1(ns)); - replacement in sbin/servers.js at line 33
)ns.purchaseServer(string_servers_bought_name,integer_get_server_ram_biggest_afforded(ns))await ns.sleep(float_period_check);})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
- edit in sbin/ram.js at line 9
ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost() && - replacement in sbin/ram.js at line 12
)) { - replacement in sbin/ram.js at line 14
for (;ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost();)ns.upgradeHomeRam(), await ns.sleep(float_period_check);ns.upgradeHomeRam(); - replacement in sbin/ram.js at line 16
ns.print(JSON.stringify(error)), await ns.sleep(float_period_check);ns.print(JSON.stringify(error)); - edit in sbin/ram.js at line 18
await ns.sleep(float_period_check);} - replacement in sbin/hacker.js at line 1
/* hacker.js - 8.05GB - TODO:/* hacker.js - 8.25GB - TODO: - edit in sbin/hacker.js at line 13
import { boolean_array_scripts_any_running } from "lib_ps.js"; - replacement in sbin/hacker.js at line 21
(integer_time_finishes =void_runner(ns, ...array_arguments.slice(1)) + Date.now()),await ns.sleep(1e3 * array_arguments[0]);!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
// returns the total RAM from all the servers you have root access toconst float_get_network_ram_total = function (ns) {// returns the total RAM trait from all the servers you have root access toconst float_get_network_ram_trait = function (ns, float_get_ram_trait) { - replacement in lib/lib_ram_server.js at line 28
let float_network_ram_total = 0;let float_network_ram_trait = 0; - replacement in lib/lib_ram_server.js at line 34
float_network_ram_total += float_get_server_ram_total(float_network_ram_trait += float_get_ram_trait( - replacement in lib/lib_ram_server.js at line 38
return float_network_ram_total;return float_network_ram_trait; - edit in lib/lib_ram_server.js at line 41
// returns the total RAM used from all the servers you have root access toconst 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
return float_get_network_ram_used(ns) / float_get_network_ram_total(ns);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
import { boolean_script_running } from "lib_ps.js"; - edit in bin/main.js at line 159
float_period_check_seconds, - edit in bin/main.js at line 228
}};// returns true if a script is running on any serverconst 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
return !1; - replacement in README.md at line 11
* Reserve at least enough RAM to be able to run "hacker.js" (8.05 GB).* 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
* 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.* 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.