So I'm trying to create a browser version of connect 4 using HTML, CSS and Javascript, and I have my gameboard initialized into a 2d array. I've managed to switch turns, and change the values in the array to then change the color of the gameboard's internal divs, but I'm having trouble finding a way to determine if any win conditions are present, (i.e, the array contains 4 consecutive 1s or 2s horizontally, vertically, and diagonally). I'm assuming the .includes method will be relevant here, but I'm getting a return of false if I include the numbers as an array, or strings.
function init() {
board = [
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]
];
render();
}
//Functions controlling user input & declare render(),
//render function
function render() {
board.forEach(function (colArr, colIdx) {
colArr.forEach(function (cellVal, rowIdx) {
//console.log(colIdx, rowIdx);
const div = document.getElementById(`c${colIdx}r${rowIdx}`);
if (board[colIdx][rowIdx] === 1){
console.log(colIdx, rowIdx);
div.style.backgroundColor = "red";
} else if (board[colIdx][rowIdx] === 2) {
div.style.backgroundColor = "blue";
} else {
div.style.backgroundColor = "white";
};
});
});
}