Game of fifteen is 1) printing an extra line each time a move is labeled illegal and 2) somewhat randomly labeling moves illegal (e.g. it will swap to the left once but not twice, and up/down etc. sometimes but not all of the time). Init and draw seem to be working fine since the board prints alright.
bool move(int tile)
{
int r;
int c;
for(r = 0; r < d; r++)
{
for(c = 0; c < d; c++)
{
if(tile == 0)
{
return false;
}
// from github
if(tile == board[r][c])
{
if((r - 1) >= 0 && board[r-1][c] == 0)
{
int tmp = board[r][c];
board[r][c] = board[r-1][c];
board[r-1][c] = tmp;
return true;
}
else if((r + 1) <= (d - 1) && board[r + 1][c] == 0)
{
int tmp = board[r][c];
board[r][c] = board[r + 1][c];
board[r + 1][c] = tmp;
return true;
}
else if ((c - 1) >= 0 && (board[r][c - 1] == 0))
{
int tmp = board[r][c];
board[r][c] = board[r][c - 1];
board[r][c - 1] = tmp;
return true;
}
else if((c + 1) >= (d - 1) && (board[r][c + 1] == 0))
{
int tmp = board[r][c];
board[r][c] = board[r][c + 1];
board[r][c + 1] = tmp;
return true;
}
}
}
}
return false;
}
bool won(void)
{
for (int r = 0; r < d; r++)
{
for (int c = 0; c < d; d++)
{
if(board[r][c] > board[r][c+1])
{
return false;
}
if(board[r][c] > board[r+1][c])
{
return false;
}
}
}
return true;
}