Don't like ads? PRO users don't see any ads ;-)
Guest

Init function

By: a guest on Aug 18th, 2012  |  syntax: C  |  size: 0.69 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void
  2. init(void)
  3. {
  4.     //first number
  5.     int num = d*d-1;
  6.            
  7.     //initialize the board
  8.     for (int row=0; row < d; row++)    
  9.     {
  10.         for (int col=0; col<d; col++)
  11.         {  
  12.             board[row][col] = num;
  13.                 //initialize the "space" tile
  14.                 if (num == 0)
  15.                     board[row][col]=d*d;
  16.        
  17.                 //swap 1 & 2 if d is even
  18.                 if (d%2 == 0)
  19.                 {
  20.                     int temp;
  21.                     temp = board[d-1][d-2];
  22.                     board[d-1][d-2] = board[d-1][d-3];
  23.                     board[d-1][d-3] = temp;
  24.                 }
  25.    
  26.             num--;
  27.         }
  28.     }
  29. }