Started working on rewriting blackjack
This commit is contained in:
53
BlackJack.py
53
BlackJack.py
@@ -84,7 +84,7 @@ def showDeck(deck):
|
||||
|
||||
class BlackJack:
|
||||
def __init__(self):
|
||||
self.gameState = INIT
|
||||
self.gameInSession = False
|
||||
self.playerTurn = True
|
||||
self.deck = generateDeck()
|
||||
random.shuffle(self.deck)
|
||||
@@ -93,12 +93,6 @@ class BlackJack:
|
||||
self.dealerHand = []
|
||||
self.ledger = Ledger.Ledger()
|
||||
|
||||
def getPH(self):
|
||||
return self.playerHand
|
||||
|
||||
def getDH(self):
|
||||
return self.dealerHand
|
||||
|
||||
def returnCards(self):
|
||||
self.discard.extend(self.playerHand)
|
||||
self.playerHand.clear()
|
||||
@@ -164,30 +158,38 @@ class BlackJack:
|
||||
|
||||
async def play_game(self, ID, bet, recv, send):
|
||||
|
||||
self.gameState = INIT
|
||||
if self.gameInSession:
|
||||
await send("Fuck you")
|
||||
return
|
||||
else:
|
||||
self.gameInSession = True
|
||||
gameState = INIT
|
||||
|
||||
while self.gameState != OVER:
|
||||
while gameState != OVER:
|
||||
|
||||
if self.gameState == INIT:
|
||||
if gameState == INIT:
|
||||
|
||||
self.returnCards()
|
||||
playerStats = self.ledger.read(ID)
|
||||
if playerStats is None:
|
||||
self.ledger.write(ID)
|
||||
playerStats = self.ledger.read(ID)
|
||||
self.deal()
|
||||
|
||||
playerWinState = self.checkHandState(self.playerHand)
|
||||
dealerWinState = self.checkHandState(self.dealerHand)
|
||||
|
||||
play = None
|
||||
self.playerTurn = True
|
||||
playerStood = False
|
||||
dealerStood = False
|
||||
validInput = False
|
||||
self.gameState = PLAYING
|
||||
|
||||
gameState = CHECKING
|
||||
|
||||
elif self.gameState == PLAYING:
|
||||
elif gameState == PLAYING:
|
||||
|
||||
await send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(
|
||||
self.playerHand) + "\n" + "Dealers hand = ??: " + convertNumberToCard(self.dealerHand[0]) + "??")
|
||||
play = await recv("Hit or Stand? (h/s)")
|
||||
play = await recv("Hit or Stand?")
|
||||
while not validInput:
|
||||
if play == "h":
|
||||
self.hit()
|
||||
@@ -197,12 +199,12 @@ class BlackJack:
|
||||
playerStood = True
|
||||
validInput = True
|
||||
|
||||
self.dealerHitLogic()
|
||||
dealerStood = self.dealerHitLogic()
|
||||
playerWinState = self.checkHandState(self.playerHand)
|
||||
dealerWinState = self.checkHandState(self.dealerHand)
|
||||
self.gameState = CHECKING
|
||||
gameState = CHECKING
|
||||
|
||||
elif self.gameState == ENDING:
|
||||
elif gameState == ENDING:
|
||||
|
||||
# Players turn
|
||||
self.stand()
|
||||
@@ -215,18 +217,18 @@ class BlackJack:
|
||||
if dealerWinState == "c":
|
||||
|
||||
dealerWinState = self.compareHands()
|
||||
self.gameState = CHECKING
|
||||
gameState = CHECKING
|
||||
|
||||
elif self.gameState == CHECKING:
|
||||
elif gameState == CHECKING:
|
||||
|
||||
if self.checkGameOver(playerWinState) or self.checkGameOver(dealerWinState):
|
||||
self.gameState = FINISHED
|
||||
gameState = FINISHED
|
||||
elif playerStood:
|
||||
self.gameState = ENDING
|
||||
gameState = ENDING
|
||||
else:
|
||||
self.gameState = PLAYING
|
||||
gameState = PLAYING
|
||||
|
||||
elif self.gameState == FINISHED:
|
||||
elif gameState == FINISHED:
|
||||
|
||||
await send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(self.playerHand) +
|
||||
"\n" + "Dealers hand = " + str(getHandTotal(self.dealerHand)) + ": " + handNumbersToCards(self.dealerHand))
|
||||
@@ -252,4 +254,5 @@ class BlackJack:
|
||||
await send("Shuffling Deck")
|
||||
self.shuffle()
|
||||
|
||||
self.gameState = OVER
|
||||
gameState = OVER
|
||||
self.gameInSession = False
|
||||
|
||||
Reference in New Issue
Block a user