My "move" function lets me make one move. After that, anything I do is illegal.
This is my code:
bool move(int tile)
{
int a = d - 1;
int b = d - 1;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (tile == board[i][j])
{
if ((a == i - 1 && b == j) || (a == i + 1 && b == j) || (a == i && b == j - 1) || (a == i && b == j + 1))
{
board[a][b] = tile;
board[i][j] = 0;
return true;
}
}
}
}
return false;
}
Can anyone tell me what I'm doing wrong? Is there a way to fix this code other than completely rewriting it?