Can someone please help looking into my code for move and draw? When executed, only the blankspace goes to the right position. The tile sometimes jumps to the next line and the board gets expanded. Thanks so much in advance!
void draw(void)
{
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] == 0)
printf(" _ \n");
else if (board[i][j] > 9)
printf("%i ", board[i][j]);
else
printf(" %i ", board[i][j]);
}
printf("\n");
}
}
bool move(int tile)
{
int a;
int b;
int e;
int f;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] == tile)
{
a = i;
b = j;
}
else if (board[i][j] == 0)
{
e = i;
f = j;
}
}
}
if (((a == e + 1 || a == e - 1) && b == f) || ((b == f + 1 || b == f - 1) && a == e))
{
board[a][b] = 0;
board[e][f] = tile;
return true;
}
return false;
}