If you could solve poker with data science, you could make a lot of money any time you want.
If we want to model poker, the first step is to model a single deal of the cards. Now, casinos might deal from more than one deck. But let's start by modeling a single deal from a single 52-card deck:
def sample (n, m):
s = []
for j in range(n-m+1, n + 1):
t = randint(1, j + 1)
if t not in s:
s.append(t)
else:
s.append(j)
return s
This solution is called Floyd's Algorithm.
We can run this for different 5-card hands:
>>> sample(52, 5)
[42, 41, 19, 31, 52]
>>> sample(52, 5)
[30, 23, 37, 5, 17]
>>> sample(52, 5)
[44, 2, 17, 21, 30]
>>> sample(52, 5)
[19, 3, 36, 26, 6]
>>> sample(52, 5)
[23, 41, 11, 26, 34]
And if we want to deal 5 cards to two players, we will want to take 10 cards:
>>> sample(52, 10)
[37, 32, 45, 24, 35, 14, 12, 42, 51, 33]
>>> sample(52, 10)
[37, 4, 29, 39, 2, 44, 12, 5, 50, 53]
>>> sample(52, 10)
[25, 3, 40, 14, 23, 37, 35, 18, 50, 32]
>>> sample(52, 10)
[41, 21, 33, 46, 47, 9, 8, 14, 42, 16]
Next we will want to do two more things:
- Associate each card in the deck with one of these numbers.
- Randomize the order of the selected cards.
Once dealt, we need to be able to score (or at least) sort hands by their value.
There are lots of kinds of power, and each one will have to be modeled differently. It is probably best to start with the simplest game, and build up from there.
You are dealt five cards and you can play them or fold.