Skip to content

Commit

Permalink
Theoretically faster scan, practically no different, might even intro…
Browse files Browse the repository at this point in the history
…duce a bug *shrug*
  • Loading branch information
alainbryden committed Oct 25, 2022
1 parent 9d2c798 commit 47eb406
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ export function scanAllServers(ns) {
let infiniteLoopProtection = 9999; // In case you mess with this code, this should save you from getting stuck
while (hostsToScan.length > 0 && infiniteLoopProtection-- > 0) { // Loop until the list of hosts to scan is empty
let hostName = hostsToScan.pop(); // Get the next host to be scanned
discoveredHosts.push(hostName); // Mark this host as "scanned"
for (const connectedHost of ns.scan(hostName)) // "scan" (list all hosts connected to this one)
if (!discoveredHosts.includes(connectedHost)) // If we haven't already scanned this host
if (!discoveredHosts.includes(connectedHost) && !hostsToScan.includes(connectedHost)) // If we haven't found this host
hostsToScan.push(connectedHost); // Add it to the queue of hosts to be scanned
discoveredHosts.push(hostName); // Mark this host as "scanned"
}
return discoveredHosts; // The list of scanned hosts should now be the set of all hosts in the game!
}
Expand Down

0 comments on commit 47eb406

Please sign in to comment.