What is the best algorithm to stop the winning function of connect four to return true again?

我怕爱的太早我们不能终老 提交于 2021-01-29 16:18:38

问题


my winning function works well, but let's say there's four circles in a line and the line got 10 columns when I add the 5th circle the winning function return true again. is there a way to mark the already won circles and how?

here's the code:

function horizontalWin(row, col) {
    var playervalue = avatar[turn];
    var count = 0;
    for (var i = 0; i < GRID_SIZE; i++) {
        var slot = document.getElementById('tbl').rows[row].cells[i].innerHTML;
        if (slot == playervalue) {
            count++;
            if (count >=4) {return true;}
        }
        else {count = 0}
    }
    return false;
}

来源:https://stackoverflow.com/questions/61156108/what-is-the-best-algorithm-to-stop-the-winning-function-of-connect-four-to-retur

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!