我已经编写了一个二十一点脚本,我想递归地迭代它,直到相当大的资金用完。我想对遥测进行分析。这是一个本地脚本,除了我运行它的浏览器环境之外,不会对任何东西造成危险。
本质上,脚本应该是递归的,直到现金用完。在大约 5k 手左右的情况下,它可以正常工作 - 对于高达 10k 的资金,然后它会抛出最大调用堆栈错误。然而,我需要更多的数据;喜欢 > 100k 手。
我已经搜索了解决方案,并且我收集它是特定于浏览器的东西。任何想法将不胜感激!
附上代码片段:
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
}
最佳答案
我建议你使用循环:
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();
}
很难说我是否正确地重构了它,因为我不知道 playTheGame
或 defineBet
之类的函数会做什么,但我希望你能明白。
关于javascript - 调用栈增加javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16882939/