I noticed that my in my init function, that the '1' and '2' variables weren't switching correctly.
After playing around with my code, I have noticed that this works:
void init(void)
{
// initilizes array
int total = d * d;
for (int row = 0; row < d; row++)
{
for (int col = 0; col < d; col ++)
{
board[row][col] = --total;
}
}
// Swap 2 and 1 if even number of spaces
if (((d*d)-1) % 2 != 0)
{
int temp = board[d-1][d-2];
board[d-1][d-2] = board[d-1][d-3];
board[d-1][d-3] = temp;
}
But THIS doesn't.
if ((total-1) % 2 != 0)
{
int temp = board[d-1][d-2];
board[d-1][d-2] = board[d-1][d-3];
board[d-1][d-3] = temp;
}
In both functions, I have declared that 'total == d * d'
I know this is done correctly because I have already swapped initalized the array. Can you please tell me why? I can't get my ahead around it, they seem identical to me.
Is there really any difference between using 'total' and 'd * d'???
Thank you