I have tried many different variations of the check feature of the move function to try and find if it is a legal move. This is about my forth attempt and I still cant get it to find an illegal move. If the number is in the middle it is found illegal but if its around the outside it always let it move I cant figure out the problem. Thank you very much in advance. Here is my move function code.
bool move(int tile) { if (tile > 0 && tile < (d * d))
for (int i = 0; i < d; i++)
{
for (int t = 0; t < d ; t++)
{
if (board[i][t] == tile)
{
if (board[i][t+1] == 0 && t < d )
{
board[emptyz][emptyx] = tile;
board[i][t] = 0;
emptyz = i;
emptyx = t;
return true;
}
else if (board[i+1][t] == 0 && i < d )
{
board[emptyz][emptyx] = tile;
board[i][t] = 0;
emptyz = i;
emptyx = t;
return true;
}
else if (board[i][t-1] == 0 && t > -1)
{
board[emptyz][emptyx] = tile;
board[i][t] = 0;
emptyz = i;
emptyx = t;
return true;
}
else if (board[i-1][t] == 0 && i > -1)
{
board[emptyz][emptyx] = tile;
board[i][t] = 0;
emptyz = i;
emptyx = t;
return true;
}
else
{
return false;
}
}
}
}
return false;
}