BlackJack Finished
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
from Ledger import Ledger
|
from Ledger import Ledger
|
||||||
|
|
||||||
#TODO Starting a game with 21 fucks with hidden cards
|
|
||||||
#TODO Look into 5card jack thingo that Tim mentioned
|
#TODO Look into 5card jack thingo that Tim mentioned
|
||||||
#TODO Insurance - If dealer starts with 21, you can bet against it and win your money back
|
#TODO Insurance - If dealer starts with 21, you can bet against it and win your money back
|
||||||
#TODO Make each game session more distinct (Embeds?)
|
#TODO Make each game session more distinct (Embeds?)
|
||||||
@@ -30,9 +29,11 @@ class Card():
|
|||||||
self.suit = suit
|
self.suit = suit
|
||||||
self.hidden = False
|
self.hidden = False
|
||||||
|
|
||||||
def turn_card(self):
|
def hide_card(self):
|
||||||
# XOR to flip hidden element
|
self.hidden = True
|
||||||
self.hidden = self.hidden != True
|
|
||||||
|
def show_card(self):
|
||||||
|
self.hidden = False
|
||||||
|
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
return self.value
|
return self.value
|
||||||
@@ -67,11 +68,11 @@ class Deck():
|
|||||||
self.discard = []
|
self.discard = []
|
||||||
self.joker = joker
|
self.joker = joker
|
||||||
|
|
||||||
self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 13)])
|
self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 14)])
|
||||||
self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 13)])
|
self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 14)])
|
||||||
self.deck.extend([Card(x, Card.SPADES) for x in range(1, 13)])
|
self.deck.extend([Card(x, Card.SPADES) for x in range(1, 14)])
|
||||||
self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 13)])
|
self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 14)])
|
||||||
|
print(len(self.deck))
|
||||||
if joker:
|
if joker:
|
||||||
self.deck.append(Card(0, 0))
|
self.deck.append(Card(0, 0))
|
||||||
|
|
||||||
@@ -113,6 +114,7 @@ class Deck():
|
|||||||
class Hand():
|
class Hand():
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.hand = []
|
self.hand = []
|
||||||
|
self.hidden_cards = []
|
||||||
|
|
||||||
def sortHand(self):
|
def sortHand(self):
|
||||||
self.hand.sort()
|
self.hand.sort()
|
||||||
@@ -130,7 +132,22 @@ class Hand():
|
|||||||
return self.hand[index]
|
return self.hand[index]
|
||||||
|
|
||||||
def hide_card(self, index):
|
def hide_card(self, index):
|
||||||
self.peek_card(index).turn_card()
|
card = self.peek_card(index)
|
||||||
|
card.hide_card()
|
||||||
|
self.hidden_cards.append(card)
|
||||||
|
|
||||||
|
def show_card(self, index):
|
||||||
|
card = self.peek_card(index)
|
||||||
|
card.show_card()
|
||||||
|
try:
|
||||||
|
self.hidden_cards.remove(card)
|
||||||
|
except ValueError:
|
||||||
|
print("Card not hidden")
|
||||||
|
|
||||||
|
def show_hand(self):
|
||||||
|
for card in self.hidden_cards:
|
||||||
|
card.show_card()
|
||||||
|
self.hidden_cards.remove(card)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.hand)
|
return len(self.hand)
|
||||||
@@ -151,7 +168,8 @@ class Hand():
|
|||||||
aces += 1
|
aces += 1
|
||||||
continue
|
continue
|
||||||
if card.value > 10:
|
if card.value > 10:
|
||||||
card.value = 10
|
value += 10
|
||||||
|
continue
|
||||||
value += card.value
|
value += card.value
|
||||||
|
|
||||||
# Dynamically add ace value based on ideal rules
|
# Dynamically add ace value based on ideal rules
|
||||||
@@ -174,7 +192,6 @@ class Hand():
|
|||||||
def __next__(self):
|
def __next__(self):
|
||||||
return next(self.iter)
|
return next(self.iter)
|
||||||
|
|
||||||
|
|
||||||
class BlackJack:
|
class BlackJack:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.deck = Deck()
|
self.deck = Deck()
|
||||||
@@ -196,6 +213,7 @@ class BlackJack:
|
|||||||
self.dealerHand.hide_card(1)
|
self.dealerHand.hide_card(1)
|
||||||
|
|
||||||
def discard_hand(self, hand):
|
def discard_hand(self, hand):
|
||||||
|
hand.show_hand()
|
||||||
for _ in range(len(hand)):
|
for _ in range(len(hand)):
|
||||||
card = hand.remove_from_hand(0)
|
card = hand.remove_from_hand(0)
|
||||||
self.deck.addToDiscard(card)
|
self.deck.addToDiscard(card)
|
||||||
@@ -220,6 +238,9 @@ class BlackJack:
|
|||||||
self.game_setup()
|
self.game_setup()
|
||||||
gameState = PLAYERTURN
|
gameState = PLAYERTURN
|
||||||
|
|
||||||
|
if int(repr(self.playerHand)) >= 21:
|
||||||
|
gameState = FINISHED
|
||||||
|
|
||||||
if gameState == PLAYERTURN:
|
if gameState == PLAYERTURN:
|
||||||
|
|
||||||
await self.show_cards(send)
|
await self.show_cards(send)
|
||||||
@@ -227,13 +248,9 @@ class BlackJack:
|
|||||||
if playerHit:
|
if playerHit:
|
||||||
self.deal_card(self.playerHand)
|
self.deal_card(self.playerHand)
|
||||||
else:
|
else:
|
||||||
#TODO Rename hide_card function
|
|
||||||
self.dealerHand.hide_card(1)
|
|
||||||
gameState = DEALERTURN
|
gameState = DEALERTURN
|
||||||
|
|
||||||
if int(repr(self.playerHand)) >= 21:
|
if int(repr(self.playerHand)) >= 21:
|
||||||
|
|
||||||
self.dealerHand.hide_card(1)
|
|
||||||
gameState = FINISHED
|
gameState = FINISHED
|
||||||
|
|
||||||
if gameState == DEALERTURN:
|
if gameState == DEALERTURN:
|
||||||
@@ -247,6 +264,7 @@ class BlackJack:
|
|||||||
|
|
||||||
if gameState == FINISHED:
|
if gameState == FINISHED:
|
||||||
|
|
||||||
|
self.dealerHand.show_hand()
|
||||||
playerBlackJack = False
|
playerBlackJack = False
|
||||||
dealerBlackJack = False
|
dealerBlackJack = False
|
||||||
playerBust = False
|
playerBust = False
|
||||||
|
|||||||
BIN
src/py/__pycache__/BlackJack.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/BlackJack.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/py/__pycache__/Calculator.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/Calculator.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/py/__pycache__/Gamepicker.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/Gamepicker.cpython-310.pyc
Normal file
Binary file not shown.
BIN
src/py/__pycache__/Ledger.cpython-310.pyc
Normal file
BIN
src/py/__pycache__/Ledger.cpython-310.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user