
Init function
By: a guest on
Aug 18th, 2012 | syntax:
C | size: 0.69 KB | hits: 13 | expires: Never
void
init(void)
{
//first number
int num = d*d-1;
//initialize the board
for (int row=0; row < d; row++)
{
for (int col=0; col<d; col++)
{
board[row][col] = num;
//initialize the "space" tile
if (num == 0)
board[row][col]=d*d;
//swap 1 & 2 if d is even
if (d%2 == 0)
{
int temp;
temp = board[d-1][d-2];
board[d-1][d-2] = board[d-1][d-3];
board[d-1][d-3] = temp;
}
num--;
}
}
}