简体   繁体   中英

call stack increase javascript

I've written a blackjack script that I'd like to iterate recursively until a rather large bankroll runs out. I'd like to run analyses on the telemetry. It's a script that lives locally and poses no danger to anything but the browser environment I'm running it in.

Essentially, the script is supposed to be recursive until the cash runs out. It works fine up to around 5k separate hands or so - for bankrolls up to 10k, and then it throws the max call stack error. However, I need way more data; like > 100k hands.

I've searched SO for solutions and I'm gathering it's a browser-specific thing. Any thoughts would be much appreciated!

Code snippet attached:

function main() {
init();
if (bankRoll >= initialBet) {
    determineBet();
}
else {
    alert("Not enough moneyz to play!");
    console.log("telemetry");
    exitFunction();
}
bankRoll -= initialBet;
playTheGame(); // the whole game, betting, receiving cards, strategy etc
}

I suggest you use a loop:

function main() {
    init();
    while (bankRoll >= initialBet) {
        determineBet();
        bankRoll -= initialBet;
        playTheGame(); // the whole game, betting, receiving cards, strategy etc
    }
    alert("Not enough moneyz to play!");
    console.log("telemetry");
    exitFunction();
}

It's hard to say if I refactored it correctly since I don't know what functions like playTheGame or determineBet do, but I hope you get the idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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