0

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;
}
  • Both functions work fine. If you have a problem, it's elsewhere. Is it possible that you're not running the current build? – Cliff B Jul 6 '16 at 11:11
  • I'm not sure. Got to check. Will look elsewhere. Thank you for your help! – Britt Jul 7 '16 at 7:47
  • Did you find the problem? If so, please add as an answer (self-answers are encouraged) and accept your answer to remove from the unanswered question pool. thanks. – Cliff B Jul 9 '16 at 21:10

You must log in to answer this question.

Browse other questions tagged .