After two weeks struggle, I still can not come up with a solution to the won function. I divided the whole board into 3 areas: 1) rows except the last row (i.e. 0<=id+1 until (d-1)(d-2). Value at area 3 must value 0. If all of the three conditions are met, then the game must be won. but I do not know how to implement it.(because the first two conditions within the respective for loops, simply && cannot be used.) So, my logic is as follows: instead, if the first condition is not met, returning false, if the second condition is not met, again returning false, and if the third condition is not met, once again returning false; by so doing the remainder will mean all three conditions met and the game won (return true). But, the logic seems to have fraws. I am kind of give up and inclined to submit the fifteen uncompleted. My code is attached. Please give me any hints. Thank you in advance.
bool won(void)
{
// check rows except the last one if each tile is in ascending order starting at 1
int n = 1;
int temp = (d-1)*d+1;
for (int i = 0; i < d-1; i++)
{
for (int j = 0; j < d; j++)
{
if(board[i][j] != n)
{
return false;
n++;
}
}
}
//last row other than the last one must increment starting with (d-1)*d + 1
for(int j = 0; j < d-1; j++)
{
if(board[d-1][j] != temp)
{
return false;
temp++;
}
}
if( (board[d-1][d-1] != 0) //board[d-1][d-1] must be blanktile
{
return false;
}
return true;
}