Advertisement
Guest User

Untitled

a guest
Mar 10th, 2018
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. // takes (target), makes a job for that target, and pushes the job to the queue
  2. target = args[0];
  3. JOB_PORT = 1; // port to use as the job queue
  4. SEC_THRESH = 1.1; // don't bother weakening if security is near minimum
  5. MONEY_THRESH = 0.95; // don't bother growing if money is near maximum
  6. HACK_PCT = 0.8; // percent of money to hack per job
  7. BITNODE_MULTS = false; // do we have access to bitnode multipliers yet?
  8.  
  9. // game constants needed for calculations
  10. SERVER_BASE_GROWTH = 0.03;
  11. SERVER_MAX_GROWTH = 0.0035;
  12. WEAKEN_AMT = 0.05;
  13. GROW_SEC = 0.004;
  14. HACK_SEC = 0.002;
  15. // bitnode constants (since we don't have access to the API yet)
  16. BN_SERVER_GROWTH_RATE = 1;
  17. BN_SCRIPT_HACK_MONEY = 1;
  18.  
  19. if (BITNODE_MULTS) {
  20. BN_SERVER_GROWTH_RATE = getBitNodeMultipliers().ServerGrowthRate;
  21. BN_SCRIPT_HACK_MONEY = getBitNodeMultipliers().ScriptHackMoney;
  22. }
  23.  
  24. function getWeakThreads(secLev,secMin) {
  25. return Math.ceil( (secLev - secMin) / WEAKEN_AMT );
  26. }
  27.  
  28. function getGrowThreads(secLev,monLev,monMax) {
  29. if (monLev === 0) {
  30. threads = 100; // grow some seed money from 0
  31. } else {
  32. growthRate = 1 + Math.min(SERVER_MAX_GROWTH, SERVER_BASE_GROWTH / secLev);
  33. threads = Math.log(monMax / monLev) / Math.log(growthRate);
  34. threads /= getServerGrowth(target) / 100;
  35. threads /= getHackingMultipliers().growth;
  36. threads /= BN_SERVER_GROWTH_RATE;
  37. threads = Math.ceil(threads);
  38. }
  39. return threads;
  40. }
  41.  
  42. function getHackThreads(secLev) {
  43. hackRate = (100 - secLev) / 100;
  44. hackRate *= 1 - (getServerRequiredHackingLevel(target) - 1)/getHackingLevel();
  45. hackRate *= getHackingMultipliers().money / 240;
  46. hackRate = Math.min(1,Math.max(0,hackRate));
  47. hackRate *= BN_SCRIPT_HACK_MONEY;
  48. if (hackRate > HACK_PCT) {
  49. threads = 1;
  50. } else if (hackRate <= 0) {
  51. tprint("exiting makejob2.script because we can't hack this server");
  52. tprint("target=" + target);
  53. exit(); // even with min security we can't usefully hack this server
  54. } else {
  55. threads = Math.ceil(HACK_PCT / hackRate);
  56. }
  57. return threads;
  58. }
  59.  
  60. // build a job:
  61. // 'weak' jobs only weaken
  62. // 'grow' jobs also weaken enough to get back to min security (even if we're above minimum now)
  63. // 'hack' jobs also grow enough to get back to max money and weaken enough to get back to min security
  64. function buildJob(type,secLev,secMin,monLev,monMax) {
  65. if (type === 'hack') {
  66. // simulate hack's effect on money and security
  67. hackThreads = getHackThreads(secLev);
  68. monLev *= 1 - HACK_PCT;
  69. secLev += hackThreads * HACK_SEC;
  70. } else {
  71. hackThreads = 0;
  72. }
  73. if (type === 'weak') {
  74. growThreads = 0;
  75. } else {
  76. // simulate grow's effect on security
  77. growThreads = getGrowThreads(secLev,monLev,monMax);
  78. secLev += growThreads * GROW_SEC;
  79. }
  80. weakThreads = getWeakThreads(secLev,secMin);
  81. return [target,hackThreads,growThreads,weakThreads,-1]; // -1 is the monitor ID
  82. }
  83.  
  84. secLev = getServerSecurityLevel(target);
  85. secMin = getServerMinSecurityLevel(target);
  86. monLev = getServerMoneyAvailable(target);
  87. monMax = getServerMaxMoney(target);
  88. if (secLev > SEC_THRESH * secMin) {
  89. // do a weaken-only job if security level is above threshold
  90. type = 'weak';
  91. } else if (monLev < MONEY_THRESH * monMax) {
  92. // do a grow job (plus offsetting weaken) if money is below threshold
  93. type = 'grow';
  94. } else {
  95. // security is low and money is high, hack!
  96. // (including offsetting grow & weaken)
  97. type = 'hack';
  98. }
  99. // build and issue job
  100. write(JOB_PORT,buildJob(type,secLev,secMin,monLev,monMax).join(','));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement