r/learnpython • u/mouthpiec • Apr 22 '24
Phyton code for blackjack to simulate thousands of games using basic strategy.
can someone please guide me into a subreddit giving the phyton code for blackjack?
i need to create a simulator to output thousands of games, playing basic strategy, user is able to double and split. Also soft cards should be taken into consideration.
-9
u/Vandercoon Apr 22 '24
Just get gpt4 or Claude to do it. Will take 10 minutes of going back and forth to get it where you want it
-1
u/mouthpiec Apr 22 '24
oohhh ..... will do and paste the code here if successful :)
0
u/Vandercoon Apr 22 '24
I literally the other day made a CLI python blackjack game and just kept iterating on it. I started with ‘build a game of black jack’. It won’t be great first go, but just tell it what it’s missing each time and it will add it.
3
u/mouthpiec Apr 22 '24
holy sh*t ..... https://chat.openai.com/share/1ff38da4-93ae-4b2c-a6bd-327bf36cf309
although I have some experience with coding, I have zero experience in phyton! this is amazing!
0
u/Vandercoon Apr 22 '24
Yeah awesome. You have a bug that ace is only 1 in there. I found that too when I made mine.
Just tell it to make ace 11 unless it’s going to make your score greater than 21
0
u/mouthpiec Apr 22 '24
there is this function ... is this what you meant?
Function to calculate the total score of a hand
def calculate_score(hand):
score = sum(hand)
num_aces = hand.count(1) # Count the number of Aces in the hand
Adjust score for Aces being counted as 11 if it doesn't bust the hand
for _ in range(num_aces):
if score + 10 <= 21:
score += 10
return score
1
u/Vandercoon Apr 22 '24
I just ran it in Replit and there were lots of hands valued at 1, which must be aces:
Game 10: Player score = 23, Cards dealt to playe
r =[1, 2, 1, 8, 4, 7] Dealer score = 22, Cards
dealt to dealer = [9, 3, 10], Outcome = Player busts
So it’s defaulting to 1, it should default to 11, and if it makes the score go over 21 then -10 from player score.
Just ask gpt to fix it
1
u/mouthpiec Apr 22 '24
now should be fine:
Dealer score = 19, Cards dealt to dealer = [1, 3, 5], Outcome = Player lose {11+3+5=19}
Dealer score = 24, Cards dealt to dealer = [5, 8, 1, 10], Outcome = Player win {5+8+1+10=24}
https://chat.openai.com/share/1ff38da4-93ae-4b2c-a6bd-327bf36cf309
1
u/Vandercoon Apr 22 '24
So now you have another thing to fix!
Hopefully you’re taking this as me trying to help, but if you lose on 19 to 19 with an ace you’d rather hit again and make that ace a 1 and hope you get 20 or 21.
Unles that’s not apart of basic strategy of course. That’s why you keep iterating coz new little things always arise.
I would also make the output more readable. I had trouble following that
1
u/mouthpiec Apr 22 '24
on 19 I would stand due to basic strategy. the output is an easy fix :)
no worries, I appreciate your input ... i am amazed with what chatgpt can do
→ More replies (0)
1
u/thesadpotato19 Apr 22 '24
I think the big book of small python projects has this. you can search it