Compare commits

..

4 Commits

Author SHA1 Message Date
e2c99dfea4 made game playable 2025-11-08 21:31:36 +01:00
d57022f742 cleanup 2025-11-06 20:00:39 +01:00
a3aa761739 added test for Player() 2025-11-06 20:00:22 +01:00
4222e76262 added exception for keyboard interrupt 2025-11-06 19:44:05 +01:00
3 changed files with 56 additions and 6 deletions

View File

@@ -11,8 +11,8 @@ class Game:
def __init__(self) -> None: def __init__(self) -> None:
"""Creates instances of 'Deck', 'Player', and 'Dealer'.""" """Creates instances of 'Deck', 'Player', and 'Dealer'."""
self.deck = Deck() self.deck = Deck()
self.player = Player(0) self.player = Player(100)
self.dealer = Dealer(1000) self.dealer = Dealer(10000)
def compare_hands(self, bet: float) -> str: def compare_hands(self, bet: float) -> str:
"""*Resolution/Payout*: Compares final hand values, checks for """*Resolution/Payout*: Compares final hand values, checks for
@@ -103,6 +103,20 @@ class Game:
player = self.player player = self.player
dealer = self.dealer dealer = self.dealer
# TODO: implement logic for setting the bet and passing the
# value to the hand comparison. Also keep the chip ammount of
# the player over multiple rounds.
# player starts with x amount and bets per round from his
# current chips. Internally the chips are handled as a float
# the player gets to see the float number as 'IS' and the
# rounded down number as 'Payout'
# HACK: this is just to fuck around and find out...
player_bet = input("How much do you want to bet?")
# player.chips += float(player_bet)
# Beginning of the round, the deck gets shuffled and all the # Beginning of the round, the deck gets shuffled and all the
# player cards are shown, while the dealer only shows one card. # player cards are shown, while the dealer only shows one card.
deck.shuffle() deck.shuffle()
@@ -131,7 +145,9 @@ class Game:
# Comparing hands and returning the winner of the game. # Comparing hands and returning the winner of the game.
os.system("clear") os.system("clear")
print(self.compare_hands(0)) print(self.compare_hands(float(player_bet)))
print(f"Player Chips: {player.chips}")
print(f"Dealer Chips: {dealer.chips}")
# After each full round, the players and dealers hand get # After each full round, the players and dealers hand get
# cleared and a new deck is created. # cleared and a new deck is created.

View File

@@ -7,7 +7,13 @@ if __name__ == "__main__":
print("pyjack by cerberus") print("pyjack by cerberus")
print("do you wanna play a round??") print("do you wanna play a round??")
# Create game instance with the player and dealer
game = Game() game = Game()
while True:
# os.system("clear") # Play the game
game.play_round() try:
while True:
game.play_round()
except KeyboardInterrupt:
print("End Program")

28
tests/test_player.py Normal file
View File

@@ -0,0 +1,28 @@
import pytest
from pyjack.player import Player
from pyjack.deck import Deck
# Start Fixtures
@pytest.fixture
def player() -> Player:
"""Fixture for the player test."""
player = Player(0)
return player
@pytest.fixture
def deck() -> Deck:
deck = Deck()
return deck
# Start Tests:
def test_player_hit_one_card(player, deck):
player.hit(deck)
assert len(player.hand.cards) == 1