so I just programmed in pycharm a sort of blackjack simulation for card counting. The goal is to run many many hands of blackjack using perfect basic strategy and card counting and seeing based off the users bankroll and bet spread what their risk of losing all their money is. The problem is, in order to do that I need to run through virtual hands of blackjack many times until they lose their bankroll or they profit by a set amount. Each iteration of them playing until either losing or winning is handled by a function with a for n in range NumberOfSims. When the player finally loses all it's money or profits x, it goes to a function simwin() or simlost() where the looping stops and the next value in the for n in range NumberOfSims resets the bankroll and loops the functions until again they get to simwin() or simlost(). I got the maximum recursion error and used set recursion limit higher. Then I got the error: python process finished with exit code -1073741571 (0xc00000fd). I found this Process finished with exit code -1073741571 which mentions changing the threadsize, but I'm still a bit new to this and don't understand if it applies to my situation and how to use it.
Here is a basic version of my code.
import random
import math
import sys
deck = z = [2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
numberOfSims = 5 # This in the real code is user input
profit = 100 # User input
sys.setrecursionlimit(20000)
bet = 10
bankroll = 100 # User Input
ogbankroll = 100 # User input
simlosses = 0
simwins = 0
def start():
for n in range(numberOfSims):
playgame()
print("Sim wins: ", simwins)
print("Sim losses: ", simlosses)
def playgame():
global deck
global numberOfSims
global profit
global bet
global bankroll
random.shuffle(deck)
random.shuffle(deck)
random.shuffle(deck)
if bankroll == ogbankroll + profit:
simwin()
elif bankroll <= 0:
simlost()
else:
dealerhand = [deck[0], deck[1]]
playerhand = [deck[2], deck[3]]
if dealerhand[0] + dealerhand[1] == playerhand[0] + playerhand[1]:
#Push
playgame()
elif dealerhand[0] + dealerhand[1] > playerhand[0] + playerhand[1]:
# Lost
bankroll = bankroll - bet
playgame()
else: # This else means player wins
# dealerhand[0] + dealerhand[1] < playerhand[0] + playerhand[1]
bankroll = bankroll + bet
playgame()
def simwin():
global bankroll
global ogbankroll
global simwins
global simlosses
bankroll = ogbankroll
simwins = simwins + 1
def simlost():
global bankroll
global ogbankroll
global simwins
global simlosses
bankroll = ogbankroll
simlosses = simlosses + 1
start()
I left out functions that actually control the game like when the player hits when the dealer hits and ETC but this is basically the flow of the code. It has to go through hands many times because often the bankroll is something like 5000 and the player's max bet is like 20 so it takes a long time for the player to lose it all or profit.