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");
}
}
1
  • Please comment here if something else I post can help Commented May 27, 2017 at 18:05

1 Answer 1

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

2
  • what if I put up a check in the draw() function? The server will reject that? Commented May 28, 2017 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). Commented May 28, 2017 at 15:51

You must log in to answer this question.

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