# won() Doesn't Work Properly

My won() function works properly when the board dimensions are 3 x 3. However, it doesn't work properly when the board dimensions are 4 x 4. What could possibly be wrong?

``````for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if ((i==(d-1)) && (j==(d-1)))
{
if (board[i][j] != 0)
return false;
}
else if (j > 0)
{
if (board[i][j] < board[i][j-1])
return false;
}
else
{
if (board[i][j] < board[i-1][d-1])
return false;
}
}
}
return true;
``````

I'm not quite sure how that works with any size.

First time through the loop:

``````say d = 4
i = 0
j = 0

if 0 == 3  //no
else if 0 > 0  //no
else
if board < board[-1]  //board[-1] ?? is off the grid
``````

Consider the winning position:

``````01 02 03 04
05 06 07 08
09 10 11 12
13 14 15

board is 1  (i is 0, j is 0)
board is 2  (i is 0, j is 1)
board is 3  (i is 0, j is 2)
board is 4  (i is 0, j is 3)
board is 5  (i is 1, j is 0)
etc.
``````

Notice how I'm just looping through `i` and then `j`? What's happening to the value? Can you think of an easy way to test whether your tiles are in order?

Brenda.