I'm trying here to solve a 4x4 skyscraper (link skyscraper game)
But the problem is that my function place insert 0 number in tab and I don't understand why console log
Also I want to specify that I get 0 error: see below why console log: view code
Now when I place myself a number for example here 9, it works, in the sense that it fills the cells of the table. But here I get an error on the declaration of x, why? console log console log: view code
I won't post all the code for the sake of readability so here is the main function place:
function place(tab, consign, pos)
{
var x = Math.floor(pos / 4);
var y = pos % 4;
if (tab[x][y] != 0)
place(tab, consign, pos + 1);
else
{
for (var index = 1; index <= 4; index++)
{
tab[x][y] = 9;
console.log(tab);
if (colnline_has_no_double(tab, x, y, index))
{
if (x % 4 == 3)
{
if (check_top_range(tab, consign, x) && check_bottom_range(tab, consign, x))
place(tab, consign, pos + 1);
}
if (y % 4 == 3)
{
if (check_left_range(tab, consign, x) && check_right_range(tab, consign, x))
place(tab, consign, pos + 1);
}
place(tab, consign, pos + 1);
}
else
tab[x][y] = 0;
if (is_filled_good(tab, consign))
{
set_data_in_input(tab);
return ;
}
index++;
}
tab[x][y] = 0;
}
}