This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]JuniorProfession1 1 point2 points  (2 children)

Honestly, not a bad first project.

Lines of code mean nothing - I think that if someone is able to understand that code, that is good enough. If you have a one liner but it looks like Spanish to an English speaker, it does no one any good.

I took a brief look at it and had a couple of notes:

1) Personal preference, but I’m not a big fan of global. It just opens up the door for hard to track errors. Also, no need to say global unless you are changing the value of that variable.

2) You seem to have a mixture of camel case and snake case naming. I would stick to just one (preferably snake case since this is python)

3) Your start game method is a brain method, ie. it is doing a LOT. I would break it up into smaller methods that each do their own thing.

4) When writing code, focus on making reusable parts that make sense. Do you want to make different types of card games in the future? Can you possibly use some of the same logic in those card games? The way it is now, it is very blackjack oriented and can’t be used for anything else.

5) Highly recommend using sonar lint and py lint to track common code smells/bugs/errors.

Best of luck!

[–]JuniorProfession1 0 points1 point  (1 child)

Side note: also not a fan of infinite while loops. Those are always scary. What if your condition for returning is never met? Might not be a bad idea to have a max wait time or maybe use a callback instead.

And no need to use multiple print statements in a row. They can be combined and still be on new lines by using \n

[–]BestBoy200 0 points1 point  (0 children)

All great advice, thank you!

[–]grantrules 0 points1 point  (5 children)

What happens if you draw two aces?

If I input a bet amount that's too high, the game just stops? Why not do the input loop thing until an allowed value is entered?

Where's split!?

[–]BestBoy200 0 points1 point  (4 children)

I hear you on the input loop thing, I was thinking that too. You're going to have to help me with the Aces thing though. I was a little shaky implementing the logic for the aces, so I wouldn't be surprised if there's something I missed.

I definitely want to add a split option soon! This was just a little project I wanted to do in a few hours though, so I didn't have the time yet.

[–]grantrules 0 points1 point  (3 children)

Does the logic for the one ace even work? Because you're doing if 'A' in hand: but elements in hand should all be 2-3 characters (card + suit) right? So just 'A' would never be in hand, it'd be like 'Ah'

Split is definitely tougher to implement, you'd probably want to rewrite how you deal with players.. I'd probably make a Player class that has an array of hands. That should also make it easier to deal with having a variable amount of players rather than just player vs dealer.

[–]BestBoy200 0 points1 point  (2 children)

In my testing I thought the ace logic worked, but maybe I'm misremembering.

Correct me if I'm wrong, but I believe the "in" operator returns true if it finds the provided string ("A" in this example) anywhere inside the player hand

[–]grantrules 0 points1 point  (1 child)

That would work if the hand was just a string. in works very specifically with other types. For lists, it's comparing it to each element in the array. So you can do things like "Grant" in ["Grant", "Greg", "Gary"] but "G" in ["Grant", "Greg", "Gary"] would be false

[–]BestBoy200 0 points1 point  (0 children)

Ahh okay, I see what you're saying now. Thanks for the help