Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // takes (target), makes a job for that target, and pushes the job to the queue
- target = args[0];
- JOB_PORT = 1; // port to use as the job queue
- SEC_THRESH = 1.1; // don't bother weakening if security is near minimum
- MONEY_THRESH = 0.95; // don't bother growing if money is near maximum
- HACK_PCT = 0.8; // percent of money to hack per job
- BITNODE_MULTS = false; // do we have access to bitnode multipliers yet?
- // game constants needed for calculations
- SERVER_BASE_GROWTH = 0.03;
- SERVER_MAX_GROWTH = 0.0035;
- WEAKEN_AMT = 0.05;
- GROW_SEC = 0.004;
- HACK_SEC = 0.002;
- // bitnode constants (since we don't have access to the API yet)
- BN_SERVER_GROWTH_RATE = 1;
- BN_SCRIPT_HACK_MONEY = 1;
- if (BITNODE_MULTS) {
- BN_SERVER_GROWTH_RATE = getBitNodeMultipliers().ServerGrowthRate;
- BN_SCRIPT_HACK_MONEY = getBitNodeMultipliers().ScriptHackMoney;
- }
- function getWeakThreads(secLev,secMin) {
- return Math.ceil( (secLev - secMin) / WEAKEN_AMT );
- }
- function getGrowThreads(secLev,monLev,monMax) {
- if (monLev === 0) {
- threads = 100; // grow some seed money from 0
- } else {
- growthRate = 1 + Math.min(SERVER_MAX_GROWTH, SERVER_BASE_GROWTH / secLev);
- threads = Math.log(monMax / monLev) / Math.log(growthRate);
- threads /= getServerGrowth(target) / 100;
- threads /= getHackingMultipliers().growth;
- threads /= BN_SERVER_GROWTH_RATE;
- threads = Math.ceil(threads);
- }
- return threads;
- }
- function getHackThreads(secLev) {
- hackRate = (100 - secLev) / 100;
- hackRate *= 1 - (getServerRequiredHackingLevel(target) - 1)/getHackingLevel();
- hackRate *= getHackingMultipliers().money / 240;
- hackRate = Math.min(1,Math.max(0,hackRate));
- hackRate *= BN_SCRIPT_HACK_MONEY;
- if (hackRate > HACK_PCT) {
- threads = 1;
- } else if (hackRate <= 0) {
- tprint("exiting makejob2.script because we can't hack this server");
- tprint("target=" + target);
- exit(); // even with min security we can't usefully hack this server
- } else {
- threads = Math.ceil(HACK_PCT / hackRate);
- }
- return threads;
- }
- // build a job:
- // 'weak' jobs only weaken
- // 'grow' jobs also weaken enough to get back to min security (even if we're above minimum now)
- // 'hack' jobs also grow enough to get back to max money and weaken enough to get back to min security
- function buildJob(type,secLev,secMin,monLev,monMax) {
- if (type === 'hack') {
- // simulate hack's effect on money and security
- hackThreads = getHackThreads(secLev);
- monLev *= 1 - HACK_PCT;
- secLev += hackThreads * HACK_SEC;
- } else {
- hackThreads = 0;
- }
- if (type === 'weak') {
- growThreads = 0;
- } else {
- // simulate grow's effect on security
- growThreads = getGrowThreads(secLev,monLev,monMax);
- secLev += growThreads * GROW_SEC;
- }
- weakThreads = getWeakThreads(secLev,secMin);
- return [target,hackThreads,growThreads,weakThreads,-1]; // -1 is the monitor ID
- }
- secLev = getServerSecurityLevel(target);
- secMin = getServerMinSecurityLevel(target);
- monLev = getServerMoneyAvailable(target);
- monMax = getServerMaxMoney(target);
- if (secLev > SEC_THRESH * secMin) {
- // do a weaken-only job if security level is above threshold
- type = 'weak';
- } else if (monLev < MONEY_THRESH * monMax) {
- // do a grow job (plus offsetting weaken) if money is below threshold
- type = 'grow';
- } else {
- // security is low and money is high, hack!
- // (including offsetting grow & weaken)
- type = 'hack';
- }
- // build and issue job
- write(JOB_PORT,buildJob(type,secLev,secMin,monLev,monMax).join(','));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement