# pset3 fifteen move function adds 0

My move function generally works properly, but every so often it adds an extra 0 in to the table, so that there are two. Both can then be moved around. I can't figure out what corner case I haven't accounted for that is causing this bug.

``````bool move(int tile)
{
// TODO
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] == tile)
{
if (board[i + 1][j] == 0 && i + 1 < d)
{
board[i][j] = 0;
board[i + 1][j] = tile;
return true;
}
else if (board[i - 1][j] == 0 && i - 1 < d)
{
board[i][j] = 0;
board[i - 1][j] = tile;
return true;
}
else if (board[i][j + 1] == 0 && j + 1 < d)
{
board[i][j] = 0;
board[i][j + 1] = tile;
return true;
}
else if (board[i][j - 1] == 0 && j - 1 < d)
{
board[i][j] = 0;
board[i][j - 1] = tile;
return true;
}
}
}

}
return false;
}
``````

Where is the flaw in my logic?

``````else if (board[i - 1][j] == 0 && i - 1 < d)
When `i` = 0, what is i-1? Seems like i-1 will always be less than d, but maybe this isn't what you want to check? Same for j. This should get you going. ;-)