Added returning cards from hand at end of game
This commit is contained in:
24
BlackJack.py
24
BlackJack.py
@@ -93,6 +93,10 @@ class Deck():
|
||||
|
||||
def returnFromDiscard(self):
|
||||
self.returnToDeckTop(self.discard.pop())
|
||||
|
||||
def return_all_from_discard(self):
|
||||
self.deck.extend(self.discard)
|
||||
self.discard = []
|
||||
|
||||
def __str__(self) -> str:
|
||||
string = ""
|
||||
@@ -100,6 +104,9 @@ class Deck():
|
||||
string += str(card)
|
||||
return string
|
||||
|
||||
def __len__(self):
|
||||
return len(self.deck)
|
||||
|
||||
class Hand():
|
||||
def __init__(self) -> None:
|
||||
self.hand = []
|
||||
@@ -117,6 +124,9 @@ class Hand():
|
||||
card = self.remove_from_hand(index)
|
||||
card.turn_card()
|
||||
self.add_to_hand(card)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.hand)
|
||||
|
||||
def __str__(self) -> str:
|
||||
string = ""
|
||||
@@ -158,6 +168,11 @@ class BlackJack:
|
||||
|
||||
# Hide one of the dealers cards
|
||||
self.dealerHand.hide_card(1)
|
||||
|
||||
def discard_hand(self, hand):
|
||||
for _ in range(len(hand)):
|
||||
card = hand.remove_from_hand(0)
|
||||
self.deck.addToDiscard(card)
|
||||
|
||||
async def show_cards(self, send, displayDealerScore=False):
|
||||
# Show Cards to player
|
||||
@@ -183,6 +198,7 @@ class BlackJack:
|
||||
if playerHit:
|
||||
self.deal_card(self.playerHand)
|
||||
else:
|
||||
self.dealerHand.hide_card(1)
|
||||
gameState = DEALERTURN
|
||||
|
||||
if int(repr(self.playerHand)) >= 21:
|
||||
@@ -192,7 +208,6 @@ class BlackJack:
|
||||
|
||||
if gameState == DEALERTURN:
|
||||
|
||||
self.dealerHand.hide_card(1)
|
||||
self.deal_card(self.dealerHand)
|
||||
if int(repr(self.dealerHand)) >= 17:
|
||||
gameState = FINISHED
|
||||
@@ -201,6 +216,13 @@ class BlackJack:
|
||||
|
||||
await self.show_cards(send, True)
|
||||
await send("You won or lost idk lmao")
|
||||
self.discard_hand(self.playerHand)
|
||||
self.discard_hand(self.dealerHand)
|
||||
|
||||
if len(self.deck) < 0.25 * 51:
|
||||
self.deck.return_all_from_discard()
|
||||
self.deck.shuffle()
|
||||
await send("Everyday I'm shuffling")
|
||||
gameState = OVER
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user