Can you please tell me what this code does specifically? How does it work?
void init(void) {
int total = d * d;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
board[i][j] = --total;
}
}
}
I'm really struggling with Game of Fifteen.
I just don't know where to start so I found the first part of a solution and have decided to make sure I know it in and out before moving on. I need to understand it as opposed to just copying it.
I don't understand how this works though.
I'm assuming this populates the array with variables, but I'm not sure how. On the first pass through the for loop, both i and j will be 0 right? So the first value will be: board[0][0] which if --total (assuming total is 9), it will be value no. 8?
But then on the second pass through, if both i and j are incremented by 1, then the next array value is board[1][1], as opposed to [0][1] or even [1][0] right? I'm really confused, please walk me through this code!