blackjack-cli 1.0.2__tar.gz → 1.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: blackjack-cli
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: This is a cli-based blackjack game! Woo!
5
5
  Home-page: https://github.com/vlek/blackjack-cli
6
6
  License: GPLv3
@@ -1,11 +1,15 @@
1
1
  [tool.poetry]
2
2
  name = "blackjack-cli"
3
- version = "1.0.2"
3
+ version = "1.0.3"
4
4
  description = "This is a cli-based blackjack game! Woo!"
5
5
  authors = ["Vlek <derek@mccammond.org>"]
6
6
  license = "GPLv3"
7
7
  readme = "README.md"
8
8
  repository = "https://github.com/vlek/blackjack-cli"
9
+ packages = [
10
+ { include = "blackjack_cli", from = "src" },
11
+ { include = "deck", from = "src" },
12
+ ]
9
13
 
10
14
  [tool.poetry.dependencies]
11
15
  python = "^3.10"
@@ -0,0 +1,5 @@
1
+ from deck.card import Card
2
+ from deck.deck import Deck
3
+ from deck.cardhand import CardHand
4
+
5
+ __all__ = ["Card", "Deck", "CardHand"]
@@ -0,0 +1,49 @@
1
+ """
2
+ Handles the logic for a single Card within a Deck.
3
+ """
4
+
5
+ from enum import Enum
6
+
7
+
8
+ class Card:
9
+ class Suit(Enum):
10
+ SPADES = "♠"
11
+ CLUBS = "♣"
12
+ DIAMONDS = "♦"
13
+ HEARTS = "♥"
14
+
15
+ class Value(Enum):
16
+ TWO = 2
17
+ THREE = 3
18
+ FOUR = 4
19
+ FIVE = 5
20
+ SIX = 6
21
+ SEVEN = 7
22
+ EIGHT = 8
23
+ NINE = 9
24
+ TEN = 10
25
+ JACK = "J"
26
+ QUEEN = "Q"
27
+ KING = "K"
28
+ ACE = "A"
29
+
30
+ def __init__(self, suit: Suit, value: Value) -> None:
31
+ self.suit = suit
32
+ self.value = value
33
+
34
+ def __str__(self) -> str:
35
+ """Returns the string representation of a Card."""
36
+ return f"{self.suit.value}{self.value.value}"
37
+
38
+ def __eq__(self, otherCard) -> bool:
39
+ """Determine whether one card is the same as the other."""
40
+ return self.suit == otherCard.suit and self.value == otherCard.value
41
+
42
+
43
+ if __name__ == "__main__":
44
+ card = Card(Card.Suit.SPADES, Card.Value.ACE)
45
+ otherCard = Card(Card.Suit.SPADES, Card.Value.ACE)
46
+
47
+ print(card)
48
+
49
+ print(card == otherCard)
@@ -0,0 +1,37 @@
1
+ """
2
+ This deals with holding and evaluating cards that
3
+ a player has in their hand.
4
+ """
5
+
6
+ from deck import Card
7
+ from typing_extensions import Self
8
+
9
+ from typing import Callable
10
+
11
+
12
+ class CardHand:
13
+
14
+ def __init__(self, cards: list[Card | None], scoringStrategy: Callable[[list[Card]], int] = lambda x: -1) -> None:
15
+ """Initializes a cardhand."""
16
+
17
+ self.cards: list[Card] = [c for c in cards if c is not None]
18
+ self.scoringStrategy = scoringStrategy
19
+
20
+ def setScoringStrategy(self, scoringStrategy: Callable[[list[Card]], int]) -> Self:
21
+ """Sets the strategy for how to score the given hand."""
22
+ self.scoringStrategy = scoringStrategy
23
+ return self
24
+
25
+ def getScore(self) -> int:
26
+ """Returns the score of the current hand with the given strategy."""
27
+ return self.scoringStrategy(self.cards)
28
+
29
+ def add(self, card: Card | None) -> Self:
30
+ """Add a card to the player's hand."""
31
+ if card is not None:
32
+ self.cards.append(card)
33
+ return self
34
+
35
+ def __str__(self) -> str:
36
+ """Returns string representation of the cardhand."""
37
+ return " ".join(str(c) for c in self.cards)
@@ -0,0 +1,73 @@
1
+ """
2
+ Logic for having a deck of cards.
3
+
4
+ NOTE: THIS DOES NOT NECESSARILY HAVE ANYTHING TO DO WITH BLACKJACK!
5
+
6
+ We have 52 cards:
7
+ 4 Suits:
8
+ Clubs, Spades, Hearts, Diamonds
9
+
10
+ 9 Number cards:
11
+ 2 - 10
12
+
13
+ 3 Face cards:
14
+ Jack
15
+ Queen
16
+ King
17
+
18
+ 1 Ace
19
+ """
20
+
21
+ from deck import Card
22
+ from typing_extensions import Self
23
+ from random import randint
24
+
25
+
26
+ class Deck:
27
+ def __init__(self) -> None:
28
+ self.cards: list[Card] = []
29
+ self.isShuffled = False
30
+ self.__add_cards()
31
+
32
+ def shuffle(self) -> Self:
33
+ """Returns the deck of cards shuffled."""
34
+ self.isShuffled = True
35
+ return self
36
+
37
+ def draw(self) -> Card | None:
38
+ """Returns a card from the deck."""
39
+ result: Card | None
40
+
41
+ if len(self.cards) == 0:
42
+ result = None
43
+ elif self.isShuffled:
44
+ cardChoice: int = randint(0, len(self.cards) - 1)
45
+ result = self.cards.pop(cardChoice)
46
+ else:
47
+ result = self.cards.pop()
48
+
49
+ return result
50
+
51
+ def __add__(self, otherDeck: Self) -> Self:
52
+ """Puts to decks of cards together."""
53
+ self.cards += otherDeck.cards
54
+
55
+ return self
56
+
57
+ def __len__(self) -> int:
58
+ """Returns the number of cards in the deck."""
59
+ return len(self.cards)
60
+
61
+ def __mul__(self, num: int) -> Self:
62
+ """Duplicates the cards in the deck num times."""
63
+ self.cards *= num
64
+
65
+ return self
66
+
67
+ def __add_cards(self) -> Self:
68
+ """Adds initial cards to the deck."""
69
+ for suit in Card.Suit:
70
+ for value in Card.Value:
71
+ self.cards.append(Card(suit, value))
72
+
73
+ return self
File without changes