What is the optimal algorithm of "random card distribution (Poker game)"?
I'd like to build a program that can distribute playing cards evenly with respect to their numbers and suits to the 4 players in a Poker game. In other words, all 4 players should have a straight or straight flush at the same turn. But, how do we build the algorithm for that?
This is how I think it can be approached:
- Set i = suits (e.g., 1 for heart 2 for spades) j = number (ace = 1, king =13)
- Make a matrix deck (Like [H1, H2, ... H13]...[S1, S2, ... S13])
- Randomly choose the first card (random i1 and j1), save to player 1's deck card = deck[i1, j1] player1 = np.append(card)
- Randomly choose second card (random i2 and j2)
- If i2 = i1, rechoose i, if not, save the card to player 2 deck
- Continue until 4th card
- For 5th turn, if i5 = i1 and j5 = j1+1 or j1-1, save the card to player 1 deck. if not rechoose j or i.
- Continue until 8th card
- For the 9th turn, if i9 = i1 and j9 = j1+1 or j1-1 or j5+1 or j5-1, save the card to player 1 deck. if no rechoose j or i
However, this algorithm is time-consuming, because I need to introduce a new way to check every 4 turns whether it has a close number of previous cards that the player already has. Is there any way to make this simpler, such as to check the card having a close number of previous cards for making a straight flush?