Created
November 25, 2014 16:38
-
-
Save DenisGorbachev/329a68914426a13c9909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var newZombieCountsByNode = [] | |
for(var nodeIdx = 0; nodeIdx < zombieCountsByNode.length; nodeIdx++) { | |
var incomingZombies = neighborsByNode[nodeIdx].map(function(neighbor) { return zombieCountsByNode[neighbor] / neighborsByNode[neighbor].length }) | |
newZombieCountsByNode[nodeIdx] = incomingZombies.reduce(function(a,b) {return a + b}) | |
} | |
var isStabilised = true | |
for(var nodeIdx = 0; nodeIdx < zombieCountsByNode.length; nodeIdx++) { | |
if (Math.abs(zombieCountsByNode[nodeIdx] - newZombieCountsByNode[nodeIdx]) > 0.10) { | |
isStabilised = false | |
break; | |
} | |
} | |
if (isStabilised) { | |
newZombieCountsByNode.sort(function(a,b) { return b - a; }) | |
console.log(newZombieCountsByNode.slice(0, 5).map(function(x) { return Math.round(x) }).join(" ")) | |
} else { | |
runSimulation(neighborsByNode, newZombieCountsByNode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment