blackjack-cli 1.0.3__tar.gz → 1.2.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.
@@ -0,0 +1,160 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
@@ -1,20 +1,19 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: blackjack-cli
3
- Version: 1.0.3
3
+ Version: 1.2.0
4
4
  Summary: This is a cli-based blackjack game! Woo!
5
- Home-page: https://github.com/vlek/blackjack-cli
6
- License: GPLv3
7
- Author: Vlek
8
- Author-email: derek@mccammond.org
9
- Requires-Python: >=3.10,<4.0
10
- Classifier: License :: Other/Proprietary License
5
+ Project-URL: Repository, https://github.com/vlek/blackjack-cli
6
+ Author-email: Vlek <derek@mccammond.org>
7
+ License-Expression: GPL-3.0
11
8
  Classifier: Programming Language :: Python :: 3
12
9
  Classifier: Programming Language :: Python :: 3.10
13
10
  Classifier: Programming Language :: Python :: 3.11
14
11
  Classifier: Programming Language :: Python :: 3.12
15
- Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
16
- Requires-Dist: rich-click (>=1.6.1,<2.0.0)
17
- Project-URL: Repository, https://github.com/vlek/blackjack-cli
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Python: <4,>=3.10
15
+ Requires-Dist: pyyaml<7,>=6.0.1
16
+ Requires-Dist: rich-click<2,>=1.6.1
18
17
  Description-Content-Type: text/markdown
19
18
 
20
19
  # Blackjack-cli
@@ -23,4 +22,3 @@ A Python-based Blackjack CLI game
23
22
  Play Blackjack in the terminal!
24
23
 
25
24
  [![asciicast](https://asciinema.org/a/667218.svg)](https://asciinema.org/a/667218)
26
-
@@ -0,0 +1,79 @@
1
+ [project]
2
+ name = "blackjack-cli"
3
+ version = "1.2.0"
4
+ description = "This is a cli-based blackjack game! Woo!"
5
+ authors = [{ name = "Vlek", email = "derek@mccammond.org" }]
6
+ requires-python = ">=3.10,<4"
7
+ readme = "README.md"
8
+ license = "GPL-3.0"
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3",
11
+ "Programming Language :: Python :: 3.10",
12
+ "Programming Language :: Python :: 3.11",
13
+ "Programming Language :: Python :: 3.12",
14
+ "Programming Language :: Python :: 3.13",
15
+ "Programming Language :: Python :: 3.14",
16
+ ]
17
+ dependencies = [
18
+ "rich-click>=1.6.1,<2",
19
+ "pyyaml>=6.0.1,<7",
20
+ ]
21
+
22
+ [project.urls]
23
+ Repository = "https://github.com/vlek/blackjack-cli"
24
+
25
+ [project.scripts]
26
+ blackjack = "blackjack_cli.console:bj"
27
+ bj = "blackjack_cli.console:bj"
28
+ hit = "blackjack_cli.console:hit"
29
+ stand = "blackjack_cli.console:stand"
30
+ stay = "blackjack_cli.console:stand"
31
+
32
+ [dependency-groups]
33
+ dev = [
34
+ "black>=26.5.1,<27",
35
+ "pytest>=8.2.2,<9",
36
+ "coverage>=7.3.1,<8",
37
+ "pre-commit-hooks>=4.4,<6.0",
38
+ "pyupgrade>=3.21.2",
39
+ ]
40
+
41
+ [tool.uv]
42
+ default-groups = "all"
43
+
44
+ [tool.hatch.build.targets.sdist]
45
+ include = [
46
+ "src/blackjack_cli",
47
+ "src/deck",
48
+ ]
49
+
50
+ [tool.hatch.build.targets.wheel]
51
+ include = [
52
+ "src/blackjack_cli",
53
+ "src/deck",
54
+ ]
55
+
56
+ [tool.hatch.build.targets.wheel.sources]
57
+ "src/blackjack_cli" = "blackjack_cli"
58
+ "src/deck" = "deck"
59
+
60
+ [build-system]
61
+ requires = ["hatchling"]
62
+ build-backend = "hatchling.build"
63
+
64
+ [tool.coverage.paths]
65
+ source = ["src", "*/site-packages"]
66
+ tests = ["tests", "*/tests"]
67
+
68
+ [tool.coverage.run]
69
+ parallel = true
70
+ branch = true
71
+ source = ["blackjack-cli"]
72
+ omit = ["tests"]
73
+
74
+ [tool.coverage.report]
75
+ show_missing = false
76
+ fail_under = 90
77
+
78
+ [flake8]
79
+ 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,9 @@ This is going to house things like:
8
8
  """
9
9
 
10
10
  from enum import Enum
11
- from typing_extensions import Self
11
+ from typing import Self
12
12
 
13
- from deck import Deck, Card, CardHand
13
+ from deck import Card, CardHand, Deck
14
14
 
15
15
 
16
16
  def blackjackScoringStrategy(cards: list[Card]) -> int:
@@ -100,28 +100,26 @@ class Blackjack:
100
100
 
101
101
  def performDealersTurn(self) -> Self:
102
102
  """Performs the dealer's moves and finishes the game."""
103
- playersScore: int = self.playersCards.getScore()
104
- dealersScore: int = self.dealersCards.getScore()
103
+ while self.dealersCards.getScore() <= 16:
104
+ self._drawCard(self.dealersCards)
105
105
 
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
106
+ self._calcGameState()
110
107
 
111
- while (dealersScore := self.dealersCards.getScore()) <= 16:
112
- self._drawCard(self.dealersCards)
108
+ return self
113
109
 
114
- dealersScore = self.dealersCards.getScore()
110
+ def _calcGameState(self) -> None:
111
+ """Based on current cards, calculates the gamestate."""
112
+ playersScore: int = self.playersCards.getScore()
113
+ dealersScore: int = self.dealersCards.getScore()
115
114
 
116
- if playersScore > dealersScore or dealersScore > 21:
115
+ if playersScore > 21:
116
+ self.gameState = GameState.Lose
117
+ elif playersScore == dealersScore:
118
+ self.gameState = GameState.Push
119
+ elif playersScore > dealersScore or dealersScore > 21:
117
120
  self.gameState = GameState.Win
118
121
  else:
119
- if playersScore == dealersScore:
120
- self.gameState = GameState.Push
121
- else:
122
- self.gameState = GameState.Lose
123
-
124
- return self
122
+ self.gameState = GameState.Lose
125
123
 
126
124
  def _drawCard(self, hand: CardHand) -> Card | None:
127
125
  """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:
@@ -1,6 +1,6 @@
1
- from typing import Any
1
+ from typing import Any, Self
2
+
2
3
  from blackjack_cli.blackjack import GameState
3
- from typing_extensions import Self
4
4
 
5
5
 
6
6
  class BlackjackStats:
@@ -3,15 +3,18 @@ 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
7
- from typing_extensions import Self
6
+ from typing import Callable, Self
8
7
 
9
- from typing import Callable
8
+ from deck import Card
10
9
 
11
10
 
12
11
  class CardHand:
13
12
 
14
- def __init__(self, cards: list[Card | None], scoringStrategy: Callable[[list[Card]], int] = lambda x: -1) -> None:
13
+ def __init__(
14
+ self,
15
+ cards: list[Card | None],
16
+ scoringStrategy: Callable[[list[Card]], int] = lambda x: -1,
17
+ ) -> None:
15
18
  """Initializes a cardhand."""
16
19
 
17
20
  self.cards: list[Card] = [c for c in cards if c is not None]
@@ -35,3 +38,7 @@ class CardHand:
35
38
  def __str__(self) -> str:
36
39
  """Returns string representation of the cardhand."""
37
40
  return " ".join(str(c) for c in self.cards)
41
+
42
+ def __len__(self) -> int:
43
+ """Returns the length of a given hand."""
44
+ return len(self.cards)
@@ -18,9 +18,10 @@ We have 52 cards:
18
18
  1 Ace
19
19
  """
20
20
 
21
- from deck import Card
22
- from typing_extensions import Self
23
21
  from random import randint
22
+ from typing import Self
23
+
24
+ from deck import Card
24
25
 
25
26
 
26
27
  class Deck:
@@ -1,48 +0,0 @@
1
- [tool.poetry]
2
- name = "blackjack-cli"
3
- version = "1.0.3"
4
- description = "This is a cli-based blackjack game! Woo!"
5
- authors = ["Vlek <derek@mccammond.org>"]
6
- license = "GPLv3"
7
- readme = "README.md"
8
- repository = "https://github.com/vlek/blackjack-cli"
9
- packages = [
10
- { include = "blackjack_cli", from = "src" },
11
- { include = "deck", from = "src" },
12
- ]
13
-
14
- [tool.poetry.dependencies]
15
- python = "^3.10"
16
- rich-click = "^1.6.1"
17
- pyyaml = "^6.0.1"
18
-
19
- [tool.poetry.group.dev.dependencies]
20
- black = "^24.4.2"
21
- pytest = "^8.2.2"
22
- coverage = "^7.3.1"
23
- pre-commit-hooks = "^4.4.0"
24
-
25
- [tool.poetry.scripts]
26
- blackjack = "blackjack_cli.console:bj"
27
- bj = "blackjack_cli.console:bj"
28
- hit = "blackjack_cli.console:hit"
29
- stand = "blackjack_cli.console:stand"
30
- stay = "blackjack_cli.console:stand"
31
-
32
- [tool.coverage.paths]
33
- source = ["src", "*/site-packages"]
34
- tests = ["tests", "*/tests"]
35
-
36
- [tool.coverage.run]
37
- parallel = true
38
- branch = true
39
- source = ["blackjack-cli"]
40
- omit = ["tests"]
41
-
42
- [tool.coverage.report]
43
- show_missing = false
44
- fail_under = 90
45
-
46
- [build-system]
47
- requires = ["poetry-core"]
48
- build-backend = "poetry.core.masonry.api"
@@ -1,2 +0,0 @@
1
- from deck.card import Card
2
- from deck.deck import Deck
File without changes