问题
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