-
-
Save pellejacobs/93196751ee3040c751bd6fef2474a40c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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