0

Source code for init:

void init(void)
{
 int k=(d*d)-1;

for(int row=0; row<d; row++){
    for(int col=0; col<d; col++){
        board[row][col]=k; 
        if((d%2==0)&&(k==3)){
            k=1;
        }
        else if((d%2==0)&&(k==1)){
            k=2;

        }
        else{k--;}
    }
}
}

Error only in expected "0" character 7 of line 4, not "1" :( init initializes 4x4 board correctly )

I put a check in the draw() function.

void draw(void)
{
blank =0;
for(int i=0; i<d; i++){
    for(int j=0; j<d; j++){
        if((i==c)&&(j==r)){
            printf("%2i ", blank);
        }
        else{

            printf("%2i ", board[i][j]);

        }
    }
printf("\n");
}
}
  • Please comment here if something else I post can help – Mayank Goel May 27 '17 at 18:05
0

Depending on the draw function, the last row of a 4x4 board will look look like this: 3 | 1 | 2 | 1. No tile is being set to 0 when the board has an "even" dimension. Let's join the loops already in progress:

i = 3, j = 0: place tile 3, set k = 1
i = 3, j = 1: place tile 1, set k = 2
i = 3, j = 2: place tile 2, decrement k => k = 1
i = 3, j = 3: place tile 1

| improve this answer | |
  • what if I put up a check in the draw() function? The server will reject that? – Mayank Goel May 28 '17 at 2:21
  • The problem is in the init function. There must be a tile with value 0, and if the board is "even" dimension, there is no tile with value 0 (specifically the "last" tile). – DinoCoderSaurus May 28 '17 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .