1

This is the error I get:

:( init initializes 3x3 board correctly

\ expected file to be of length 18, not 19

:( init initializes 4x4 board correctly

\ expected file to be of length 38, not 39

However, my code for init function is as follows:

void init(void) 
{

for(int i = 0; i < d; i++)
{
    for(int j = 0; j < d; j++)
    {
      board[i][j] = d*(d - j) - (i + 1);
    }
}

board[d - 1][d - 1] = '_';
}

How can I solve this?

1

It looks like the original code that you had was more correct than after the changes you made, whatever they were. The original problem lies here:

board[d - 1][d - 1] = '_';

Since board[][] is an int array, you actually set the value to 95, the ASCII value of an underscore. Since check50 is expecting 0 but got 95, it got an extra digit, thus the error.

The value of the blank tile in the array should be set to 0. The underscore needs only be substituted when printing out the array in draw().

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

3
  • I did that but the error still exists: { :( init initializes 3x3 board correctly \ expected "7" character 3 of line 1, not "5" } I have no idea why this is happening, it's annoying now.
    – samidha
    Aug 31 '16 at 14:58
  • Your code is calculating the initial values by column and then by row, when it should be by row and then column. I suspect that your draw is doing the same. Unfortunately, check50 and the log.txt code depend on the top row being in board[0][x], not board[x][0]. Try reversing the i and j in the formula that calculates the initial values, and make the necessary changes in draw as well.
    – Cliff B
    Aug 31 '16 at 18:48
  • that worked! thanks :)
    – samidha
    Sep 3 '16 at 6:09
1

The last element in your board does not need to be initialized by you.
Remember you should organize your elements differently depending on the board size.
The way you initialize your elements doesn't feel right, try writing by hand the expected values generated when making a small board, say the smallest value for d as possible and increase it by 1 or 2 if you don't find anything wrong.

For example a 3x3 board should be:

8 7 6
5 4 3
2 1 0


So your code should first generate the first row:
8 7 6
Second row:
5 4 3
And third row:
2 1 0
If this answers your question please mark as answered.

3
  • now i get another error: :( init initializes 3x3 board correctly \ expected "7" character 3 of line 1, not "5":( init initializes 4x4 board correctly \ expected "4" character 5 of line 1, not "1"
    – samidha
    Aug 30 '16 at 16:10
  • I disagree. Every element, including the last, needs to be initialized. It's an issue of what value is being set - see my answer.
    – Cliff B
    Aug 30 '16 at 22:08
  • Well, he doesn't need to initialize the last one since board is global.
    – thomas
    Aug 30 '16 at 23:37

You must log in to answer this question.

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