import random
import pandas as pd
import numpy as np
from IPython.display import clear_output
import seaborn
import matplotlib.pyplot as plt
class freshDeck:
def __init__(self):
suits = ['Spades','Hearts','Diamonds','Clubs']
values = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
cards = []
for suit in suits:
for value in values:
cards.append([suit,value])
cards = pd.DataFrame(cards,columns={'Value','Suit'})
self.table = cards
class shuffleDeck:
def __init__(self,cards):
shuffled = cards.sample(frac = 1).reset_index()
shuffled = shuffled.drop(columns='index')
self.table = shuffled
class dealCards:
def __init__(self,player_count):
global deck
players_cards = []
for player in range(1,player_count+1):
for x in range(2):
drop_indices = np.random.choice(deck.index, 1, replace=False)
ind = int(drop_indices)
pick = deck.loc[ind]
deck = deck.drop([ind],axis=0).reset_index().drop(columns='index')
players_cards.append([player,pick['Value'],pick['Suit']])
players_cards = pd.DataFrame(players_cards)
players_cards = players_cards.rename(columns={0:'Player',1:'Value',2:'Suit'})
self.table = players_cards
class deckStats:
def __init__(self):
global evalevalDeck
suitGroups = evalDeck.groupby('Suit')
valueGroups = evalDeck.groupby('Value')
suitStats = []
valueStats = []
for x in suitGroups.groups:
s = suitGroups.get_group(x)
amount = str(len(s))
suitStats.append([x,amount])
for x in valueGroups.groups:
s = valueGroups.get_group(x)
amount = str(len(s))
valueStats.append([x,amount])
statsoverall = pd.DataFrame(valueStats).sort_index().T
statsoverall.columns = statsoverall.iloc[0]
statsoverall = statsoverall[1:]
statsoverall = statsoverall[['A']+['K']+['Q']+['J']+[str(col) for col in range(10,1,-1)]]
matrix_dict = {}
for i in statsoverall.columns:
matrix_dict[i] = []
for j in statsoverall.columns:
if statsoverall[j].name == statsoverall[i].name:
result = (int(statsoverall[j])*int(statsoverall[i]))/2
matrix_dict[i].append(result)
else:
result = (int(statsoverall[j])*int(statsoverall[i]))
matrix_dict[i].append(result)
dataMatrix = np.matrix([matrix_dict[i] for i in statsoverall.columns])
self.dataMatrix = dataMatrix
class flop:
def __init__(self):
global deck
flop_cards = []
for x in range(3):
drop_indices = np.random.choice(deck.index, 1, replace=False)
ind = int(drop_indices)
pick = deck.loc[ind]
deck = deck.drop([ind],axis=0).reset_index().drop(columns='index')
flop_cards.append([pick['Value'],pick['Suit']])
flop_cards = pd.DataFrame(flop_cards,columns={'Value','Suit'})
self.table = flop_cards
class turn:
def __init__(self):
global deck
turn_card = []
for x in range(1):
drop_indices = np.random.choice(deck.index, 1, replace=False)
ind = int(drop_indices)
pick = deck.loc[ind]
deck = deck.drop([ind],axis=0).reset_index().drop(columns='index')
turn_card.append([pick['Value'],pick['Suit']])
turn_card = pd.DataFrame(turn_card,columns={'Value','Suit'})
self.table = turn_card
class river:
def __init__(self):
global deck
river_card = []
for x in range(1):
drop_indices = np.random.choice(deck.index, 1, replace=False)
ind = int(drop_indices)
pick = deck.loc[ind]
deck = deck.drop([ind],axis=0).reset_index().drop(columns='index')
river_card.append([pick['Value'],pick['Suit']])
river_card = pd.DataFrame(river_card,columns={'Value','Suit'})
self.table = river_card
class play:
def __init__(self,player_count):
clear_output(wait=True)
global deck
global evalDeck
fresh = freshDeck().table
deck = shuffleDeck(fresh).table
dealt = dealCards(player_count).table
columns = ['A','K','Q','J','10','9','8','7','6','5','4','3','2']
hands = dealt.groupby('Player')
yourHand = hands.get_group(1)
display(yourHand)
evalHand = dealt[2:].drop(columns={'Player'})
evalDeck = pd.concat([deck,evalHand],ignore_index=True)
ds = deckStats()
seaborn.heatmap(ds.dataMatrix,xticklabels=columns,yticklabels=columns)
plt.show()
choice1 = input('Fold? (f) Check/Call? (c) Raise? (r) Quit? (x)')
if choice1 == 'f':
play(player_count)
elif choice1 == 'r' or choice1 == 'c':
theFlop = flop().table
display(theFlop)
evalDeck = pd.concat([deck,evalHand],ignore_index=True)
ds = deckStats()
seaborn.heatmap(ds.dataMatrix,xticklabels=columns,yticklabels=columns)
plt.show()
choice2 = input('Fold? (f) Check/Call? (c) Raise? (r) Quit? (x)')
if choice2 == 'f':
play(player_count)
elif choice2 == 'r' or choice2 == 'c':
theTurn = turn().table
display(theTurn)
evalDeck = pd.concat([deck,evalHand],ignore_index=True)
ds = deckStats()
seaborn.heatmap(ds.dataMatrix,xticklabels=columns,yticklabels=columns)
plt.show()
choice3 = input('Fold? (f) Check/Call? (c) Raise? (r) Quit? (x)')
if choice3 == 'f':
play(player_count)
elif choice3 == 'r' or choice3 == 'c':
theRiver = river().table
display(theRiver)
evalDeck = pd.concat([deck,evalHand],ignore_index=True)
ds = deckStats()
seaborn.heatmap(ds.dataMatrix,xticklabels=columns,yticklabels=columns)
plt.show()
leng = len(dealt) - 2
display(dealt[len(dealt)-leng:])
choice4 = input('Next Hand? (return) Quit? (x)')
if choice4 == '':
play(player_count)
elif choice4 == 'x':
quit
elif choice3 == 'x':
quit
elif choice2 == 'x':
quit
elif choice1 == 'x':
quit
player_count = 6
play(player_count)
Player | Value | Suit | |
---|---|---|---|
0 | 1 | 10 | Spades |
1 | 1 | 10 | Diamonds |
Suit | Value | |
---|---|---|
0 | K | Hearts |
1 | 3 | Clubs |
2 | J | Clubs |
Suit | Value | |
---|---|---|
0 | Q | Spades |
Suit | Value | |
---|---|---|
0 | 7 | Spades |
Player | Value | Suit | |
---|---|---|---|
2 | 2 | 10 | Hearts |
3 | 2 | Q | Hearts |
4 | 3 | A | Hearts |
5 | 3 | 2 | Clubs |
6 | 4 | 10 | Clubs |
7 | 4 | 9 | Clubs |
8 | 5 | Q | Clubs |
9 | 5 | 3 | Hearts |
10 | 6 | 8 | Clubs |
11 | 6 | K | Diamonds |
<__main__.play at 0x18b0d144100>