Last active
July 22, 2023 23:45
-
-
Save apacheli/fc459074cbcf1416a9bc88bd346af905 to your computer and use it in GitHub Desktop.
SPD (speed) determines who goes first, and the amount of actions that can be made in a turn. Here, the example uses two speeds: [125, 100]. The higher the value the faster. 125 can make 2 actions on every 4th turn, or 1.25 actions every turn to put it simply.
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
function actions_per_turn(speeds, turns) { | |
const arr = []; | |
const slowest_speed = Math.min(...speeds); | |
for (const speed of speeds) { | |
const speed_arr = []; | |
let remainder = 0; | |
for (let i = 0; i < turns; i++) { | |
const value = speed / slowest_speed + remainder; | |
const floored = Math.floor(value); | |
speed_arr.push(floored); | |
remainder = value - floored; | |
} | |
arr.push(speed_arr); | |
} | |
return arr; | |
} | |
const arr = actions_per_turn([125, 100], 10); | |
console.log(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment