简体   繁体   English

当我需要多次运行 sim 调用函数时避免退出代码 -1073741571 (0xc00000fd)

[英]Avoiding exit code -1073741571 (0xc00000fd) when I need to run a sim calling functions many times over

so I just programmed in pycharm a sort of blackjack simulation for card counting.所以我只是在 pycharm 中编写了一种用于算牌的二十一点模拟。 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.他们的每次迭代直到输赢都由 function 处理,其中 n 在 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().当玩家最终失去所有的钱或利润 x 时,它会转到 function simwin() 或 simlost() 循环停止,并且 NumberOfSims 范围内 for n 中的下一个值重置资金并循环函数,直到它们再次获得到 simwin() 或 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).然后我收到错误:python 进程以退出代码 -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.我发现这个进程以退出代码 -1073741571 完成,其中提到了更改线程大小,但我对此还是有点陌生,不明白它是否适用于我的情况以及如何使用它。

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.我省略了实际控制游戏的函数,例如玩家在庄家击球时击球和 ETC,但这基本上是代码流。 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.它必须多次通过手牌到go,因为通常资金约为5000,玩家的最大赌注为20,因此玩家需要很长时间才能输掉全部或盈利。

So I figured out how to do it with more iteration.所以我想出了如何通过更多的迭代来做到这一点。 I created a variable simIsDone, Then In the main function, playgame() at the end of defining all the functions such as hit() Stand() Etc, I put a while simIsDone == 0: playgame() then I removed all function calls to playgame() other than the for n in range.我创建了一个变量simIsDone,然后在主function,playgame()的末尾定义了所有的函数如hit() Stand()等,我放了一会儿simIsDone == 0: playgame() 然后我把ZC1C425268E68385D1AB5074C17A94F14全部去掉对 playgame() 的调用,而不是 for n in range。 Then whenever you won with simwin() or lost with simlost() at the end I would turn simIsDone = 1 This would stop the while loop meaning that you either profited or lost all your bankroll.然后,每当您在最后使用 simwin() 获胜或使用 simlost() 失败时,我都会将 simIsDone = 1 这将停止 while 循环,这意味着您要么获利,要么损失所有资金。 Then as a result the for n in range loop would check if we had completed all the simulations, if we still have more to do then we set simIsDone = 0 and then went to playgame() where the for loop would once again take over until a profit or loss happened.然后结果 for n in range 循环将检查我们是否已完成所有模拟,如果我们还有更多工作要做,那么我们设置 simIsDone = 0 然后转到 playgame() ,其中 for 循环将再次接管,直到发生了利润或损失。 Below is the code fixed for this solution Note: For this basic minimal code it will still get the error because there is a 50 percent chance that any hand will lose or win so if you set the profit too high it will be mathematically improbable that you will ever win and thus the only way to end each iteration is if you lose all your money.下面是为此解决方案修复的代码 注意:对于这个基本的最小代码,它仍然会出现错误,因为任何一手牌都有 50% 的机会输或赢,所以如果您将利润设置得太高,从数学上讲,您不太可能将永远获胜,因此结束每次迭代的唯一方法就是输掉所有的钱。 So it's possible that you end up ahead a bunch but then since the set profit is so high you are likely to keep drawing hands where you keep winning and losing in a row thus never reacher bankroll == 0 or bankroll >= profit + ogbankroll因此,您有可能最终领先一大堆,但由于设定的利润如此之高,您可能会在连续输赢的情况下继续抽牌,因此永远不会达到 bankroll == 0 或 bankroll >= profit + ogbankroll

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 = 5 # User input
sys.setrecursionlimit(20000)
bet = 1
bankroll = 10 # User Input
ogbankroll = 10 # User input
simlosses = 0
simwins = 0
simdone = 0
numberr = 0
def start():
    global simdone
    global numberr
    for n in range(numberOfSims):
        numberr = 0
        simdone = 0
        playgame()
    simdone = 1
    print("Sim wins: ", simwins)
    print("Sim losses: ", simlosses)

def playgame():
    global deck
    global numberOfSims
    global profit
    global bet
    global bankroll
    global numberr

    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]:
            ab = 1
            #Push

        elif dealerhand[0] + dealerhand[1] > playerhand[0] + playerhand[1]:
            # Lost
            bankroll = bankroll - bet

        else: # This else means player wins
            # dealerhand[0] + dealerhand[1] < playerhand[0] + playerhand[1]
            bankroll = bankroll + bet
    while simdone == 0:
        numberr = numberr + 1
        # print(numberr)
        playgame()

def simwin():
    global bankroll
    global ogbankroll
    global simwins
    global simlosses
    global simdone
    bankroll = ogbankroll
    simwins = simwins + 1
    simdone = 1
def simlost():
    global bankroll
    global ogbankroll
    global simwins
    global simlosses
    global simdone
    bankroll = ogbankroll
    simlosses = simlosses + 1
    simdone = 1


start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM