1

I'm wondering if I'm going about Init() correctly. It took me quite some time to understand what I was supposed to do. I realized drawing out the actual board on paper helped a lot.

Anyways, here is the code. What do you guys think? Is there anything I'm missing from Init()?

void init(void)
{
 // so we'll ask the user for one single D(digit), for the board size
 // let's say I want a board size of 8
 // we will do 8 * 8 to populate rows
 // so there will be 64 spaces
 // BUT, remember, we need one blank space! *****

 int gridSize = d * d;

 // now we will loop through the rows
 for (int i = 0; i < d; i++)
 {
     // on each iteration of a row, we will go through all of the columns
     for (int j = 0; j < d; j++)
     {
        // for every spot we hit on the board, we will assign it, it's  number
        // so if we are at board[0][1], it's number will be, for  example, 64 - 1 = 63!
         board[i][j] = (gridSize - 1);
         // each time we do this, we must go down one more step
         // if we dont, every spot will have the same number
         gridSize--;
     }
 }

 // if our grid is an even number
 if (gridSize % 2 == 0)
 {
     // swap the placements of 1 & 2
     // drawing this out really helped me understand what I was doing
     board[d - 1][d - 2] = 2;
     board[d - 1][d - 3] = 1;
 }

 // if the last spot on the board is 0
 if (board[d - 1][d - 1] == 0)
 {
     // set it to a blank spot, or "__"
     board[d - 1][d - 1] = "__";
 }


}
2

It looks good (not a guarantee) right up until the end. What do you think will happen when you try to assign a string to an int?

Instead, leave the 0 in place for the blank tile here, and use the same if statement block to print the underscores in draw().

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

| improve this answer | |

You must log in to answer this question.

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