javascript - 在一定数量的移动后,我需要让我的 tic tac toe 机器人关闭
问题描述
所以我需要停止这段代码我有一个变量但我不知道如何编写一行代码来停止函数就像我需要它在完成 8 次移动后停止
var movecount = (turn >= 8);
var killbot =
if (movecount) {
killbot;
}
function easy_bot() {
var rnum = Math.floor(Math.random() * 9);
if (!checkWinner(turn))
while (board[rnum].style.backgroundImage != "") {
console.log("104");
rnum = Math.floor(Math.random() * 9);
}
board[rnum].style.backgroundImage = "url('X.gif')";
turn = "O";
解决方案
你可以使用返回来结束函数执行。
推荐阅读
- java - android studio每隔X秒自动刷新线程中的数据json url
- javascript - onselect 函数在我的日期选择器上不起作用
- android - Fragment 可以包含 NavController 吗?
- git - Jenkins 无法提取 20 GB git repo
- r - R Plotly, composite scatter graph
- firebase - 是否可以根据请求的 ServiceAccountKey.json 文件中的信息在 Firestore 安全规则中设置条件?
- python - 如何在 keras 中使用 LSTMCell 和 RNN 手动展开 LSTM 层?
- typescript - (TypeScript)从函数参数类型创建类型
- python - Python列表切片和索引,更好的方法
- sparql - 如何在 SPARQL 中获取 DBpedia 中两个节点之间的路径详细信息