2nd attempt to fix percentage to steal
[?]
Apr 13, 2020, 3:49 PM
VHWFHMNWZS4GA5ZW6QSOTDXS4WONZLGEZS5P2RFM7DK7VWDYSHHACDependencies
- [2]
VMXI7PS4added action cap. improved scoring system. fixed parts of security and cash predictors. made lshw loopable. - [3]
6MBUKAG6remove unneeded functions and comments. update readme. - [4]
2BKHJI2Sinit - [5]
YANDOFZ4added readme and licenses
Change contents
- replacement in lib/lib.js at line 540
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));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
const integer_threads_required = integer_get_threads_required_for_min_security_weaken(ns, string_server_target, float_server_target_security);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
};// returns the security decrease from the weaken threads used. Adapted from `weaken` in NetscriptFunctions.js and `weaken` in Server.tsconst 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
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));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
const integer_threads_required = integer_get_threads_required_for_max_cash_grow(ns, string_server_target, float_server_target_security, float_server_target_cash);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
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));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
const integer_threads_required = float_get_threads_required_to_hack_percentage(ns, string_server_target, float_server_target_security, float_percentage_to_steal);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
// 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_securityconst 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) {// 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_securityconst 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
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;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
return true;return false; - replacement in lib/lib.js at line 700
// 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 algorithmconst 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) {// 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 algorithmconst 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
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)) {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
const float_server_target_security_uncorrected = float_server_target_security_current - (integer_threads_weaken * object_constants.ServerWeakenAmount);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
// 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));// // 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
- replacement in bin/main.js at line 11
const integer_action_cap = 200;const integer_action_cap = 2000; - replacement in bin/main.js at line 13
const float_padding_seconds = 0.1;const float_padding_seconds = 0.5;