blackjack-cli 1.0.3__tar.gz → 1.1.0__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.3
3
+ Version: 1.1.0
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,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "blackjack-cli"
3
- version = "1.0.3"
3
+ version = "1.1.0"
4
4
  description = "This is a cli-based blackjack game! Woo!"
5
5
  authors = ["Vlek <derek@mccammond.org>"]
6
6
  license = "GPLv3"
@@ -46,3 +46,6 @@ fail_under = 90
46
46
  [build-system]
47
47
  requires = ["poetry-core"]
48
48
  build-backend = "poetry.core.masonry.api"
49
+
50
+ [flake8]
51
+ max-line-length = 88
@@ -0,0 +1,5 @@
1
+ from blackjack_cli.blackjack import Blackjack
2
+ from deck.card import Card
3
+ from deck.deck import Deck
4
+
5
+ __all__ = ["Card", "Deck", "Blackjack"]
@@ -8,9 +8,10 @@ This is going to house things like:
8
8
  """
9
9
 
10
10
  from enum import Enum
11
+
11
12
  from typing_extensions import Self
12
13
 
13
- from deck import Deck, Card, CardHand
14
+ from deck import Card, CardHand, Deck
14
15
 
15
16
 
16
17
  def blackjackScoringStrategy(cards: list[Card]) -> int:
@@ -100,28 +101,26 @@ class Blackjack:
100
101
 
101
102
  def performDealersTurn(self) -> Self:
102
103
  """Performs the dealer's moves and finishes the game."""
103
- playersScore: int = self.playersCards.getScore()
104
- dealersScore: int = self.dealersCards.getScore()
104
+ while self.dealersCards.getScore() <= 16:
105
+ self._drawCard(self.dealersCards)
105
106
 
106
- # If the player bust or the dealer got blackjack
107
- if playersScore > 21 or dealersScore == 21:
108
- self.gameState = GameState.Lose
109
- return self
107
+ self._calcGameState()
110
108
 
111
- while (dealersScore := self.dealersCards.getScore()) <= 16:
112
- self._drawCard(self.dealersCards)
109
+ return self
113
110
 
114
- dealersScore = self.dealersCards.getScore()
111
+ def _calcGameState(self) -> None:
112
+ """Based on current cards, calculates the gamestate."""
113
+ playersScore: int = self.playersCards.getScore()
114
+ dealersScore: int = self.dealersCards.getScore()
115
115
 
116
- if playersScore > dealersScore or dealersScore > 21:
116
+ if playersScore > 21:
117
+ self.gameState = GameState.Lose
118
+ elif playersScore == dealersScore:
119
+ self.gameState = GameState.Push
120
+ elif playersScore > dealersScore or dealersScore > 21:
117
121
  self.gameState = GameState.Win
118
122
  else:
119
- if playersScore == dealersScore:
120
- self.gameState = GameState.Push
121
- else:
122
- self.gameState = GameState.Lose
123
-
124
- return self
123
+ self.gameState = GameState.Lose
125
124
 
126
125
  def _drawCard(self, hand: CardHand) -> Card | None:
127
126
  """Draws a card and places it into the given hand."""
@@ -31,7 +31,7 @@ class Config:
31
31
  self.config_folder_path: Path = self.config_file_path.parent
32
32
 
33
33
  if not self.config_folder_path.exists():
34
- self.config_folder_path.mkdir()
34
+ self.config_folder_path.mkdir(parents=True)
35
35
 
36
36
  if self.config_file_path.exists():
37
37
  with self.config_file_path.open() as config_file:
@@ -3,15 +3,20 @@ This deals with holding and evaluating cards that
3
3
  a player has in their hand.
4
4
  """
5
5
 
6
- from deck import Card
6
+ from typing import Callable
7
+
7
8
  from typing_extensions import Self
8
9
 
9
- from typing import Callable
10
+ from deck import Card
10
11
 
11
12
 
12
13
  class CardHand:
13
14
 
14
- def __init__(self, cards: list[Card | None], scoringStrategy: Callable[[list[Card]], int] = lambda x: -1) -> None:
15
+ def __init__(
16
+ self,
17
+ cards: list[Card | None],
18
+ scoringStrategy: Callable[[list[Card]], int] = lambda x: -1,
19
+ ) -> None:
15
20
  """Initializes a cardhand."""
16
21
 
17
22
  self.cards: list[Card] = [c for c in cards if c is not None]
@@ -35,3 +40,7 @@ class CardHand:
35
40
  def __str__(self) -> str:
36
41
  """Returns string representation of the cardhand."""
37
42
  return " ".join(str(c) for c in self.cards)
43
+
44
+ def __len__(self) -> int:
45
+ """Returns the length of a given hand."""
46
+ return len(self.cards)
@@ -1,2 +0,0 @@
1
- from deck.card import Card
2
- from deck.deck import Deck
File without changes