Eduardo Arruda Pimentel Eduardo Arruda Pimentel - 2 years ago 117
Javascript Question

Determine Poker Table Positions - Sit'n Go Tournaments

In poker we define player position according to the dealer. Like this:

enter image description here

Blue: Small Blind and Big Blind positions

Green: Late and Dealer/Late positions

Yellow: Middle positions

Pink: Early positions

So, assuming these two arrays:


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:


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:


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"


And should result:


How can I find the new dealer when player is eliminated?

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?

How sould I do the changePosition(dealer) function?

I have tried so much, but can't figure out how to do that.

Answer Source

Let's assume the players are always numbered 1-10. We don't need two data structures to store the player positions and statuses. We only need one indexed data structure to store player state:

State 1


State 2

positions: ["late","btn","sb","bb","early","early","early","medium","medium","medium"]

State 3

positions: ["eliminated","late","btn","sb","bb","early","early","early","medium","medium"];

This stores the same amount of information as your two arrays, and is more consistent. You simply access positions[0] to see what player 1's state is or positions[9] for player 10.

Now with this more consistent structure, it should be easier to handle status changes at the end of each round.

Eliminating players

After each round, change an eliminated player's status to "eliminated". You may need to have a temporary array at this point so that you can check what has happened in the previous round will still updating information for the next round.

How to treat the array as a circle

Move the dealer chip "btn" to (currentPositionOfBtn+1)%10 - this means the Button moves from 1 to 2 to 3, etc., but by using the remainder operator and the total number of players, we ensure that the move from position 9 (Player 10) cycles back round to 0 (Player 1).

If the player in currentPositionOfBtn+1)%10 has been eliminated, then check currentPositionOfBtn+2)%10 and so on - this is an easy loop to implement.

Recalculating the positions

Now given that the description of the positions changes as players are eliminated (by the end you have no "early" or "medium"), I would suggest recalculating the positions from the Dealer onwards at the end of each round, skipping over any players who are marked as "eliminated".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download