Skip to content

Instantly share code, notes, and snippets.

@pellejacobs
Created November 11, 2016 21:39
Show Gist options
  • Save pellejacobs/93196751ee3040c751bd6fef2474a40c to your computer and use it in GitHub Desktop.
Save pellejacobs/93196751ee3040c751bd6fef2474a40c to your computer and use it in GitHub Desktop.
const chooseSpawn = (roleCount) => {
const priorityQueue = [
'harvester',
'miner',
'transporter',
]
let nextSpawn
_.reduce(priorityQueue, (expectedRoleCount, role) => {
if (!expectedRoleCount[role]) expectedRoleCount[role] = 0
expectedRoleCount[role] += 1
if (nextSpawn === 'undefined' && roleCount[role] < expectedRoleCount[role]) {
nextSpawn = role
}
return expectedRoleCount
}, {})
return nextSpawn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment