【发布时间】:2019-01-15 09:15:22
【问题描述】:
我有一个国际象棋程序,它使用递归 alphaBeta 算法(以及在此之上的一些层)搜索移动。我想在 10 秒后停止搜索(但我尝试用 1 秒使其工作),所以我使用 setTimeout 设置全局标志。
let timeOut = false;
let i = 0;
setTimeout(() => {
timeOut = true;
console.log('timeout');
console.log('timeout');
console.log('timeout');
console.log('timeout');
}, 1000);
while (i < 1000 && timeOut === false) {
score = mtdf(pos, i, score)
console.log('depth:' + i + ', size: ' + tp.size());
i++;
}
这肯定会在浏览器中运行,所以我知道 console.log 语句应该在浏览器中打印,但它们不是。未调用回调。请帮忙。
编辑:添加了 timeOut 变量初始化以使其更清晰。另外,对不起,忘记添加 i 初始化(并不是这些声明甚至与问题相关,因为问题是 setTimeout 回调甚至没有被执行......)
【问题讨论】:
-
您能在控制台中看到任何错误吗?
-
不,我只看到我 console.log 的所有其他内容,所以我知道 console.log 有效。喜欢
depth:1, size: 21
标签: javascript settimeout