Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Apply Reserved word fix + Sleep time fix #21

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/mainHack.ns
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ function weakenCyclesForHack(hackCycles) {
async function getHackableServers(ns, servers) {
const playerDetails = getPlayerDetails(ns)

const hackableServers = Object.keys(servers)
const vulnerableServers = Object.keys(servers)
.filter((hostname) => ns.serverExists(hostname))
.filter((hostname) => servers[hostname].ports <= playerDetails.portHacks || ns.hasRootAccess(hostname))
.filter((hostname) => servers[hostname].ram >= 2)

for (const hostname of hackableServers) {
for (const hostname of vulnerableServers) {
if (hostname === 'home') continue;
if (!ns.hasRootAccess(hostname)) {
hackPrograms.forEach((hackProgram) => {
Expand All @@ -111,8 +111,8 @@ async function getHackableServers(ns, servers) {

}

hackableServers.sort((a, b) => servers[a].ram - servers[b].ram)
return hackableServers
vulnerableServers.sort((a, b) => servers[a].ram - servers[b].ram)
return vulnerableServers
}

function findTargetServer(ns, serversList, servers, serverExtraData) {
Expand Down Expand Up @@ -172,13 +172,13 @@ export async function main(ns) {
}
serverMap.servers.home.ram = Math.max(0, serverMap.servers.home.ram - settings.homeRamReserved)

const hackableServers = await getHackableServers(ns, serverMap.servers)
const vulnerableServers = await getHackableServers(ns, serverMap.servers)

const targetServers = findTargetServer(ns, hackableServers, serverMap.servers, serverExtraData)
const targetServers = findTargetServer(ns, vulnerableServers, serverMap.servers, serverExtraData)
const bestTarget = targetServers.shift()
const hackTime = ns.getHackTime(bestTarget) * 1000
const growTime = ns.getGrowTime(bestTarget) * 1000
const weakenTime = ns.getWeakenTime(bestTarget) * 1000
const hackTime = ns.getHackTime(bestTarget)
const growTime = ns.getGrowTime(bestTarget)
const weakenTime = ns.getWeakenTime(bestTarget)

const growDelay = Math.max(0, weakenTime - growTime - 15 * 1000)
const hackDelay = Math.max(0, growTime + growDelay - hackTime - 15 * 1000)
Expand All @@ -199,8 +199,8 @@ export async function main(ns) {
let growCycles = 0
let weakenCycles = 0

for (let i = 0; i < hackableServers.length; i++) {
const server = serverMap.servers[hackableServers[i]]
for (let i = 0; i < vulnerableServers.length; i++) {
const server = serverMap.servers[vulnerableServers[i]]
hackCycles += Math.floor(server.ram / 1.7)
growCycles += Math.floor(server.ram / 1.75)
}
Expand Down Expand Up @@ -239,8 +239,8 @@ export async function main(ns) {
}`
)

for (let i = 0; i < hackableServers.length; i++) {
const server = serverMap.servers[hackableServers[i]]
for (let i = 0; i < vulnerableServers.length; i++) {
const server = serverMap.servers[vulnerableServers[i]]
let cyclesFittable = Math.max(0, Math.floor(server.ram / 1.75))
const cyclesToRun = Math.max(0, Math.min(cyclesFittable, growCycles))

Expand All @@ -261,8 +261,8 @@ export async function main(ns) {

ns.tprint(`[${localeHHMMSS()}] Cycles ratio: ${growCycles} grow cycles; ${weakenCycles} weaken cycles`)

for (let i = 0; i < hackableServers.length; i++) {
const server = serverMap.servers[hackableServers[i]]
for (let i = 0; i < vulnerableServers.length; i++) {
const server = serverMap.servers[vulnerableServers[i]]
let cyclesFittable = Math.max(0, Math.floor(server.ram / 1.75))
const cyclesToRun = Math.max(0, Math.min(cyclesFittable, growCycles))

Expand Down Expand Up @@ -300,8 +300,8 @@ export async function main(ns) {

ns.tprint(`[${localeHHMMSS()}] Cycles ratio: ${hackCycles} hack cycles; ${growCycles} grow cycles; ${weakenCycles} weaken cycles`)

for (let i = 0; i < hackableServers.length; i++) {
const server = serverMap.servers[hackableServers[i]]
for (let i = 0; i < vulnerableServers.length; i++) {
const server = serverMap.servers[vulnerableServers[i]]
let cyclesFittable = Math.max(0, Math.floor(server.ram / 1.7))
const cyclesToRun = Math.max(0, Math.min(cyclesFittable, hackCycles))

Expand Down