So, I'm coding a Bejeweled clone and I have an error in my flood fill function. I have a 15 x 15 matrix of jewels of different color and I try to count the number of tiles with flood-fill.
The function is here:
function count(x, y, color) {
if(matrix[x] && matrix[x][y]) {
if(matrix[x][y].color != color)
return;
cnt++;
count(x, y+1, color);
count(x, y-1, color);
count(x-1, y, color);
count(x+1, y, color);
console.log(cnt);
}
}
What's wrong?