-
Notifications
You must be signed in to change notification settings - Fork 1
/
classes.py
140 lines (104 loc) · 3.94 KB
/
classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import random
import drawCard
class Player:
def __init__(self, name='player', money=0, cards=None, bet=None, points=None):
self.name = name
self.cards = cards
self.money = money
self.bet = bet
self.points = points
self.allin = False
self.minBet = None
self.maxBet = None
def betting(self, bet):
if self.bet == None:
self.bet = 0
if self.money < bet:
bet = self.money
self.money -= bet
self.bet += bet
if self.money == 0:
self.allin = True
def clear(self):
self.cards = None
self.bet = None
self.minBet = None
self.maxBet = None
self.points = None
self.allin = False
def giveCards(self, deck):
self.cards = deck.draw(2)
class Table:
def __init__(self, blind, maxBet, cards=None, pot=0, points=None, allin=False):
self.blind = blind
self.cards = cards
self.pot = pot
self.points = points
self.allin = allin
def clear(self):
self.cards = None
self.pot = 0
self.points=None
self.allin = False
def checkMinMaxBet(self, player, otherPlayers):
"""
Updates min and max bet for player object
player: Player object
otherPlayers: List of Player objects
"""
otherPlayersBets = [each.bet for each in otherPlayers]
if None in otherPlayersBets or player.bet == None :
if all([each == None for each in otherPlayersBets]):
player.minBet = self.blind
# Or player can check
player.maxBet = min(*[each.money for each in otherPlayers], player.money)
else:
otherPlayersBets = [each for each in otherPlayersBets]
otherPlayersBets = [0 if each == None else each for each in otherPlayersBets]
player.minBet = self.blind if max(otherPlayersBets) == 0 else max(otherPlayersBets)
player.maxBet = min([bet + each.money for bet, each in
list(zip(*[[*otherPlayersBets,0], [*otherPlayers,player]]))])
else:
# Everyone has already betted, player included
# consider that player betted 100, other better 200, 300, 400
player.minBet = max(otherPlayersBets) - player.bet
# Accounting all bets+money of players
player.maxBet = min(*[each.bet + each.money for each in otherPlayers], player.bet + player.money)
def addToPot(self, players):
self.pot = self.pot + sum([player.bet for player in players if player.bet != None])
for i in range(len(players)):
players[i].bet = None
def payPlayer(self, player):
player.money += self.pot
self.pot = 0
def isALLIN(self, players):
if True in [player.allin for player in players]:
self.allin = True
def flop(self, deck):
if self.cards == None:
self.cards = deck.draw(3)
elif len(self.cards) == 3 or len(self.cards) == 4:
self.cards += deck.draw(1)
class Card:
def __init__(self, number, suit, image=None):
self.number = number
self.suit = suit
self.image = image
def addImage(self):
self.image = drawCard.main(self)
class Deck:
def __init__(self):
numbers = [x for x in range(2,15)]
deck = []
for y in ["♥", "♦", "♣", "♠"]:
for x in numbers:
deck.append(Card(x, y))
random.shuffle(deck)
self.deck = deck
def draw(self, number):
drawn, self.deck = self.deck[:number], self.deck[number:]
for i in range(len(drawn)):
drawn[i].addImage()
return drawn
def remove(self, card):
[self.deck.remove(each) for each in self.deck if card.number == each.number and card.suit == each.suit]