I've written a function who fills the array with the numbers 1 to 9. It's a 8 puzzle game. First I fill the array for the winning numbers. And in the second for loop I'll compare the values from the existing board to the winning board. But the moment I read out the winning board I expect a 3 but get a 4.
Code:
bool
won(void)
{
int count = 0;
int winboard[d][d];
int inc = 1;
int swap = 0;
int k = 0;
int l = 0;
for (i = 0 ; i <= d -1 ; i++)
{
for (j = 0 ; j <= d -1; j++)
{
winboard[i][j] = inc++;
printf("test %d\n", winboard[i][j]);
}
}
// init winning board and compare to current board
for (i = 0 ; i <= d -1 ; i++)
{
for (j = 0 ; j <= d -1; j++)
{
k= winboard[i][j];
printf("%d\n", k);
l= board[i][j];
//printf("%d\n", l);
if(winboard[i][j] == board[i][j])
count++;
if (count == (d*d)-1)
return true;
}
}
return false;
}
Here the output from the program :
Code:
test 1
test 2
test 3
test 4
test 5
test 6
test 7
test 8
test 9
1
2
4
4
5
7
7
8
9
You ll see nicely filled but the read out ??