简体   繁体   English

调用堆栈增加javascript

[英]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. 它最多可单独运行约5k左右-最多可赢取10k资金,然后抛出最大调用堆栈错误。 However, I need way more data; 但是,我需要更多的数据。 like > 100k hands. 超过10万手。

I've searched SO for solutions and I'm gathering it's a browser-specific thing. 我已经在SO中寻找解决方案,而我发现这是特定于浏览器的事情。 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. 这很难说,如果我重构它正确,因为我不知道什么样的功能playTheGamedetermineBet做,但我希望你的想法。

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

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