首页 > 解决方案 > 在一定数量的移动后,我需要让我的 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";

标签: javascripttic-tac-toe

解决方案


你可以使用返回来结束函数执行。


推荐阅读