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.
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/PKG-INFO +1 -1
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/pyproject.toml +4 -1
- blackjack_cli-1.1.0/src/blackjack_cli/__init__.py +5 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/blackjack_cli/blackjack.py +16 -17
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/blackjack_cli/config.py +1 -1
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/deck/cardhand.py +12 -3
- blackjack_cli-1.0.3/src/blackjack_cli/__init__.py +0 -2
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/README.md +0 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/blackjack_cli/console.py +0 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/blackjack_cli/models/__init__.py +0 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/blackjack_cli/models/stats_model.py +0 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/blackjack_cli/stats.py +0 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/deck/__init__.py +0 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/deck/card.py +0 -0
- {blackjack_cli-1.0.3 → blackjack_cli-1.1.0}/src/deck/deck.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "blackjack-cli"
|
|
3
|
-
version = "1.0
|
|
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
|
|
@@ -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
|
|
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
|
-
|
|
104
|
-
|
|
104
|
+
while self.dealersCards.getScore() <= 16:
|
|
105
|
+
self._drawCard(self.dealersCards)
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
if playersScore > 21 or dealersScore == 21:
|
|
108
|
-
self.gameState = GameState.Lose
|
|
109
|
-
return self
|
|
107
|
+
self._calcGameState()
|
|
110
108
|
|
|
111
|
-
|
|
112
|
-
self._drawCard(self.dealersCards)
|
|
109
|
+
return self
|
|
113
110
|
|
|
114
|
-
|
|
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 >
|
|
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
|
-
|
|
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
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
7
8
|
from typing_extensions import Self
|
|
8
9
|
|
|
9
|
-
from
|
|
10
|
+
from deck import Card
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class CardHand:
|
|
13
14
|
|
|
14
|
-
def __init__(
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|