57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
|
|
from pyjack import hand, player
|
||
|
|
from pyjack import dealer
|
||
|
|
from pyjack.dealer import Dealer
|
||
|
|
from pyjack.deck import Deck
|
||
|
|
from pyjack.player import Player
|
||
|
|
|
||
|
|
|
||
|
|
class Game:
|
||
|
|
"""The Game class is the central coordinator, managing the flow of
|
||
|
|
the entire round, from setup to payout."""
|
||
|
|
|
||
|
|
def __init__(self) -> None:
|
||
|
|
"""Creates instances of 'Deck', 'Player', and 'Dealer'."""
|
||
|
|
self.deck = Deck()
|
||
|
|
self.player = Player(0)
|
||
|
|
self.dealer = Dealer(1000)
|
||
|
|
|
||
|
|
def compare_hands(self, bet: int) -> str:
|
||
|
|
"""*Resolution/Payout*: Compares final hand values, checks for
|
||
|
|
Bust, Blackjack, and highest value.
|
||
|
|
|
||
|
|
*Updates* player.chips based on the outcome and the bet.
|
||
|
|
|
||
|
|
*Returns* the result string (e.g., "Player Wins!")."""
|
||
|
|
|
||
|
|
# HACK: this might work but certainly needs to be fixed.
|
||
|
|
|
||
|
|
# check if Player or Dealer busts
|
||
|
|
if self.player.hand.value > 21:
|
||
|
|
return "Player Lost"
|
||
|
|
elif self.dealer.hand.value > 21 and self.player.hand.value < 22:
|
||
|
|
self.player.chips += bet
|
||
|
|
return "Player Wins"
|
||
|
|
elif self.dealer.hand.value < 22 and self.player.hand.value < 22:
|
||
|
|
# Checks for Blackjack
|
||
|
|
if self.player.hand.value == 21 and self.dealer.hand.value != 21:
|
||
|
|
return "Player Wins 3:2"
|
||
|
|
else:
|
||
|
|
if self.dealer.hand.value == 21:
|
||
|
|
if self.player.hand.value == 21:
|
||
|
|
return "Tie"
|
||
|
|
else:
|
||
|
|
return "Player Lost"
|
||
|
|
|
||
|
|
# Checks the values if either the Player busts or has
|
||
|
|
# Blackjack
|
||
|
|
elif self.player.hand.value > self.dealer.hand.value:
|
||
|
|
return "Player Wins"
|
||
|
|
else:
|
||
|
|
if self.player.hand.value == self.dealer.hand.value:
|
||
|
|
return "Tie"
|
||
|
|
else:
|
||
|
|
return "Player Lost"
|
||
|
|
|
||
|
|
else:
|
||
|
|
return "Values could not be compared."
|