Note: I do the javascript code according to the ajrwhite answer. Hope it helps someone.
Link: http://codepen.io/eMineiro/pen/EKrNBe
Open codepen console to see the examples working.
In poker we define player position according to the dealer. Like this:
Blue: Small Blind and Big Blind positions
Green: Late and Dealer/Late positions
Yellow: Middle positions
Pink: Early positions
So, assuming these two arrays:
players:[1,2,3,4,5,6,7,8,9,10];
positions:["bb","sb","btn","late","medium","medium","medium","early","early","early"];
In this case, "player1" is the "Big Blind", "player2" is the "Small Blind", "player3" is the "button".....
I want to sort players array, when changePositions(dealer) is called. Example:
changePosition(10); //means that "player10" now is the new Dealer
And the result should be:
players:[2,1,10,9,8,7,6,5,4,3];
positions:["bb","sb","btn","late","medium","medium","medium","early","early","early"];
During the game, players could be eliminated. So I have a function to exclude "last position" in "positions array" and exclude the player. Then I need to call changePosition(X) again, where X is the next non-eliminated player on the left of "player10" (actual dealer).
Example for eliminated "player 1", new arrays should be:
players:[2,10,9,8,7,6,5,4,3];
positions:["bb","sb","btn","late","medium","medium","medium","early","early"];
And I need to call changePosition(X) again, to determine new positions, in this case X=2, because "player2" is on the left of the actual dealer "player10"
changePosition(2);
And should result:
players:[4,3,2,10,9,8,7,6,5];
positions:["bb","sb","btn","late","medium","medium","medium","early","early"];
How can I find the new dealer when player is eliminated?
Note: I created a function named changeNextDealer(). Negative index was not the problem, because the next dealer is clockwise. It's in the code pen link.
dealerArrayPosition-1; //But if bigBlind and smallBlind was eliminated simultaneously I get a negative position.
How can I map a negative index like -1, to the last position. Or -2 to the LastPosition-1? Is there a quickly way?
Note: This question is still no answered, but is not the main question of this discussion. I think a will ask in a separated post.
How should I do the changePosition(dealer) function?
I have tried so much, but can't figure out how to do that.
Note: I created a function named changePosition(). It's in the codepen link.