2nd attempt to fix percentage to steal

[?]
Apr 13, 2020, 3:49 PM
VHWFHMNWZS4GA5ZW6QSOTDXS4WONZLGEZS5P2RFM7DK7VWDYSHHAC

Dependencies

  • [2] VMXI7PS4 added action cap. improved scoring system. fixed parts of security and cash predictors. made lshw loopable.
  • [3] 6MBUKAG6 remove unneeded functions and comments. update readme.
  • [4] 2BKHJI2S init
  • [5] YANDOFZ4 added readme and licenses

Change contents

  • replacement in lib/lib.js at line 540
    [3.3759280][3.3759280:3759499]()
    const integer_get_threads_required_for_min_security_weaken = function(ns, string_server_target, float_server_target_security) {
    void_debug(integer_get_threads_required_for_min_security_weaken, Array.from(arguments));
    [3.3759280]
    [3.3759499]
    const integer_get_threads_required_for_weaken_minimum_security = function(ns, string_server_target, float_server_target_security) {
    void_debug(integer_get_threads_required_for_weaken_minimum_security, Array.from(arguments));
  • replacement in lib/lib.js at line 549
    [3.3760155][3.3760155:3760300]()
    const integer_threads_required = integer_get_threads_required_for_min_security_weaken(ns, string_server_target, float_server_target_security);
    [3.3760155]
    [3.3760300]
    const integer_threads_required = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security);
  • edit in lib/lib.js at line 551
    [3.3760397]
    [3.3760397]
    };
    // returns the security decrease from the weaken threads used. Adapted from `weaken` in NetscriptFunctions.js and `weaken` in Server.ts
    const float_get_security_decrease_from_weaken = function(ns, integer_threads_weaken) {
    void_debug(float_get_security_decrease_from_weaken, Array.from(arguments));
    return integer_threads_weaken * object_get_constants(ns).ServerWeakenAmount;
  • replacement in lib/lib.js at line 596
    [3.3762691][3.3762691:3762924]()
    const integer_get_threads_required_for_max_cash_grow = function(ns, string_server_target, float_server_target_security, float_server_target_cash) {
    void_debug(integer_get_threads_required_for_max_cash_grow, Array.from(arguments));
    [3.3762691]
    [3.3762924]
    const integer_get_threads_required_for_grow_maximum_cash = function(ns, string_server_target, float_server_target_security, float_server_target_cash) {
    void_debug(integer_get_threads_required_for_grow_maximum_cash, Array.from(arguments));
  • replacement in lib/lib.js at line 605
    [3.3763610][3.3763610:3763775]()
    const integer_threads_required = integer_get_threads_required_for_max_cash_grow(ns, string_server_target, float_server_target_security, float_server_target_cash);
    [3.3763610]
    [3.3763775]
    const integer_threads_required = integer_get_threads_required_for_grow_maximum_cash(ns, string_server_target, float_server_target_security, float_server_target_cash);
  • replacement in lib/lib.js at line 633
    [3.3765215][3.3765215:3765447]()
    const float_get_threads_required_to_hack_percentage = function(ns, string_server_target, float_server_target_security, float_percentage_to_steal) {
    void_debug(float_get_threads_required_to_hack_percentage, Array.from(arguments));
    [3.3765215]
    [2.4121]
    const integer_get_threads_required_to_hack_percentage = function(ns, string_server_target, float_server_target_security, float_percentage_to_steal) {
    void_debug(integer_get_threads_required_to_hack_percentage, Array.from(arguments));
  • replacement in lib/lib.js at line 642
    [3.3766134][3.3766134:3766299]()
    const integer_threads_required = float_get_threads_required_to_hack_percentage(ns, string_server_target, float_server_target_security, float_percentage_to_steal);
    [3.3766134]
    [3.3766299]
    const integer_threads_required = integer_get_threads_required_to_hack_percentage(ns, string_server_target, float_server_target_security, float_percentage_to_steal);
  • replacement in lib/lib.js at line 667
    [3.3767061][2.5135:5672]()
    // returns true if there is enough ram to provide the threads required by weaken to weaken to minimum security, then by grow to grow string_server_target's cash by float_percentage_to_steal, then by weaken to weaken to minimum security again if possible, otherwise, returns false. assumes security is at float_server_target_security
    const bool_is_ram_enough_after_hack_percentage = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash_before, float_server_target_security, float_percentage_to_steal) {
    [3.3767061]
    [2.5672]
    // should return true if there is enough ram to provide the threads required by weaken to weaken to minimum security, then by grow to grow string_server_target's cash back to maximum after stealing float_percentage_to_steal of the cash, then by weaken to weaken to minimum security again if possible, otherwise, returns false. assumes security is at float_server_target_security
    const bool_is_ram_enough_after_hack_percentage = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash, float_server_target_security, float_percentage_to_steal) {
  • edit in lib/lib.js at line 670
    [2.5751]
    [2.5751]
    const object_scripts = object_get_constants(ns).object_scripts;
  • replacement in lib/lib.js at line 672
    [2.5752][3.3767546:3767688](),[3.3767546][3.3767546:3767688](),[3.3767688][2.5753:6560](),[2.6560][3.3767874:3767954](),[3.3767874][3.3767874:3767954]()
    const integer_threads_available = Math.trunc(float_server_used_ram_free * Math.pow (object_get_constants(ns).object_scripts.grow.ram, -1));
    const integer_threads_required = integer_get_threads_required_for_min_security_weaken(ns, string_server_target, float_get_security_increase_from_hack(ns, string_server_target, float_server_target_security, float_server_target_cash_before, integer_get_threads_hack(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_percentage_to_steal))) + integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security, float_percentage_to_steal) + integer_get_threads_required_for_min_security_weaken(ns, string_server_target, float_get_security_increase_from_grow(ns, integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security, float_percentage_to_steal)));
    if (integer_threads_required < integer_threads_available) {
    return false;
    [2.5752]
    [3.3767954]
    const float_server_target_security_after_hack = float_server_target_security + float_get_security_increase_from_hack(ns, string_server_target, float_server_target_security, float_server_target_cash, integer_get_threads_hack(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_percentage_to_steal));
    const integer_threads_required_for_weaken_minimum_security_after_hack = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security_after_hack);
    const float_server_target_security_after_weaken = float_server_target_security_after_hack - float_get_security_decrease_from_weaken(ns, integer_threads_required_for_weaken_minimum_security_after_hack);
    const integer_threads_required_for_cash_grow_after_percentage_stolen = integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security_after_weaken, float_percentage_to_steal);
    const float_server_target_security_after_grow = float_server_target_security_after_weaken + float_get_security_increase_from_grow(ns,integer_threads_required_for_cash_grow_after_percentage_stolen);
    const integer_threads_required_for_weaken_minimum_security_after_grow = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security_after_grow);
    const float_ram_required = (integer_threads_required_for_weaken_minimum_security_after_hack * object_scripts.grow.weaken) + (integer_threads_required_for_cash_grow_after_percentage_stolen * object_scripts.grow.ram) + (integer_threads_required_for_weaken_minimum_security_after_grow * object_scripts.grow.weaken);
    if (float_ram_required < float_server_used_ram_free) {
    return true;
  • replacement in lib/lib.js at line 690
    [3.3767967][3.3767967:3767984]()
    return true;
    [3.3767967]
    [3.3767984]
    return false;
  • replacement in lib/lib.js at line 700
    [3.3768381][2.6561:7006]()
    // this should return optimum percentage to steal such that cash stolen is as high as float_steal_cap and string_server_target's cash still able to be grown to 100% after one grow with the ram it has remaining by using a binary search algorithm
    const float_get_percentage_to_steal = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash_before, float_server_target_security, float_precision, float_steal_cap) {
    [3.3768381]
    [3.3768770]
    // this should return optimum percentage to steal such that cash stolen at most is as high as float_steal_cap and string_server_target's security is able to be weakened to minimum with one weaken after the hack, its cash grown to 100% after one grow after the weaken, then its security weakened again to minimum with one weaken, all with the ram it has remaining after the hack by using a binary search algorithm
    const float_get_percentage_to_steal = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash, float_server_target_security, float_precision, float_steal_cap) {
  • replacement in lib/lib.js at line 707
    [3.2327][2.7007:7203]()
    if (bool_is_ram_enough_after_hack_percentage(ns, float_server_used_ram_free, string_server_target, float_server_target_cash_before, float_server_target_security, float_percentage_to_steal)) {
    [3.2327]
    [3.3769268]
    if (bool_is_ram_enough_after_hack_percentage(ns, float_server_used_ram_free, string_server_target, float_server_target_cash, float_server_target_security, float_percentage_to_steal)) {
  • replacement in lib/lib.js at line 880
    [3.3777381][2.8526:8688]()
    const float_server_target_security_uncorrected = float_server_target_security_current - (integer_threads_weaken * object_constants.ServerWeakenAmount);
    [3.3777381]
    [3.3777541]
    const float_server_target_security_uncorrected = float_server_target_security_current - float_get_security_decrease_from_weaken(ns, integer_threads_weaken);
  • replacement in lib/lib.js at line 941
    [3.3781781][2.9109:9807]()
    // this is supposed to be the section that uses the `float_get_percentage_to_steal` function to calculate and hack the optimum amount of cash, but it doesn't seem to work properly and I still haven't figured why or how to fix it, so for now I think it just hacks whatever `float_steal_cap` percent of cash the server has.
    //const integer_threads_hack = integer_get_threads_hack(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_get_percentage_to_steal(ns, float_server_used_ram_free_current, string_server_target, float_server_target_cash_current, float_server_target_security_current, float_precision, float_steal_cap));
    [3.3781781]
    [3.3782106]
    // // this is supposed to be the section that uses the `float_get_percentage_to_steal` function to calculate and hack the optimum amount of cash, but it doesn't seem to work properly and I still haven't figured why or how to fix it, so for now I think it just hacks whatever `float_steal_cap` percent of cash the server has.
    // const integer_threads_hack = integer_get_threads_hack(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_get_percentage_to_steal(ns, float_server_used_ram_free_current, string_server_target, float_server_target_cash_current, float_server_target_security_current, float_precision, float_steal_cap));
  • edit in lib/lib.js at line 975
    [3.3784261][2.10962:10963]()
  • replacement in bin/main.js at line 11
    [2.11423][2.11423:11458]()
    const integer_action_cap = 200;
    [2.11423]
    [2.11458]
    const integer_action_cap = 2000;
  • replacement in bin/main.js at line 13
    [2.11492][3.3793938:3793975](),[3.3793938][3.3793938:3793975]()
    const float_padding_seconds = 0.1;
    [2.11492]
    [2.11493]
    const float_padding_seconds = 0.5;