-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
53 lines (43 loc) · 1.05 KB
/
game.py
File metadata and controls
53 lines (43 loc) · 1.05 KB
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
from card import Card
from player import Player
from random import shuffle
class Game:
def __init__(self):
self.players = []
self.deck = []
self.scrap = []
self.turn = 0
self.oneOff = None
self.log = []
# Initialize deck
for i in range(4):
for j in range(1,14):
self.deck.append(Card(i, j))
# Create players
self.players.append(Player())
self.players.append(Player())
# deal
shuffle(self.deck)
self.players[1].hand.append(self.deck.pop(-1))
for i in range(5):
self.players[0].hand.append(self.deck.pop(-1))
self.players[1].hand.append(self.deck.pop(-1))
def print(self):
if len(self.log) > 0:
print(self.log[-1])
print("Player 0:")
self.players[0].print()
print("\nPlayer 1:")
self.players[1].print()
print("\n")
# for i, player in enumerate(self.players):
# print("\nPlayer %s:" %i)
# player.print()
# Returns None unless game is over, then returns index of winner
def winner(self):
res = None
if self.players[0].wins():
res = 0
elif self.players[1].wins():
res = 1
return res