What's a good way to determine the following.
You have a table of game players, in an array of size N. Each round, each player takes a turn.
You know the index of the player that should go first, and each player will take a turn ascending the array, and looping back to 0 when it hits the last index. For example, if player at index 3 went first, then 4 would go second, and 2 would go last.
How do you calculate the index of the player that goes last in the round?
Here's one way:
var startPosition = 3;
var numberOfPlayers = 10;
for (var i=0;i<numberOfPlayers;i++) {
startPosition++;
if (startPosition == numberOfPlayers) startPosition = 0;
}