-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
51 lines (43 loc) · 1.34 KB
/
game.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
import random
from card import Card
from player import Player
class TexasHoldem:
def __init__(self, player_count, players = []):
self.players = players
self.board = None
self.state = None
# init players
if not players:
for i in range(1, player_count+1):
player = Player(name='player '+str(i))
self.players.append(player)
# generate deck
deck = []
suit = ['s','c','h','d']
val = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
for i in suit:
for j in val:
temp = Card(val=j, suit=i)
deck.append(temp)
random.shuffle(deck)
self.deck = deck
def preflop(self):
for i in self.players:
i.hand1 = self.deck.pop()
for i in self.players:
i.hand2 = self.deck.pop()
self.state = 'preflop'
def flop(self):
self.deck.pop() # burn 1
self.board = [self.deck.pop() for __ in range(3)]
self.state = 'flop'
def turn(self):
self.deck.pop() # burn 2
out = self.deck.pop()
self.board.append(out)
self.state = 'turn'
def river(self):
self.deck.pop() # burn 3
out = self.deck.pop()
self.board.append(out)
self.state = 'river'