-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
125 lines (96 loc) · 2.97 KB
/
main.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
from Card import Card
from Stack import Stack
from Queue import Queue
from Player import Player
from os import system
from time import sleep
def isValueLegal(cardValue: str | int) -> bool:
'''
Check if card value is legal
# Returns:
True if the cardValue is in a standard deck of card else False
'''
if cardValue == "ace":
return True
if cardValue == "king":
return True
if cardValue == "queen":
return True
if cardValue == "jack":
return True
return ((cardValue.isnumeric()) and (int(cardValue) in range(2, 11)))
def isSuitLegal(suit: str) -> bool:
if suit == "hearts":
return True
if suit == "spades":
return True
if suit == "clubs":
return True
if suit == "diamonds":
return True
return False
def getPlayerNum(order) -> int:
return order.peak().player
def eliminatePlayer(deck: Stack, order: Queue, playerNum: int) -> None:
print(f"Player {playerNum} you lose. Next round.")
order.dequeue()
order.moveBack()
deck.clear()
for ii in range(order.size):
order.peak().setRemove = False
order.moveBack()
def cardGame() -> None:
deck = Stack()
players = 0
print("Enter a card and ensure that there are no repeat cards in the deck of 52. Each player is allowed to remove only the top card once per round. At the end of the round the player who goes next will now go last. At the end of each round the deck resets, so there are 52 available cards to choose from at the start of each round")
while((players < 2) or (players > 53)):
print("The game must have more than 1 player, but less than 53.")
try:
players = int(input("Enter number of players: "))
except:
print("Only enter numbers that are > 1, but < 54")
order = Queue()
for ii in range(1, players+1):
order.enqueue(Player(ii))
del players
playerNum = getPlayerNum(order)
while order.size > 1:
playerNum = getPlayerNum(order)
cardSuit = input(f"Player {playerNum} enter the card's suit (i.e hearts, spades, clubs, or diamonds) or enter \"remove\": ").lower().strip()
if cardSuit == "remove":
if order.peak().usedRemove == False:
deck.pop()
order.peak().setRemove = True
order.moveBack()
continue
else:
eliminatePlayer(deck, order, playerNum)
continue
elif isSuitLegal(cardSuit) == False:
eliminatePlayer(deck, order, playerNum)
continue
cardValue = input(f"Player {playerNum} enter the card's value (2 - 10 or Ace - King): ").lower().strip()
if isValueLegal(cardValue) == False:
eliminatePlayer(deck, order, playerNum)
continue
card = Card(cardSuit, cardValue)
if deck.contains(card):
eliminatePlayer(deck, order, playerNum)
continue
deck.push(card)
if deck.size >= 52:
if order.size > 2:
order.moveBack()
playerNum = getPlayerNum(order)
order.dequeue()
print(f"Player {playerNum} You lose. Next round")
deck.clear()
else:
print(f"Player {playerNum} won")
break
order.moveBack()
sleep(0.5)
system("clear")
print(f"Player {getPlayerNum(order)} won")
if __name__ == "__main__":
cardGame()