Hello, here's my implementation of python. I would like to receive some feedback on my code, which is my first try on a slightly complex project. In particular I'm not too satisfied with the check_hand() method, I was thinking about changing it to a value property. I am aware not everything is done, for instance pair splitting. Thanks!
#๐ Blackjack OOP
41 messages ยท Page 1 of 1 (latest)
@versed remnant
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
First minor suggestion is following types properly
also, is that repository fully up to date?
it has from card import Card, Deck, Player, Dealer but there is no card.py
(3.13.5) luna@msi-arch ~/Downloads/Blackjack (main) $ tree
.
โโโ blackjack.py
โโโ game_objects.py
โโโ main.py
โโโ __pycache__
โ โโโ card.cpython-310.pyc
โ โโโ card.cpython-312.pyc
โ โโโ game.cpython-312.pyc
โ โโโ test_card.cpython-312.pyc
โ โโโ test_check_hand.cpython-312.pyc
โโโ test_card.py
โโโ test_check_hand.py
the file test_card.py has this line ^^
oh, that's odd, I just pushed it. let me fix that
now it is
Doesn't seem to exist
make sure you've added it with git add
committed with git commit -m "message"
and then pushed
jup I added it with git add .
then it shouldn't be from card import ...
it should be from game_objects import ...
your tests will fail in their current state
im not the one who wrote it
I didn't reply to your message did I?
I updated it, the version on github is up to date
one more pull and i'll take another look
It does look pretty decent, your Dealer().pay() method doesn't use the same type every time but I guess that's fine
overall doesn't look bad
At most I would consider just having blackjack.py being main.py since main.py doesn't do anything on top of blackjack.py except for checking if it's the main file being run
Okay, that's fair
from GameObjects import ...
def play():
...
if __name__ == "__main__":
play()
What do you think about the check_hand() method in the Player class? I was considering modifiying the class such that if the value property is accessed it is calculated automatically
That's reasonable
i think just add @property above it tbh
by the way, what do you mean by this?
well your Dealer().pay() defaults to an int type with multiplier=1 but you later provide 1.5 which is a float so ig I'm just asking for you to add typehints so my IDE is happy with it lol
def pay(self, player: "Player", multiplier: float=1) -> None:
"""
Pays the amount owed times a multiplier.
By default the bet is returned.
Args:
player (Player): The payee.
multiplier (float): The multiplyer by default is 1. Should be changed to 1.5 in certain cases.
"""
amount_won = multiplier * player.bet
self.funds -= amount_won
player.funds += amount_won + player.bet
like that?
alright, thanks for your help!
you're welcome
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.